我目前正在我的网站中集成贝宝定期付款流程。我用了这段代码
function process()
{
include_once("config.php");
include_once("paypal.class.php");
if($_POST) //Post Data received from product list page.
{
//Mainly we need 4 variables from an item, Item Name, Item Price, Item Number and Item Quantity.
$ItemName = $_POST["itemname"]; //Item Name
$ItemPrice = $_POST["itemprice"]; //Item Price
$ItemNumber = $_POST["itemnumber"]; //Item Number
$ItemQty = $_POST["itemQty"]; // Item Quantity
$ItemTotalPrice = ($ItemPrice*$ItemQty); //(Item Price x Quantity = Total) Get total amount of product;
//Data to be sent to paypal
$padata = '&CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&PAYMENTACTION=Sale'.
'&ALLOWNOTE=1'.
'&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&PAYMENTREQUEST_0_AMT='.urlencode($ItemTotalPrice).
'&PAYMENTREQUEST_0_ITEMAMT='.urlencode($ItemTotalPrice).
'&L_PAYMENTREQUEST_0_QTY0='. urlencode($ItemQty).
'&L_PAYMENTREQUEST_0_AMT0='.urlencode($ItemPrice).
'&L_PAYMENTREQUEST_0_NAME0='.urlencode($ItemName).
'&L_PAYMENTREQUEST_0_NUMBER0='.urlencode($ItemNumber).
'&AMT='.urlencode($ItemTotalPrice).
'&L_BILLINGTYPE0='.urlencode('RecurringPayments').
'&L_BILLINGAGREEMENTDESCRIPTION0='.urlencode('message plan').
'&RETURNURL='.urlencode($PayPalReturnURL ).
'&CANCELURL='.urlencode($PayPalCancelURL);
//We need to execute the "SetExpressCheckOut" method to obtain paypal token
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
//Respond according to message we receive from Paypal
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
// If successful set some session variable we need later when user is redirected back to page from paypal.
$_SESSION['itemprice'] = $ItemPrice;
$_SESSION['totalamount'] = $ItemTotalPrice;
$_SESSION['itemName'] = $ItemName;
$_SESSION['itemNo'] = $ItemNumber;
$_SESSION['itemQTY'] = $ItemQty;
if($PayPalMode=='sandbox')
{
$paypalmode = '.sandbox';
}
else
{
$paypalmode = '';
}
//Redirect user to PayPal store with Token received.
$paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].'';
header('Location: '.$paypalurl);
}else{
//Show error message
echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}
//Paypal redirects back to this page using ReturnURL, We should receive TOKEN and Payer ID
if(isset($_GET["token"]) && isset($_GET["PayerID"]))
{
//we will be using these two variables to execute the "DoExpressCheckoutPayment"
//Note: we haven't received any payment yet.
$token = $_GET["token"];
$playerid = $_GET["PayerID"];
//get session variables
$ItemPrice = $_SESSION['itemprice'];
$ItemTotalPrice = $_SESSION['totalamount'];
$ItemName = $_SESSION['itemName'];
$ItemNumber = $_SESSION['itemNo'];
$ItemQTY =$_SESSION['itemQTY'];
$padata = '&TOKEN='.urlencode($token).
'&PAYERID='.urlencode($playerid).
'&PAYMENTACTION='.urlencode("SALE").
'&AMT='.urlencode($ItemTotalPrice).
'&CURRENCYCODE='.urlencode($PayPalCurrencyCode).
'&NOTIFYURL='.urlencode('http://mywebiste.com/listner');
//We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
//Check if everything went ok..
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
{
echo '<h2>Success</h2>';
echo 'Your Transaction ID :'.urldecode($httpParsedResponseAr["TRANSACTIONID"]);
/*
//Sometimes Payment are kept pending even when transaction is complete.
//May be because of Currency change, or user choose to review each payment etc.
//hence we need to notify user about it and ask him manually approve the transiction
*/
if('Completed' == $httpParsedResponseAr["PAYMENTSTATUS"])
{
echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!</div>';
}
elseif('Pending' == $httpParsedResponseAr["PAYMENTSTATUS"])
{
echo '<div style="color:red">Transaction Complete, but payment is still pending! You need to manually authorize this payment in your <a target="_new" href="http://www.paypal.com">Paypal Account</a></div>';
}
echo '<br /><b>Stuff to store in database :</b><br /><pre>';
$transactionID = urlencode($httpParsedResponseAr["TRANSACTIONID"]);
$nvpStr = "&TRANSACTIONID=".$transactionID;
$paypal= new MyPayPal();
$httpParsedResponseAr = $paypal->PPHttpPost('GetTransactionDetails', $nvpStr, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) {
$nvpstr="&TOKEN=".$_GET['token'];
$nvpstr.="&BILLINGPERIOD=Month";
$nvpstr.="&BILLINGFREQUENCY=1";
$nvpstr.="&AMT=1";
$nvpstr.="&CURRENCYCODE=USD";
$nvpstr.="&COUNTRYCODE=US";
$nvpstr.="&PAYERID=".$httpParsedResponseAr['PAYERID'];
$nvpstr.="&PROFILESTARTDATE=".date('Y-m-d');
$recurr = $paypal->PPHttpPost('CreateRecurringPaymentsProfile',$nvpStr,$PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode);
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
print_r($recurr);
} else {
echo '<div style="color:red"><b>GetTransactionDetails failed:</b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}else{
echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
echo '<pre>';
print_r($httpParsedResponseAr);
echo '</pre>';
}
}
}
我正在获取令牌和付款人 ID 等。它一切正常。但是当我尝试创建重复配置文件时,我得到了这个响应
Array
(
[TIMESTAMP] => 2013%2d03%2d18T05%3a32%3a06Z
[CORRELATIONID] => 912b6004f40bb
[ACK] => Failure
[VERSION] => 76%2e0
[BUILD] => 5294323
[L_ERRORCODE0] => 11585
[L_ERRORCODE1] => 11518
[L_ERRORCODE2] => 11516
[L_ERRORCODE3] => 11519
[L_ERRORCODE4] => 11549
[L_SHORTMESSAGE0] => Missing%20Token%20or%20payment%20source
[L_SHORTMESSAGE1] => Invalid%20billing%20period%2e
[L_SHORTMESSAGE2] => Invalid%20billing%20frequency
[L_SHORTMESSAGE3] => Invalid%20amount
[L_SHORTMESSAGE4] => Start%20Date%20is%20required
[L_LONGMESSAGE0] => Missing%20Token%20or%20buyer%20credit%20card
[L_LONGMESSAGE1] => Billing%20period%20must%20be%20one%20of%20Day%2c%20Week%2c%20SemiMonth%2c%20or%20Year
[L_LONGMESSAGE2] => Billing%20frequency%20must%20be%20%3e%200%20and%20be%20less%20than%20or%20equal%20to%20one%20year
[L_LONGMESSAGE3] => Bill%20amount%20must%20be%20greater%20than%200
[L_LONGMESSAGE4] => Subscription%20start%20date%20is%20required
[L_SEVERITYCODE0] => Error
[L_SEVERITYCODE1] => Error
[L_SEVERITYCODE2] => Error
[L_SEVERITYCODE3] => Error
[L_SEVERITYCODE4] => Error
)
我不知道我在哪里做错了。
谢谢你。