尝试将我的Paypal REST api网站上线。它在沙盒模式下运作良好,传输已通过验证。
当我将沙箱切换为实时客户端ID和密码时,会收到错误消息
{"error":"invalid_client","error_description":"Client Authentication failed"}
我检查并确保我的代码可以上线
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
PP_CLIENT_ID , // ClientID
PP_CLIENT_SECRET // ClientSecret
)
);
// setting mode to live
// https://github.com/paypal/PayPal-PHP-SDK/wiki/Going-Live
$apiContext->setConfig([
'mode' => 'live',
]);
通过wp_ajax运行此
任何帮助将不胜感激!谢谢!
2/5/2019:似乎其他人遇到了此问题:https://github.com/paypal/PayPal-PHP-SDK/issues/435
我错过了与StackOverflow相同的问题...也没有答案。 PayPal App works perfectly as Sandbox, Client Authentication failed on Live: list of steps to check?
答案 0 :(得分:3)
在沙盒API的PayPal REST API文档工作之后,尝试生成REST API令牌时遇到了类似的问题。直播应该是一样的。确保您获取的是REST API凭据,而不是“ NVP / SOAP API应用程序”机密。
转到此处:https://developer.paypal.com/developer/applications/
在顶部选择沙盒或实时
点击Create App
下的REST API apps
,而不是NVP/SOAP API apps
。
这将为您提供一个Client ID和Secret,它们看起来都像一串大小写的字母数字字符,长度约为40至50个字符。
使用这些凭据,运行以下curl命令以获取访问令牌,以便可以调用REST API,替换客户端ID和密码:
curl -v POST https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "CLIENT_ID:SECRET" \
-d "grant_type=client_credentials"
这应该返回您的令牌:
Sample response
{
"scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
"access_token": "A21AAFEpH4PsADK7qSS7pSRsgzfENtu-Q1ysgEDVDESseMHBYXVJYE8ovjj68elIDy8nF26AwPhfXTIeWAZHSLIsQkSYz9ifg",
"token_type": "Bearer",
"app_id": "APP-80W284485P519543T",
"expires_in": 31668,
"nonce": "2020-04-03T15:35:36ZaYZlGvEkV4yVSz8g6bAKFoGSEzuy3CQcz3ljhibkOHg"
}
您通常不会将这些东西集成到您的应用程序中,而是先做一次,然后将REST API令牌嵌入到您的应用程序中。
我知道这是在重复显而易见的事情,但我希望这会有所帮助。
在此处查看更多说明:https://developer.paypal.com/docs/platforms/get-started/#step-1-get-api-credentials
答案 1 :(得分:1)
我知道这是一篇旧帖子,但万一其他人遇到此问题:开发者帐户没有实际处理卡片的能力,因此尝试访问生产端点 (https://api-m.paypal.com/v1/) 将返回:
{"error":"invalid_client","error_description":"Client Authentication failed"}
答案 2 :(得分:0)
https://developer.paypal.com/docs/api/overview/#api-requests
使用实时凭据时 网址应为https://api.paypal.com 代替 https://api.sandbox.paypal.com
参考 https://github.com/paypal/PayPal-PHP-SDK/issues/435#issuecomment-462133355
答案 3 :(得分:0)
尝试更改
return new SandboxEnvironment($clientId, $clientSecret);
到
return new ProductionEnvironment($clientId, $clientSecret);
在您的PayPalClient.php类中