Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

javascript - 使用REACTjs的PayPal Express Checkout授权错误(Authorization error with PayPal express checkout, using REACTjs)

I am just testing the use of the Paypal Express checkout button, but whenever I click the button as it appears in my React App, the Payment window pops up and disappears.

(我只是在测试Paypal Express结帐按钮的用法,但是每当我单击反应应用程序中显示的按钮时,“付款”窗口就会弹出并消失。)

The error is a 401: Invalid Authorization.

(错误是401:无效授权。)

Things I have tried: Changing my Sandbox ID, creating a new app and starting from scratch, using https://www.npmjs.com/package/react-paypal-express-checkout as a template

(我尝试过的事情:使用https://www.npmjs.com/package/react-paypal-express-checkout作为模板,更改沙盒ID,创建新应用并从头开始)

The problem is that even when I do these things, the express checkout function just does not seem to work.

(问题是,即使我做这些事情,快速结帐功能似乎也不起作用。)

Here is the code that I used, including my Sandbox Testing ID for this app

(这是我使用的代码,包括此应用程序的沙盒测试ID)

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:    'AQrbAVq-3CkyAKGU53fn5hCB7iFW6Pp8v3DnYpVQMeX6L2ibYJWUsYUSZXcN10IpLr_qaj6GJoUB7ZhP',
            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} />
        );
    }
}

I then simply call in my App.js file, and the button appears, but as I said, when I click on it, the window pops up and closes immediately.

(然后,我只是简单地调用我的App.js文件,然后出现按钮,但是正如我所说,当我单击它时,该窗口会弹出并立即关闭。)

Any help is appreciated!

(任何帮助表示赞赏!)

  ask by Ravi Patel translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...