首页 > 解决方案 > 为什么我收到此 Paypal 创建订单错误?

问题描述

当我运行此代码并单击 Paypal 按钮时,我收到以下错误:

错误:“类型错误:无法读取属性‘地图’

知道这是为什么吗?据我所知,我的格式正确。(显然我用我的客户 ID 替换了 MY_CLIENT_ID)。

我正在假设这不需要任何服务器端代码来支持它。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://www.paypal.com/sdk/js?currency=GBP&client-id=MY_CLIENT_ID"></script>
</head>
<body>

<div id="paypal-button-container"></div>

<!-- Add the checkout buttons, set up the order and approve the order -->
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create([{
"purchase_units":{
"reference_id":"HOP_6rN2fD3oyM",
"description":"Hop Music Lesson Purchase",
"custom_id":"HOP_6rN2fD3oyM",
"soft_descriptor":"HOP_6rN2fD3oyM",
"amount":{
"currency_code":"GBP",
"value":"36",
"breakdown":{
"item_total":{"currency_code":"GBP",
"value":"36"}}
},
"items":[{
"name":"Single Lesson, In-Person: 45 mins",
"description":"Single Lesson, In-Person: 45 mins",
"sku":"45MIN_SINGLE_INPERSON",
"unit_amount":{
"currency_code":"GBP",
"value":"36"},
"quantity":"1",
"category":"DIGITAL_GOODS"
}]
}}]);
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container'); // Display payment options on your web page
</script>


</body>
</html>

标签: javascriptjsonpaypal

解决方案


“类别”:“单一”

不确定这是否是您的具体问题,但这不是一个有效的类别,因此地图错误是有意义的。有关文档,请参见此处

类别 枚举

项目类别类型。可能的值是:

  • DIGITAL_GOODS. 以电子格式存储、交付和使用的货物。
  • PHYSICAL_GOODS. 一种有形的物品,可以与交货证明一起运输。

推荐阅读