javascript - 为什么我收到此 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>
解决方案
“类别”:“单一”
不确定这是否是您的具体问题,但这不是一个有效的类别,因此地图错误是有意义的。有关文档,请参见此处
类别 枚举
项目类别类型。可能的值是:
DIGITAL_GOODS
. 以电子格式存储、交付和使用的货物。PHYSICAL_GOODS
. 一种有形的物品,可以与交货证明一起运输。
推荐阅读
- ionic-framework - 修复启动图像 ionic v1 后无法在 iphone x 中查看电池状态
- ubuntu - 从外部 IP 地址访问主机
- javascript - 访问 iFrame 中的数据属性?
- javascript - 从javascript中的文本文件中读取特定单词
- protractor - 如何使用量角器使鼠标悬停在一段文本上
- informix - Informix dbexport 失败并出现错误 -425 数据库当前由另一个用户打开?
- c++ - 为什么 C++ 流使用状态位?
- mysql - MySQL 连接到 Google Cloud SQL 实例语法错误
- haskell - Haskell 如何编译大数?
- multithreading - Spring Boot:我们如何实现多个@Scheduled 任务,每个任务都有自己的线程池?