【问题标题】:Why am I getting this Paypal create order error?为什么我收到此 Paypal 创建订单错误?
【发布时间】:2020-10-12 20:39:59
【问题描述】:

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

err: "TypeError: 无法读取属性 'map'

知道这是为什么吗?据我所知,我的格式正确。 (显然我用我的客户 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>

【问题讨论】:

    标签: javascript json paypal


    【解决方案1】:

    "类别":"SINGLE"

    不确定这是否是您的具体问题,但这不是一个有效的类别,因此地图错误是有意义的。 See here for the documentation

    类别 枚举

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

    • DIGITAL_GOODS。以电子格式存储、交付和使用的商品。
    • PHYSICAL_GOODS。一种有形的物品,可以通过交货证明发货。

    【讨论】:

    • 啊,好地方,谢谢。但不幸的是,这并不能解决问题。更新了上面的代码。
    • 好的,运行你的代码,在控制台中真正的错误是“purchase_units is undefined”。您有错误的数组和对象结构,如果您的代码正确缩进,这将更容易注意到。请参阅developer.paypal.com/demo/checkout/#/pattern/client 的示例进行比较
    • 我在运行代码时没有收到该错误。我将与样本进行比较,看看是否有差异。
    猜你喜欢
    • 1970-01-01
    • 2018-05-13
    • 2018-06-22
    • 2016-01-01
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多