主页 个人PHP笔记 PayPal的周期性自动付款代码
admin
发表于2013-04-24 15:26:29    只看楼主 楼主
头衔:  精益求精
注册时间: 2012-10-07
用户组: 日常管理组
发帖数:  502
金币数:  187
短消息
$request  = 'METHOD=CreateRecurringPaymentsProfile';
$request .= '&VERSION=51.0';
$request .= '&USER=' . urlencode('xujl_api1.bodait.com');
$request .= '&PWD=' . urlencode('1366263097');
$request .= '&SIGNATURE=' . urlencode('AnuHHk5IZAI5WOs8GNv5A-9UPH6IAfLVnUNFtL0.AAI68P7duoGAyRF7');

$request .= '&AMT= '.$_POST['amount']; //Billing amount for each billing cycle during this payment period. This amount does not include shipping and tax amounts.
$request .= '&TAXAMT= '.($_POST['amount']*0.2);
$request .= '&SHIPPINGAMT= 0';
$request .= '&CREDITCARDTYPE='.urlencode($_POST['cardtype']);
$request .= '&ACCT=' . urlencode($_POST['cardnum']);
$request .= '&EXPDATE=' . urlencode($_POST['carddate']);
$request .= '&CVV2=' . urlencode($_POST['cardcode']);
$request .= '&CURRENCYCODE=' . urlencode('GBP');
$request .= '&FIRSTNAME=' . urlencode($_POST['cardfirstname']);
$request .= '&LASTNAME=' . urlencode($_POST['cardlastname']);
$request .= '&DESC='.urlencode("Recurring Payment");
$request .= '&PROFILESTARTDATE='.urlencode(date('Y-m-d H:i:s'));
$request .= '&BILLINGPERIOD=' . urlencode("Month");
$request .= '&BILLINGFREQUENCY=' . urlencode("12");
$curl = curl_init('https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);

$response = curl_exec($curl);
curl_close($curl);
if (!$response) {
echo 'DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')';
exit;
}
$response_info = array();
parse_str($response, $response_info);
引用回复  把握生命里的每一分钟,没有人能随随便便成功~^_^
 
admin
发表于2013-04-24 15:29:45 1楼
头衔:  精益求精
注册时间: 2012-10-07
用户组: 日常管理组
发帖数:  502
金币数:  187
短消息
以上步骤会产生返回值
Array
(
[PROFILEID] => I-FMMM27NWUM26
[TIMESTAMP] => 2013-04-24T07:28:54Z
[CORRELATIONID] => 4580eb4de1085
[ACK] => Success
[VERSION] => 51.0
[BUILD] => 5650305
)

重要的是PROFILEID
引用回复  把握生命里的每一分钟,没有人能随随便便成功~^_^
 
admin
发表于2013-04-24 15:31:38 2楼
头衔:  精益求精
注册时间: 2012-10-07
用户组: 日常管理组
发帖数:  502
金币数:  187
短消息
根据PROFILEID任务定时
$request  = 'METHOD=GetRecurringPaymentsProfileDetails';
$request .= '&VERSION=51.0';
$request .= '&USER=' . urlencode('xujl_api1.bodait.com');
$request .= '&PWD=' . urlencode('1366263097');
$request .= '&SIGNATURE=' . urlencode('AnuHHk5IZAI5WOs8GNv5A-9UPH6IAfLVnUNFtL0.AAI68P7duoGAyRF7');
$request .= '&PROFILEID='.$arr['profileid'];

$curl = curl_init('https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);

$response = curl_exec($curl);
curl_close($curl);
if (!$response) {
echo 'DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')';
exit;
}

$response_info = array();
parse_str($response, $response_info);

轮询状态STATUS
引用回复  把握生命里的每一分钟,没有人能随随便便成功~^_^
 
admin
发表于2013-04-24 15:32:38 3楼
头衔:  精益求精
注册时间: 2012-10-07
用户组: 日常管理组
发帖数:  502
金币数:  187
短消息
以上步骤会产生返回值
Array
(
[PROFILEID] => I-FMMM27NWUM26
[STATUS] => Active
[AUTOBILLOUTAMT] => NoAutoBill
[DESC] => Test Recurring Payment( $200 / monthly)
[MAXFAILEDPAYMENTS] => 0
[SUBSCRIBERNAME] => Tester Testerson
[PROFILESTARTDATE] => 2013-08-17T07:00:00Z
[NEXTBILLINGDATE] => 2013-08-17T10:00:00Z
[NUMCYCLESCOMPLETED] => 0
[NUMCYCLESREMAINING] => 0
[OUTSTANDINGBALANCE] => 0.00
[FAILEDPAYMENTCOUNT] => 0
[TRIALAMTPAID] => 0.00
[REGULARAMTPAID] => 0.00
[AGGREGATEAMT] => 0.00
[AGGREGATEOPTIONALAMT] => 0.00
[FINALPAYMENTDUEDATE] => 1970-01-01T00:00:00Z
[TIMESTAMP] => 2013-04-24T07:28:55Z
[CORRELATIONID] => 945ef075d295a
[ACK] => Success
[VERSION] => 51.0
[BUILD] => 5650305
[BILLINGPERIOD] => Month
[BILLINGFREQUENCY] => 12
[TOTALBILLINGCYCLES] => 0
[CURRENCYCODE] => USD
[AMT] => 100.00
[SHIPPINGAMT] => 80.00
[TAXAMT] => 20.00
[REGULARBILLINGPERIOD] => Month
[REGULARBILLINGFREQUENCY] => 12
[REGULARTOTALBILLINGCYCLES] => 0
[REGULARCURRENCYCODE] => USD
[REGULARAMT] => 100.00
[REGULARSHIPPINGAMT] => 80.00
[REGULARTAXAMT] => 20.00
[ACCT] => 4592
[CREDITCARDTYPE] => Visa
[EXPDATE] => 042018
[FIRSTNAME] => Tester
[LASTNAME] => Testerson
[ADDRESSOWNER] => PayPal
[ADDRESSSTATUS] => Unconfirmed
[PAYERSTATUS] => unverified
)
引用回复  把握生命里的每一分钟,没有人能随随便便成功~^_^

回复人
回复内容

Powered BY YouYaX
个人自主开发论坛,从2010年10月份开发至今!

操作管理