将项目列表添加到 PayPal Standard 按钮以进行付款

Add list of items to PayPal Standard button for payment

感觉应该可以使用 Paypal 网站上生成的标准按钮创建包含多个项目的订单。很明显,我遗漏了一些东西,如果有任何帮助或信息,我将不胜感激。下面是我的页面源代码和按下支付按钮时收到的错误消息。

    <div id="paypal-button-container"></div>
    <!-- Include the PayPal JavaScript SDK -->
    <script src="https://www.paypal.com/sdk/js?client-id=MY_SANDBOX_CLIENT_ID&enable-funding=venmo&currency=USD&debug..."></script>
    <script>
    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({
    style: {
    color: 'blue',
    shape: 'rect',
    label: 'pay',
    },
    
    // Sets up the transaction when a payment button is clicked
    createOrder: function(data, actions) {
    return actions.order.create({
  "intent": "CAPTURE",
  "payer": {
    "name": {
      "given_name": "John",
      "surname": "Doe"
    },
    "address": {
      "address_line_1": "123 nowhere lane",
      "address_line_2": "Apt 2",
      "admin_area_2": "Sacramento",
      "admin_area_1": "CA",
      "postal_code": "93423",
      "country_code": "US"
    },
    "email_address": "sb_test_email_address@business.example.com",
    "phone": {
      "phone_type": "MOBILE",
      "phone_number": {
        "national_number": "12312342343"
      }
    }
  },
  "purchase_units": [
    {
      "description": "My Purchases",
      "amount": {
        "currency_code": "USD",
        "value": "12.00",
        "breakdown": {
          "item_total": {
            "currency_code": "USD",
            "value": "12.00"
          },
          "shipping": {
            "currency_code": "USD",
            "value": "0"
          },
          "tax_total": {
            "currency_code": "USD",
            "value": "0"
          }
        }
      },
      "items": [
        {
          "name": "Item 1",
          "unit_amount": {
            "currency_code": "USD",
            "value": "6.00"
          },
          "quantity": "1"
        },
        {
          "name": "Item 2",
          "unit_amount": {
            "currency_code": "USD",
            "value": "6.00"
          },
          "quantity": "1"
        }
      ]
    }
  ]
});
    },
    
    // Finalize the transaction after payer approval
    onApprove: function(data, actions) {
    return actions.order.capture().then(function(orderData) {
    window.location.href = "Thanks.html";
    });
    },
    
    onCancel: function(data) {
    //payment cancelled
    alert("Payment Cancelled");
    },
    
    onError: function(err) {
    alert("Error Message: " + err);
    }
    }).render('#paypal-button-container');
    </script>
    </div>

The error message I get is shown in this image. Any help or guidance would be greatly appreciated.

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/TD8kw.png

在您的问题中重新格式化 Orders create request payload 以确保易读性并仅测试 payload at the demo site 后,它没有问题(下面的屏幕截图)。

您还可以在 the current documentation.

中的 'Add and modify the code' 的第 6 步中找到参考示例