我一直在尝试创建一个Paypal自适应支付API调用到沙箱现在一整天没有成功。我读了几十个教程,SE线程等,但没有一个我尝试过。我一直得到"身份验证失败"。" API凭据不正确" .
下面是我使用的代码:
$baseurl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
define('PAYPAL_API_USER', '<snip>');
define('PAYPAL_API_PWD', '<snip>');
define('PAYPAL_API_SIGNATURE', '<snip>');
define('PAYPAL_API_APPLICATION_ID', 'APP-80W284485P519543T');
$returnurl = "<snip>";
$cancelurl = "<snip>";
$data = array(
"actionType" => "PAY",
"currencyCode" => "USD",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "1.00",
"email" => "<snip>"
),
)
),
"returnUrl" => $returnurl,
"cancelUrl" => $cancelurl,
"requestEnvelope" => array(
"errorLangauge" => "en_US",
"detailLevel" => "ReturnAll",
)
);
$headers = array(
"X-PAYPAL-SECURITY-USERID: ".PAYPAL_API_USER,
"X-PAYPAL-SECURITY-PASSWORD: ".PAYPAL_API_PWD,
"X-PAYPAL-SECURITY-SIGNATURE: ".PAYPAL_API_SIGNATURE,
"X-PAYPAL-SECURITY-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-SECURITY-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-SECURITY-APPLICATION-ID: ".PAYPAL_API_APPLICATION_ID,
);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $baseurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt ($ch, CURLOPT_HEADER, $headers);
print_r(curl_exec($ch));
我在developer.paypal.com的"Sandbox test accounts"下创建了几个测试帐户。我尝试使用他们的用户名+密码+签名(从API凭据选项卡)在上面的代码。总是收到"身份验证失败。"API凭证不正确。"
<标题>编辑1:在这个页面:https://developer.paypal.com/docs/classic/adaptive-payments/gs_AdaptivePayments/他们有一个类似的curl命令。我运行这个命令:
curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: caller_1312486258_biz_api1.gmail.com" -H "X-PAYPAL-SECURITY-PASSWORD: 1312486294" -H "X-PAYPAL-SECURITY-SIGNATURE: AbtI7HV1xB428VygBUcIhARzxch4AL65.T18CTeylixNNxDZUu0iO87e" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/AdaptivePayments/Pay -d "{"actionType":"PAY", "currencyCode":"USD", "receiverList":{"receiver":[{"amount":"1.00","email":"rec1_1312486368_biz@gmail.com"}]}, "returnUrl":"http://www.example.com/success.html", "cancelUrl":"http://www.example.com/failure.html", "requestEnvelope":{"errorLanguage":"en_US", "detailLevel":"ReturnAll"}}"
在终端窗口中,并得到一个付款创建成功响应。因此,接下来我将这个命令中的用户名/密码/签名与原始问题中的用户名/密码/签名交换,猜猜看,这也起作用了!
最后,我使用了示例中的用户名/密码/签名在PHP curl代码从我的原始问题,并再次得到"身份验证失败。API凭据不正确"消息。
总而言之,如果通过终端运行,用户名/密码/签名组合(我的和Paypal的)都会生成成功响应,但是当通过我的PHP CURL代码运行时,都会产生身份验证失败错误。所以我的原始代码肯定有问题,问题是什么??<标题>编辑2:仍然不能让它工作,但我认为这是与头位有关。原因如下:看看我收到的完整回复:
HTTP/1.1 200 OK
Date: Tue, 13 Oct 2015 11:51:23 GMT
Server: Apache
X-EBAY-SOA-REQUEST-ID: 150610a6-a690-a488-6781-12e6ffa2f8dd!AdaptivePayments!10.72.134.120![]
X-PAYPAL-SERVICE-VERSION: 1.0.0
X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/ap}AdaptivePayments
X-EBAY-SOA-RESPONSE-DATA-FORMAT: XML
X-PAYPAL-OPERATION-NAME: Pay
CACHE-CONTROL: no-cache
X-PAYPAL-ERROR-RESPONSE: TRUE
X-EBAY-SOA-MESSAGE-PROTOCOL: NONE
Set-Cookie: Apache=10.72.108.11.1444737084008373; path=/; expires=Thu, 05-Oct-45 11:51:24 GMT
Vary: Accept-Encoding
Paypal-Debug-Id: 32922591f3d33
Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.APIT.1%26silo_version%3D880%26app%3Dadaptivepaymentspartaweb_api3t%26TIME%3D1005591638; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml;charset=UTF-8
<?xml version='1.0' encoding='UTF-8'?><ns3:FaultMessage xmlns:ns3="http://svcs.paypal.com/types/common" xmlns:ns2="http://svcs.paypal.com/types/ap"><responseEnvelope><timestamp>2015-10-13T04:51:24.021-07:00</timestamp><ack>Failure</ack><correlationId>e133487976d4b</correlationId><build>17820627</build></responseEnvelope><error><errorId>520003</errorId><domain>PLATFORM</domain><subdomain>Application</subdomain><severity>Error</severity><category>Application</category><message>Authentication failed. API credentials are incorrect.</message></error></ns3:FaultMessage>
我指定JSON作为响应数据格式的原因是XML。因此,如果响应格式行被忽略或不能正确读取,我猜同样的事情是混淆登录细节。
标题>标题>如果您100%确定业务沙箱帐户的API凭据是正确的,那么请验证您有正确的应用程序id。APP Id需要是您为Adaptive Payments提交的应用程序中的APP Id。如果你还没有提交申请,下面是说明:
如何提交开发者应用程序
如果您已经申请了Adaptive Payments,请转到您的应用程序列表,然后单击您的应用程序以验证正确的应用程序id。