我当前的项目允许用户在不注册贝宝帐户的情况下订阅会员资格。
用户的用户名和密码由我自己的应用程序创建和管理,而不是 PayPal。
谁能告诉我如何创建一个取消订阅的 hTMl 表单?我可以通过发送取消订阅txn_id
吗?
我相信我可以使用 IPN 捕获此信息。
我还应该提到,我是一名 DBA,而不是真正的开发人员,所以如果我有点新手,请多多包涵。
提前致谢。
我当前的项目允许用户在不注册贝宝帐户的情况下订阅会员资格。
用户的用户名和密码由我自己的应用程序创建和管理,而不是 PayPal。
谁能告诉我如何创建一个取消订阅的 hTMl 表单?我可以通过发送取消订阅txn_id
吗?
我相信我可以使用 IPN 捕获此信息。
我还应该提到,我是一名 DBA,而不是真正的开发人员,所以如果我有点新手,请多多包涵。
提前致谢。
这就是我最终做的事情。
<?php
require 'core/init.php';
require 'core/conn.php';
/*The paypal_transactions table is a table I'm using to store the IPN data. This is necessary to capture the Profile_ID/Subscr_ID. The Custom parameter is being used to pass the username.*/
$profileid_sql = "select subscr_id from paypal_transactions where custom ='". escape($user->data()->username)."'";
$result=mysql_query($profileid_sql);
while($row=mysql_fetch_array($result)){
$profileid = $row['subscr_id'];
}
include 'functions/change_subscription_status.php';
change_subscription_status( $profileid, 'Cancel' );
header('Location: Cancelled.php');
?>
change_subscription_status 函数在这里...
<?php
/**
* Performs an Express Checkout NVP API operation as passed in $action.
*
* Although the PayPal Standard API provides no facility for cancelling a subscription, the PayPal
* Express Checkout NVP API can be used.
*/
function change_subscription_status( $profile_id, $action ) {
$api_request = 'USER=' . urlencode( 'API_username' )
. '&PWD=' . urlencode( 'API_Password' )
. '&SIGNATURE=' . urlencode( 'API_Signature' )
. '&VERSION=76.0'
. '&METHOD=ManageRecurringPaymentsProfileStatus'
. '&PROFILEID=' . urlencode( $profile_id )
. '&ACTION=' . urlencode( $action )
. '&NOTE=' . urlencode( 'Profile cancelled at store' );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
// Uncomment these to turn off server and peer verification
// curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
// curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, 1 );
// Set the API parameters for this transaction
curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );
// Request response from PayPal
$response = curl_exec( $ch );
// If no response was received from PayPal there is no point parsing the response
if( ! $response )
die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );
curl_close( $ch );
// An associative array is more usable than a parameter string
parse_str( $response, $parsed_response );
return $parsed_response;
}
?>
使用 paypal api 方法 ManageRecurringPaymentsProfileStatus ( API Operation NVP ),使用 ACTION 参数可以:
要创建重复配置文件,请遵循以下 (PHP) 示例:
// SetExpressCheckout 的参数,将发送到 PayPal
$pada['L_BILLINGAGREEMENTDESCRIPTION0'] = '产品描述'; $pada['L_BILLINGAGREEMENTDESCRIPTION0'] = $pada['L_BILLINGAGREEMENTDESCRIPTION0'] 。 '$'.$product->price.'/month'; $padata['L_PAYMENTREQUEST_0_DESC0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] 。 '$'.$product->price.'/month';
$padata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn'; $padata['PAYMENTREQUEST_0_DESC'] = $product->name; $padata['RETURNURL'] = 'http://site_url/paypal/returnurl'; $padata['CANCELURL'] = 'http://site_url/paypal/cancelurl';
$pada['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD'; $pada['PAYMENTREQUEST_0_PAYMENTACTION'] = '销售'; $pada['PAYMENTREQUEST_0_ITEMAMT'] = $product->price;
$padata['PAYMENTREQUEST_0_AMT'] = $product->price;
$pada['L_BILLINGTYPE0'] = 'RecurringPayments';
$pada['L_PAYMENTREQUEST_0_NAME0'] = $product->name;
$pada['L_PAYMENTREQUEST_0_NUMBER0']='322';
$pada['L_PAYMENTREQUEST_0_QTY0'] = '1';
$pada['L_PAYMENTREQUEST_0_AMT0'] = $product->price;
$paypal_data = http_build_query($pada); $httpParsedResponseAr = $this->PPHttpPost('SetExpressCheckout', $paypal_data); //根据我们从 Paypal 收到的消息进行响应 if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])){ //使用收到的令牌将用户重定向到 PayPal 商店。 $paypalurl ='https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].''; header('位置:'.$paypalurl); }别的{ echo '错误: '.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'';
}
页面返回网址:
$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = '重复描述';
$hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'] 。'$'.$pr->price.'/month';
$hosteddata['L_PAYMENTREQUEST_0_NAME0'] = $pr->name;
$hosteddata['PROFILEREFERENCE'] = $GetExpressCheckoutDetails['L_PAYMENTREQUEST_0_NUMBER0'];
$hosteddata['PROFILESTARTDATE'] = date('Ymd') 。'T'。日期('H:i:s').'Z';
$hosteddata['SUBSCRIBERNAME'] = $GetExpressCheckoutDetails['FIRSTNAME'] 。' ' 。$GetExpressCheckoutDetails['LASTNAME'];
$hosteddata['令牌'
$hosteddata['DESC'] = $hosteddata['L_BILLINGAGREEMENTDESCRIPTION0'];
$hosteddata['AMT'] = $pr->price;
$hosteddata['BILLINGPERIOD'] = '月';
$hosteddata['BILLINGFREQUENCY'] = '1';
$hosteddata['TOTALBILLINGCYCLES'] = '12';
$hosteddata['REGULARTOTALBILLINGCYCLES'] = '1';
$hosteddata['VERSION'] = '74.0';
$hosteddata['MAXFAILEDPAYMENTS'] = '1';
$hosteddata['L_PAYMENTREQUEST_0_QTY0'] = '1';
$hosteddata['L_BILLINGTYPE0'] = ' 经常性付款”;
$hosteddata['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = '数字';
$hosteddata['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;
$hosteddata['INITAMT'] = $pr->price;
$hosteddata['L_PAYMENTREQUEST_0_NUMBER0'] = $pr->id;
$hosteddata['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn';
$paypal_data = http_build_query($hosteddata); $hosted_saas_response = $this->PPHttpPost('CreateRecurringPaymentsProfile', $paypal_data);
我使用单独的方法将参数发布到贝宝
私有函数 PPHttpPost( $methodName_, $nvpStr_ ) {
$api_username = 'yourpaypal@email.com'; $api_password = 'QWEQWEWQEQWEQEQWE';
$api_signature = 'WQEQWEQWEQWEWQEQWEQWEQWEQWEQWE.cT';
$api_endpoint = "https://api-3t.paypal.com/nvp";
$版本 = '124.0'; $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq = "方法=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$api_signature&$nvpStr_";
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
$httpResponse = curl_exec($ch); 如果(!$http响应){ exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
} // 提取响应详细信息。 $httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = 数组(); foreach ($httpResponseAr as $i => $value) { $tmpAr = explode("=", $value); 如果(大小($tmpAr)> 1){ $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1]; } } if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("对 $api_endpoint 的 POST 请求 ($nvpreq) 的 HTTP 响应无效。");
} 返回 $httpParsedResponseAr;
}
另一种取消方法是在用户帐户内: