【问题标题】:PayPal Checkout with Smart Payment Buttons (React + Redux) create order problem使用智能支付按钮(React + Redux)的 PayPal 结帐创建订单问题
【发布时间】:2020-10-21 16:59:24
【问题描述】:

每当我尝试处理付款时,我都会收到422 error: Unprocessable entity。 当我动态地想要捕获从 redux 商店收到的购买项目详细信息时,就会出现此问题。

我尝试遵循这种格式(重复):PayPal Checkout (javascript) with Smart Payment Buttons create order problem

这与 PayPal 文档中的相同:https://developer.paypal.com/docs/api/orders/v2/#definition-item

但是,这无济于事。这是我的代码

import React, {useState, useEffect, useRef} from 'react';
import {useSelector, useDispatch} from 'react-redux'

const mapState = ({ cart }) => ({
    itemsInCart: cart.itemsInCart,
    total: cart.total

})

const Cart = props => {
  
    const {itemsInCart} = useSelector(mapState);


        useEffect(() => {
          const itemsObj = itemsInCart.map(item => {
            return {
              name: item.name,
              description: item.description,
              unit_amount: {
                              currency_code: "USD",
                               value: item.price
              },
              quantity: "1"
            }
          })


          window.paypal
              .Buttons({
                createOrder: (data, actions) => {
                  return actions.order.create({
                    purchase_units: [
                      {
                        description: "Your purchase details",
                        amount: {
                          currency_code: 'USD',
                          value: document.getElementById('totalAmount').innerHTML
                        },
                        items: itemsObj
                        },
                    ],
                  });
                }

如果我将items 属性更改为item_list,正如我在某些文档中看到的那样,付款会通过,但不会捕获项目对象。我不知道为什么。

【问题讨论】:

    标签: javascript reactjs redux paypal


    【解决方案1】:

    如果您想将订单项捕获为 items 属性,则必须在 amount 属性中指定细分,如下所示:

     purchase_units: [
                  {
                    description: "test",
                    amount: {
                      currency_code: "USD",
                      value: price,
                      breakdown: {
                        item_total: {
                          currency_code: "USD",
                          value: document.getElementById("totalAmount").innerHTML
                        }
                      }
    

    这篇文章对于完整的代码示例也很有帮助: https://www.paypal-community.com/t5/REST-APIs/PayPal-Checkout-javascript-with-Smart-Payment-Buttons-create/m-p/1824785#M2816

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 2020-06-23
      • 2020-05-09
      • 2020-03-23
      • 2019-12-11
      • 2020-08-07
      • 2020-10-16
      • 2021-05-01
      • 2020-10-06
      相关资源
      最近更新 更多