如何整合PayPal快递结帐



我正在开发一个wordpress插件,需要PayPal Express checkout功能。

我正在阅读paypal网站上关于如何集成上下文结帐功能(https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/integration-guide/ECGettingStarted/#id53620a28-e357-4744-9979-66ed5c592183)的文章,这篇文章给了我以下表单。

<form method=post action=https://api-3t.sandbox.paypal.com/nvp>
<input type=hidden name=USER value=API_username>
<input type=hidden name=PWD value=API_password>
<input type=hidden name=SIGNATURE value=API_signature>
<input type=hidden name=VERSION value=XX.0>
<input type=hidden name=PAYMENTREQUEST_0_PAYMENTACTION value=Sale>
<input name=PAYMENTREQUEST_0_AMT value=19.95>
<input type=hidden name=RETURNURL value=https://www.YourReturnURL.com>
<input type=hidden name=CANCELURL value=https://www.YourCancelURL.com>
<input type=submit name=METHOD value=SetExpressCheckout>
</form>

我已经添加了自己的API_username, API_password &来自PayPal的api_签名,但提交时显示ACK=Failure

以下是我从paypal收到的消息:

TIMESTAMP=2015%2d10%2d30T05%3a27%3a09Z&CORRELATIONID=24cb45b8dd36b&ACK=Failure&VERSION=0%2e000000&BUILD=18308778&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Security%20error&L_LONGMESSAGE0=Security%20header%20is%20not%20valid&L_SEVERITYCODE0=Error

因为这个我不能去贝宝文档的步骤2,所以需要帮助这里。我做错了什么?

试试我在我的项目中使用的代码,它可以工作。

PHP:

$paypal_url='https://www.paypal.com/cgi-bin/webscr'; 
$paypal_id='example@example.com';

HTML:

<form action='<?php echo $paypal_url; ?>' method='post' name='frmPayPal1'>
<input type='hidden' name='business' value='<?php echo $paypal_id;?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' value='Products Total'>
<input type='hidden' name='amount' value='<?php echo $tot;?>'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='handling' value='0'>
<input type='hidden' name='cancel_return' value='http://localhost/paypal/cancel.php'>
<input type='hidden' name='return' value='http://localhost/paypal/success.php'>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

要实现PayPal Express Checkout,您需要做一些服务器端代码(PHP, ASP。净,……)。你要做的是一个HTML表单不会工作。你必须做3个API调用来验证全额付款。

  • SetExpressCheckout
  • GetExpressCheckoutDetails
  • DoExpressCheckoutPayment

在每次调用中,您将使用您的API凭据。

我建议实现PayPal Express Checkout API。

与创建wordpress插件相比,使用这个方法有很多好处。主要原因是响应将立即交付,您不会使用IPN方法来检查事务是否成功。此外,您还可以在一个会话中添加几个经常性和一次性付款,包括税收和福利。你可以自由地添加所有这些东西,几乎所有的东西——这需要你的wordpress插件很酷!

这只是作为推荐。这里有一个简单的(PHP)示例,如何设置与多个产品的交易(也是定期付款):

//SetExpressCheckout的参数,这将被发送到PayPal
$padata['L_BILLINGAGREEMENTDESCRIPTION0'] = '产品描述';$padata['L_BILLINGAGREEMENTDESCRIPTION0'] = $padata['L_BILLINGAGREEMENTDESCRIPTION0']。"美元"。产品->价格。美元/月";$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';
$padata['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';$padata['PAYMENTREQUEST_0_PAYMENTACTION'] = 'SALE';
$padata[' PAYMENTREQUEST_0_ITEMAMT'] = $product->price;
$padata['L_BILLINGTYPE0'] = 'RecurringPayments';
$padata[' L_PAYMENTREQUEST_0_NUMBER0'] = '322';
$padata['L_PAYMENTREQUEST_0_QTY0'] = '1';
$padata['L_PAYMENTREQUEST_0_AMT0'] = $product->price;$padata['L_PAYMENTREQUEST_0_NAME1'] = '第二产品名称';
$hosteddata['L_PAYMENTREQUEST_0_DESC1'] = '第二产品描述';
$hosteddata[' L_PAYMENTREQUEST_0_QTY1'] = '1';
$hosteddata['L_PAYMENTREQUEST_0_AMT1'] = $secondproduct->id;$paypal_data = http_build_query($padata);$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美元("令牌")。";头(地点:。paypalurl美元);其他}{echo '错误:' .urldecode ($ httpParsedResponseAr [" L_LONGMESSAGE0 "])。";
}

页面returnurl:

$ hostddata ['L_BILLINGAGREEMENTDESCRIPTION0'] = '循环描述';
$ hostddata ['L_BILLINGAGREEMENTDESCRIPTION0'] = $ hostddata ['L_BILLINGAGREEMENTDESCRIPTION0'] .
$ hostddata ['L_BILLINGAGREEMENTDESCRIPTION0']。
$hosteddata['L_PAYMENTREQUEST_0_NAME0'] = $pr->name;
$hosteddata['PROFILEREFERENCE'] = $GetExpressCheckoutDetails['L_PAYMENTREQUEST_0_NUMBER0'];
$hosteddata['PROFILESTARTDATE'] = date('Y-m-d')。"T"。
$ hostddata ['SUBSCRIBERNAME'] = $GetExpressCheckoutDetails['FIRSTNAME'] . date('H:i:s').'Z';’"。$GetExpressCheckoutDetails['LASTNAME'];
$ hostddata ['TOKEN'] = urlencode($_POST[' TOKEN']);
$ hostddata ['DESC'] = $ hostddata ['L_BILLINGAGREEMENTDESCRIPTION0'];
$ hostddata ['AMT'] = $pr->price;
$ hostddata ['BILLINGPERIOD'] = 'Month';
$ hostddata ['BILLINGFREQUENCY'] = '1';
$ hostddata ['TOTALBILLINGCYCLES'] =
$ hostddata ['REGULARTOTALBILLINGCYCLES'] = '1';
$ hostddata ['VERSION'] = '74.0';
$ hostddata ['MAXFAILEDPAYMENTS'] = '1';
$ hostddata ['L_BILLINGTYPE0'] = 'RecurringPayments';
$ hostddata ['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Digital';
$ hostddata ['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;
$ hostddata ['L_PAYMENTREQUEST_0_AMT0'] = $pr->price;
$ hostddata ['L_PAYMENTREQUEST_0_AMT0'] = 'INITAMT']
$ hostddata ['L_PAYMENTREQUEST_0_NUMBER0'] = $pr->id;
$ hostddata ['PAYMENTREQUEST_0_NOTIFYURL'] = 'http://site_url/paypal/ipn';
$padata['L_PAYMENTREQUEST_0_NAME1'] = '第二个产品名称';$hosteddata['L_PAYMENTREQUEST_0_DESC1'] = '第二产品描述';
$hosteddata['L_PAYMENTREQUEST_0_NUMBER1'] = $secondproduct->id;
$hosteddata['L_PAYMENTREQUEST_0_QTY1'] = '1';$paypal_data = http_build_query($ hostddata);$hosted_saas_response = $this->PPHttpPost('CreateRecurringPaymentsProfile', $paypal_data);

我使用了一个单独的方法将参数发送到paypal

private function PPHttpPost($methodName_, $nvpStr_) {
$api_username = 'yourpaypal@email.com';$api_password = ' qweqqeqweqqqwe ';
$api_signature = ' wqeqweqweqweqweqweqweqwe . ct ';
$api_endpoint = "https://api-3t.paypal.com/nvp";
$version = '124.0';
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$ api_signure&$ nvpStr_";
curl_setopt($ch, CURLOPT_POSTFIELDS, $ch, CURLOPT_URL, $ api_postfields,美元nvpreq);
$ httpResponse = curl_exec (ch);

如果(! $ httpResponse) {退出(" $ methodName_失败:".curl_error (ch美元)。"(".curl_errno (ch)美元。)"),
}

//提取响应的细节。
$ httpResponseAr =爆炸("&",httpResponse美元);
$ httpParsedResponseAr =数组();

foreach (httpResponseAr i =>美元美元值){
$ tmpAr =爆炸("=",价值美元);
如果(sizeof (tmpAr美元)> 1){
httpParsedResponseAr美元(美元tmpAr [0]] = $ tmpAr [1],
}

}if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit(" POST request($nvpreq) to $api_endpoint.");
}返回httpParsedResponseAr美元;
}

相关内容

  • 没有找到相关文章

最新更新