【问题标题】:Paypal sandbox post error 401 (Unauthorized)Paypal 沙箱发布错误 401(未经授权)
【发布时间】:2020-04-10 11:56:54
【问题描述】:

enter image description here我一直在关注使用 react-paypal-express-checkout 的 paypal 沙盒教程并完全按照它进行操作,但是当我尝试打开 paypal 窗口时它会立即关闭并抛出此错误。

照片:Photo Here

文字:

http.js:147 POST https://www.sandbox.paypal.com/v1/payment-experience/web-profiles 401 (Unauthorized)

types.js:121 Uncaught Error: Request to post https://www.sandbox.paypal.com/v1/payment-experience/web-profiles failed with 401 error. Correlation id: bfca9a9c3fdfc

{
    "name": "AUTHENTICATION_FAILURE",
    "debug_id": "bfca9a9c3fdfc",
    "message": "Authentication failed due to invalid authentication credentials or a missing Authorization header",
    "information_link": "https://developer.paypal.com/docs/api/payment-experience/#errors",
    "details": []
}

    at XMLHttpRequest.xhrLoad (http.js:114)
    at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
    at receiveMessage (index.js:114)
    at messageListener (index.js:140)
    at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
    at receiveMessage (index.js:114)
    at messageListener (index.js:140)
_RECEIVE_MESSAGE_TYPE.<computed> @ types.js:121
receiveMessage @ index.js:114
messageListener @ index.js:140
setTimeout (async)
dispatchPossiblyUnhandledError @ exceptions.js:16
(anonymous) @ promise.js:122
setTimeout (async)
reject @ promise.js:120
dispatch @ promise.js:179
reject @ promise.js:127
dispatch @ promise.js:179
reject @ promise.js:127
dispatch @ promise.js:186
reject @ promise.js:127
(anonymous) @ promise.js:157
dispatch @ promise.js:184
reject @ promise.js:127
(anonymous) @ promise.js:51
respond @ client.js:147
_RECEIVE_MESSAGE_TYPE.<computed> @ types.js:126
receiveMessage @ index.js:114
messageListener @ index.js:140
serialize.js:175 Uncaught Error: Error: Request to post https://www.sandbox.paypal.com/v1/payment-experience/web-profiles failed with 401 error. Correlation id: bfca9a9c3fdfc

{
    "name": "AUTHENTICATION_FAILURE",
    "debug_id": "bfca9a9c3fdfc",
    "message": "Authentication failed due to invalid authentication credentials or a missing Authorization header",
    "information_link": "https://developer.paypal.com/docs/api/payment-experience/#errors",
    "details": []
}

    at XMLHttpRequest.xhrLoad (http.js:114)
    at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
    at receiveMessage (index.js:114)
    at messageListener (index.js:140)
    at Object._RECEIVE_MESSAGE_TYPE.<computed> [as postrobot_message_response] (types.js:121)
    at receiveMessage (index.js:114)
    at messageListener (index.js:140)
    at deserializeError (serialize.js:175)
    at serialize.js:212
    at util.js:140
    at eachArray (util.js:102)
    at each (util.js:116)
    at replaceObject (util.js:138)
    at util.js:147
    at eachObject (util.js:109)
    at each (util.js:118)
    at replaceObject (util.js:138)

这是我的按钮的页面,所有教程人员更改的是我所做的沙箱 ID:

import React from 'react';
import PaypalExpressBtn from 'react-paypal-express-checkout';

export default class MyApp extends React.Component {
    render() {
        const onSuccess = (payment) => {
            // Congratulation, it came here means everything's fine!
                    console.log("The payment was succeeded!", payment);
                    // You can bind the "payment" object's value to your state or props or whatever here, please see below for sample returned data
        }

        const onCancel = (data) => {
            // User pressed "cancel" or close Paypal's popup!
            console.log('The payment was cancelled!', data);
            // You can bind the "data" object's value to your state or props or whatever here, please see below for sample returned data
        }

        const onError = (err) => {
            // The main Paypal's script cannot be loaded or somethings block the loading of that script!
            console.log("Error!", err);
            // Because the Paypal's main script is loaded asynchronously from "https://www.paypalobjects.com/api/checkout.js"
            // => sometimes it may take about 0.5 second for everything to get set, or for the button to appear
        }

        let env = 'sandbox'; // you can set here to 'production' for production
        let currency = 'USD'; // or you can set this value from your props or state
        let total = 1; // same as above, this is the total amount (based on currency) to be paid by using Paypal express checkout
        // Document on Paypal's currency code: https://developer.paypal.com/docs/classic/api/currency_codes/

        const client = {
            sandbox:    'ASloDPNYZO9LtigzQd58tcYQHuORCH3TlvPS-LWMdwzIWiEiefonUQE7KmWCE-WkaEaiiJb54RSNcrLE',
            production: 'YOUR-PRODUCTION-APP-ID',
        }
        // In order to get production's app-ID, you will have to send your app to Paypal for approval first
        // For sandbox app-ID (after logging into your developer account, please locate the "REST API apps" section, click "Create App"):
        //   => https://developer.paypal.com/docs/classic/lifecycle/sb_credentials/
        // For production app-ID:
        //   => https://developer.paypal.com/docs/classic/lifecycle/goingLive/

        // NB. You can also have many Paypal express checkout buttons on page, just pass in the correct amount and they will work!
        return (
            <PaypalExpressBtn env={env} client={client} currency={currency} total={total} onError={onError} onSuccess={onSuccess} onCancel={onCancel} />
        );
    }
}

【问题讨论】:

    标签: paypal paypal-sandbox


    【解决方案1】:

    react-paypal-express-checkout 存储库没有引用 v1/payment-experience/web-profiles ,所以我不确定您的错误实际上来自哪里

    v1/payment-experience/web-profiles API 需要有效的ClientIdSecret 进行身份验证。

    【讨论】:

    • 我输入了正确的ClientId,视频中的人不需要秘密,您有什么建议可以尝试吗?
    • 您的特定 npm 或 react 环境可能引入了不同的依赖项或做不同的事情您需要找出调用 v1/payment-experience/web-profiles API 的内容,并检查其配置
    猜你喜欢
    • 1970-01-01
    • 2017-01-16
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    • 2017-12-20
    相关资源
    最近更新 更多