【问题标题】:How to link order id for my ecommerce with react PayPal如何将我的电子商务的订单 ID 与 React PayPal 联系起来
【发布时间】:2021-04-30 22:59:44
【问题描述】:

我有一个与 PayPal 链接的 React 应用程序,PayPal 参数不希望我传递我的订单 ID,这是支付时哪个产品用户的标识符,或者至少我似乎找不到可以传递的参数在那里,当 IPN 将通知带回我的网站时,我可以查看用户

我的组件看起来像这样

<PayPalScriptProvider options={{
                    "client-id": PAYPAL_CLIENT_ID
                }
                }>

                    <div>
                        <PayPalButtons style={{ height: 25 }}
                            createOrder={this.createOrder}
                            forceReRender={this.state.amount}
                            onApprove={this.paymentHandler}
                            onError={(error) => alert(error)} />
                    </div>
</PayPalScriptProvider>

onApprove 方法中,我注销了这些值并得到了一个orderID 参数,它似乎不是IPN 返回值的一部分 Approve上的数据是这样的

{'orderID': '6BX576974S2955109', 'payerID': 'NMWXFKW5ZW5EC', 'paymentID': None, 'billingToken': None, 'facilitatorAccessToken': 'toekn here'}

谁能帮我解决这个问题,比如我可以使用什么参数将我自己的值传递给 react-PayPal 以便它在 IPN 中返回?

【问题讨论】:

    标签: reactjs paypal


    【解决方案1】:

    createOrder 函数应使用 Orders V2 对象调用 PayPal SDK 的 actions.order.create()。可用参数为documented here

    如果您自己的“订单 ID”是唯一的——以前从未用于成功捕获的付款——您可以将其作为 invoice_id 参数包含在 purchase_unit 中。唯一性很重要,因为默认情况下无法捕获重复的(以前使用/捕获的)invoice_id。付款人可以在他们的交易详情中看到此 invoice_id。

    如果您想要一个可以存储任意数据的字段,请使用custom_id。付款人看不到此值。

    【讨论】:

    • 刚试了下出现错误,组件无法渲染Bad object: {"purchase_unit": { "custom_id": 2 } } Valid keys: [ "buyer-country", "client-id", "commit", "components", "currency", "data-client-token", "data-csp-nonce", "data-order-id", "data-page-type", "data-partner-attribution-id", "debug", "disable-funding", "integration-date", "intent", "locale", "merchant-id", "vault" ]
    • 您正在将密钥传递给配置。不要那样做。 createOrder 函数发生变化
    • 好的,刚刚解决了这个问题......我把它放在错误的地方应该是在 createOrder 函数中......非常感谢
    • 更仔细地阅读您的问题,因为您的 ID 用于产品而不是“订单 ID”,因此您可能想要传递 items 数组而不是 custom_id ,例如stackoverflow.com/questions/59448758/…
    猜你喜欢
    • 2022-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 2021-12-28
    • 2012-04-25
    • 2012-09-10
    相关资源
    最近更新 更多