Paypal Express Checkout.js - 填充产品详细信息

Posted

技术标签:

【中文标题】Paypal Express Checkout.js - 填充产品详细信息【英文标题】:Paypal Express Checkout.js - populate product details 【发布时间】:2021-02-22 18:06:49 【问题描述】:

我正在尝试使用 Paypal Express Checkout.js 填充交易详细信息下的产品详细信息。我能够正确传递总金额,但我需要获取每个产品名称和数量。

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

export default class MyApp extends React.Component 
    render() 
        const onSuccess = (payment) => 
            // 1, 2, and ... Poof! You made it, everything's fine and dandy!
                    console.log("Payment successful!", payment);
                    // You can bind the "payment" object's value to your state or props or whatever here, please see below for sample returned data
                    this.props.reset()
                    alert("Pagamento efetuado com sucesso!")

        

        const onCancel = (data) => 
            // The user pressed "cancel" or closed the PayPal popup
            console.log('Payment 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 script could not be loaded or something blocked the script from loading
            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 this string to 'production'
        let currency = 'BRL'; // you can set this string from your props or state  
        // let total = 1;  // this is the total amount (based on currency) to charge
        // Document on Paypal's currency code: https://developer.paypal.com/docs/classic/api/currency_codes/

        const client = 
            sandbox:    'Aat8DGkJm-8JrK-8SsvIvClaJpy2EohIlw8x5wDkK1DfuAKpJFHeTH0dNRg3xFywRkhn-375Fjlproca',
            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 your sandbox Client-ID (after logging into your developer account, please locate the "REST API apps" section, click "Create App" unless you have already done so):
        //   => https://developer.paypal.com/docs/classic/lifecycle/sb_credentials/
        // Note: IGNORE the Sandbox test AppID - this is ONLY for Adaptive APIs, NOT REST APIs)
        // 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=this.props.total onError=onError paymentOptions=this.props.cartList onSuccess=onSuccess onCancel=onCancel />
        );
    

如何将每个产品名称和单位传递给“产品详细信息”?谢谢。

【问题讨论】:

【参考方案1】:

使用react-paypal-button-v2 代替react-paypal-express-checkout

【讨论】:

react-paypal-express-checkout 是否已弃用? 它使用paypal支付api v1。参考paymentOptionsnpmjs.com/package/react-paypal-express-checkout#props @DaviMello 您应该使用 PayPal Smart Payment Buttons 而不是 PayPal Express Checkout Buttons

以上是关于Paypal Express Checkout.js - 填充产品详细信息的主要内容,如果未能解决你的问题,请参考以下文章

Paypal:通过 Express Checkout 定期付款,无需用户拥有 paypal 帐户

具有 Paypal 权限和 Paypal Express Checkout 的 Rails

更改 PayPal Express Checkout 插件中的 paypal 项目名称

支付完成后注销Paypal Express账户

Paypal Sandbox (express-checkout) 返回内部错误

PayPal按钮和PayPal Express Checkout之间有什么区别?