如何使用Avangate设置定期订阅

时间:2015-10-15 08:05:27

标签: php mysql paypal payment recurring-billing

我正在建立一个会员区,并且我使用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,"");
}
?>

1 个答案:

答案 0 :(得分:0)

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

您还需要测试请愿书是否正确(产品,订阅等),但主要部分是使用LCN(许可证更改通知)挂钩。