Paypal - 尝试实施定期付款时的付款问题
Posted
技术标签:
【中文标题】Paypal - 尝试实施定期付款时的付款问题【英文标题】:Paypal - payment issue while trying to implement recurring payment 【发布时间】:2015-11-07 10:49:41 【问题描述】:paypalrecurring.php
private $test = false;
private $liveServer = 'https://api-3t.paypal.com/nvp'; # https://api.paypal.com/nvp
private $testServer = 'https://api-3t.sandbox.paypal.com/nvp'; # https://api.sandbox.paypal.com/nvp
private $methodName = 'CreateRecurringPaymentsProfile';
public function sendRequest()
$nvpreq = '';
foreach ($this->request as $fldname => $val)
if($val != '') $nvpreq .= strtoupper($fldname) . "=" . urlencode($val) . "&";
$url = ($this->test) ? $this->testServer : $this->liveServer;
$post = "METHOD=" . $this->methodName . "&" . $nvpreq . "&VERSION=56.0";
$retstr = $this->sendAPIRequest($url . "?" . $post);
$retarrtmp = explode("&",$retstr);
$retarr = array();
for($i=0;$i<count($retarrtmp);$i++)
$sparr = explode("=",$retarrtmp[$i]);
$txt = urldecode($sparr[0]);
$val = urldecode($sparr[1]);
$retarr[$txt] = $val;
return $retarr;
/**
* True for test server. False for production.
* @param bool $isTest
*/
public function setIsTest($isTest)
$this->test = $isTest;
private function sendAPIRequest($url)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if(curl_errno($ch))
$response = curl_error($ch);
curl_close($ch);
return $response;
Usageexample.php
<?php
require_once 'PaypalRecurring.php';
$pp = new PayPalRecurring();
$pp->setIsTest(true); // PayPal test sandbox or live server
// Your PayPal account credentials go here
$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';
// End PayPal account credentials
// User info
$pp->request['firstname'] = 'The users first name';
$pp->request['lastname'] = 'The users last name';
$pp->request['email'] = 'The users email address';
$pp->request['creditcardtype'] = 'Visa'; // Visa, Mastercard, Discover, Amex
$pp->request['acct'] = ''; // Credit card number
$pp->request['expdate'] = str_pad('8',2,'0', STR_PAD_LEFT) .'2020'; // Expiration month and full year. Pad the month with 0. Month should be 1-12. This example is 8/2020.
// End user info
// Product info
$pp->request['countrycode'] = 'US';
$pp->request['billingperiod'] = 'Month'; // Bill per month
$pp->request['billingfrequency'] = 1; // How many times to bill per billing period.. This example is once per month
$pp->request['currencycode'] = 'USD';
$pp->request['amt'] = 9.95; // Amount to bill every month
$pp->request['initamt'] = 0.00; // Setup fee.. One time on account creation
$pp->request['taxamt'] = $pp->request['amt'] * .07; // Replace .07 with your tax percentage. 0 for no tax.
$pp->request['desc'] = 'Super Deluxe Package'; // The description of your product for reporting in your account
$pp->request['profilestartdate'] = gmdate('Y-m-d\TH:i:s\Z');
$pp->request['totalbillingcycles'] = '3'; // How many billing cycles. 0 for no expiration. This example is for 3 total months of billing.
$pp->request['payerstatus'] = 'verified';
// End product info
$ppResponse = $pp->sendRequest();
if(isset($ppResponse['L_ERRORCODE0']))
echo "Error: $ppResponse['L_LONGMESSAGE0']";
else if(isset($ppResponse['ACK']) && $ppResponse['ACK'] == ('Success' || 'SuccessWithWarning'))
echo "Success: $ppResponse['ACK']";
else
print_r($ppResponse);
每当我尝试在贝宝中实施定期付款时总是出错
security header is not valid
以上示例来自github
我需要在电子商务网站中集成定期付款
我有两个文件paypalrecurring.php
& usageExample.php
当我执行usageExample.php
时出现错误security header is not valid
谁能帮帮我
【问题讨论】:
也许这会有所帮助:***.com/questions/1712685/… 【参考方案1】:这是因为您在以下代码中的 API 凭据不正确。
$pp->request['user'] = 'xxx';
$pp->request['pwd'] = 'xxx';
$pp->request['signature'] = 'xxx';
您可以按照以下步骤查找您的 API 凭据:
对于沙盒帐户:
访问https://developer.paypal.com/并登录,然后访问以下网址:
https://developer.paypal.com/developer/accounts
点击用于测试的企业帐户,然后点击该帐户下的“个人资料”链接。 然后单击“API Credentials”选项卡,您将找到 API 凭据。
对于真实账户:
登录 www.paypal.com,进入 Profile->Selling tools->API Access,点击“Request API credentials”链接, 然后选择“请求 API 签名”并单击“同意并提交”。 然后你可以在最后一页找到你的 API 用户名、API 密码和 API 签名。
【讨论】:
由于此错误通常是由于凭据不正确,您是否再次确认您的沙盒凭据正确? 您可能需要联系 PayPal 商家技术支持:paypal-techsupport.com,提供您的帐户和所有 API 请求和响应,然后我们将进一步调查。以上是关于Paypal - 尝试实施定期付款时的付款问题的主要内容,如果未能解决你的问题,请参考以下文章