【问题标题】:How to setup recurring subscription using Avangate如何使用 Avangate 设置定期订阅
【发布时间】:2016-01-13 14:11:24
【问题描述】:

我正在建立一个会员区,并使用 avangate.com 作为支付系统。

我只想在发生定期付款时用新的到期日期更新数据库中的订阅者日期。

我从他们那里得到了这个 ipn 代码作为起点:

<?php
/* Internet Payment Notification */

$pass       = "AABBCCDDEEFF";   /* pass to compute HASH */
$result     = "";               /* string for compute HASH for received data */
$return     = "";               /* string to compute HASH for return result */
$signature  = $_POST["HASH"];   /* HASH received */
$body       = "";

/* read info received */
ob_start();
while(list($key, $val) = each($_POST)){
    $$key=$val;

    /* get values */
    if($key != "HASH"){

        if(is_array($val)) $result .= ArrayExpand($val);
        else{
            $size       = strlen(StripSlashes($val));
            $result .= $size.StripSlashes($val);
        }

    }

}
$body = ob_get_contents();
ob_end_flush();

$date_return = date("YmdGis");

$return = strlen($_POST["IPN_PID"][0]).$_POST["IPN_PID"][0].strlen($_POST["IPN_PNAME"][0]).$_POST["IPN_PNAME"][0];
$return .= strlen($_POST["IPN_DATE"]).$_POST["IPN_DATE"].strlen($date_return).$date_return;

function ArrayExpand($array){
    $retval = "";
    for($i = 0; $i < sizeof($array); $i++){
        $size       = strlen(StripSlashes($array[$i]));
        $retval .= $size.StripSlashes($array[$i]);
    }

    return $retval;
}

function hmac ($key, $data){
   $b = 64; // byte length for md5
   if (strlen($key) > $b) {
       $key = pack("H*",md5($key));
   }
   $key  = str_pad($key, $b, chr(0x00));
   $ipad = str_pad('', $b, chr(0x36));
   $opad = str_pad('', $b, chr(0x5c));
   $k_ipad = $key ^ $ipad ;
   $k_opad = $key ^ $opad;
   return md5($k_opad  . pack("H*",md5($k_ipad . $data)));
}

$hash =  hmac($pass, $result); /* HASH for data received */

$body .= $result."\r\n\r\nHash: ".$hash."\r\n\r\nSignature: ".$signature."\r\n\r\nReturnSTR: ".$return;

if($hash == $signature){
    echo "Verified OK!";

    /* ePayment response */
    $result_hash =  hmac($pass, $return);
    echo "<EPAYMENT>".$date_return."|".$result_hash."</EPAYMENT>";

    /* Begin automated procedures (START YOUR CODE)*/


}else{
    /* warning email */
    mail("your_address@example.com","BAD IPN Signature", $body,"");
}
?>

【问题讨论】:

    标签: php mysql paypal payment recurring-billing


    【解决方案1】:

    您必须使用 LCN 响应,而不是 IPN。对于 LCN,数据数组中的 EXPIRATION_DATE 字段告诉我们新的过期数据。

    您还需要测试请求是否正确(产品、订阅等),但主要部分是使用 LCN(License Change Notification)挂钩。

    【讨论】:

      猜你喜欢
      • 2014-07-12
      • 2016-08-12
      • 2014-09-27
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 2022-07-21
      相关资源
      最近更新 更多