如何解决PayPal 401 客户端身份验证在具有节点 js sdk 的沙盒环境中失败
我已按照本指南 https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/ 和此示例 https://github.com/paypal/Checkout-Nodejs-SDK/
这是我的代码:
import paypalCheckout from '@paypal/checkout-server-sdk';
const environment = new paypalCheckout.core.SandboxEnvironment(
'ACTUAL_CLIENT_ID_FROM_PAYPAL_DASHBOARD','ACTUAL_CLIENT_SECRET_FROM_PAYPAL_DASHBOARD'
);
const client = new paypalCheckout.core.PayPalHttpClient(environment);
const request = new paypalCheckout.orders.OrdersCreateRequest();
request.requestBody({
intent: 'CAPTURE',purchase_units: [
{
amount: {
currency_code: 'USD',value: `100.00`
}
}
],});
client.execute(request)
.then((response) => {
console.log(`${JSON.stringify(response)}`);
console.log(`${JSON.stringify(response?.result)}`);
})
.catch((executeError) => {
console.log(`${JSON.stringify(executeError)}`);
});
我明白了:
{
error: HttpError: {"error":"invalid_client","error_description":"Client Authentication failed"}
at IncomingMessage.<anonymous> (.../node_modules/@paypal/paypalhttp/lib/paypalhttp/http_client.js:136:22)
at IncomingMessage.emit (events.js:388:22)
at endReadableNT (internal/streams/readable.js:1336:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
statusCode: 401,headers: {
'content-type': 'application/json','content-length': '77',connection: 'close',date: 'Tue,29 Jun 2021 01:22:38 GMT','cache-control': 'max-age=0,no-cache,no-store,must-revalidate','paypal-debug-id': 'c2b.......c7a','x-paypal-token-service': 'IAAS','strict-transport-security': 'max-age=31536000; includeSubDomains'
},_originalError: {
text: '{"error":"invalid_client","error_description":"Client Authentication failed"}',statusCode: 401,headers: [Object]
}
},message: '{"error":"invalid_client","error_description":"Client Authentication failed"}'
}
我已经在 Google 和 Stack Overflow 上搜索过,但我只发现从沙盒切换到直播的类似问题。
我的代码无法在沙盒环境中运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。