Paypal Pass item sku and order reference id(PayPal Pass项目SKU和订单参考ID)
本文介绍了PayPal Pass项目SKU和订单参考ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用Java脚本API Purchase_Units向PayPal发送订单,但当PayPal重定向到成功页面时,我收到错误未知Purchase_Units。当我在控制台中检查API调用时,我在带有Purchase_Units的调用旁边看到感叹号
以下是我的代码
paypal.Buttons({
env: 'sendbox',
style: {
layout: 'horizontal',
size: 'responsive',
shape: 'pill',
color: 'gold',
fundingicons: false,
tagline: false
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [ {
reference_id: "PUHF",
description: "Some description",
custom_id: "Something7364",
soft_descriptor: "Great description 1",
amount: {
currency_code: "USD",
value: "200.00",
breakdown: {
item_total: {
currency_code: "USD",
value: "200.00"
}
}
}, items: [{
name: "Item 1",
description: "The best item ever",
sku: "xyz-2654",
unit_amount: {
currency_code: "USD",
value: "100.00"
},
quantity: "1"
}, {
name: "Item 2",
description: "Not bad too",
sku: "zdc-3942",
unit_amount: {
currency_code: "USD",
value: "50.00"
}, quantity: "2"
}
],
}
]
})}, onApprove: function(data, actions) {
return fetch('<?= $rootPath.URL['services']['orderGet'] ?>', {
method: 'GET'
}
).then(function(res) {
return res.json();
}).then(function(res) {
window.location.href = 'pages/success.php';
});
}
}).render('#paypalCheckoutContainer');
推荐答案
我将您的Purchase_Units数组复制到一个完整的有效Html示例中(下面,不要尝试在StackOverflow中运行它),并且没有任何问题。
查看代码的其余部分,env: sendbox
是一个打字错误。OnApprove部分给我带来了麻烦,我看到里面有PHP,但您的代码在删除整个onApprove部分时工作正常--所以也许可以尝试在没有该部分的情况下进行测试,然后修复它。
<!DOCTYPE html>
<!-- example from https://developer.paypal.com/demo/checkout/#/pattern/client -->
<head>
<!-- Add meta tags for mobile and IE -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=USD"></script>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
// You can find a working example purchase_units at https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
purchase_units: [ {
reference_id: "PUHF",
description: "Some description",
custom_id: "Something7364",
soft_descriptor: "Great description 1",
amount: {
currency_code: "USD",
value: "200.00",
breakdown: {
item_total: {
currency_code: "USD",
value: "200.00"
}
}
}, items: [{
name: "Item 1",
description: "The best item ever",
sku: "xyz-2654",
unit_amount: {
currency_code: "USD",
value: "100.00"
},
quantity: "1"
}, {
name: "Item 2",
description: "Not bad too",
sku: "zdc-3942",
unit_amount: {
currency_code: "USD",
value: "50.00"
}, quantity: "2"
}
],
}
]
,
application_context: {
brand_name: "MyBusiness",
/*shipping_preference: 'NO_SHIPPING'*/
}
}/*end of parameters to actions.order.create*/);
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
</body>
这篇关于PayPal Pass项目SKU和订单参考ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:PayPal Pass项目SKU和订单参考ID
基础教程推荐
猜你喜欢
- 在for循环中使用setTimeout 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 动态更新多个选择框 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01