javascript - 使用 PayPal 智能按钮的动态运费
问题描述
我在我的网站上使用 PayPal 智能按钮。如何按国家/地区制定不同的运费?我根据PayPal教程在这里尝试了这个:
<script>
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: document.getElementById("Color").innerText,
amount: {
value:
{{ current_variant.price | divided_by: 100.00 }}
},
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name + '! Thank You For Your
Purchase');
});
},
常量 baseOrderAmount = '15.00'; onShippingChange:函数(数据,操作){
// Patch the shipping amount
const shippingAmount = data.shipping_address.country_code === 'US' ? '5.00' : '0.00';
return actions.order.patch([
{
op: 'replace',
path: '/purchase_units/@reference_id==\'default\'/amount',
value: {
currency_code: 'USD',
value: (parseFloat(baseOrderAmount) + parseFloat(shippingAmount)).toFixed(2),
breakdown: {
item_total: {
currency_code: 'USD',
value: baseOrderAmount
},
shipping: {
currency_code: 'USD',
value: shippingAmount
}
}
}
}
]);
}
}).render('#paypal-button-container');
我试图只向美国运送 5 美元,因为这是我的供应商费用。我也尝试了一些 if/else 语句,但似乎没有任何效果!我究竟做错了什么?或者也许有人知道用这些 PayPal 按钮制作这个的其他方法?到目前为止没有发现任何有用的东西。顺便说一句 - 使用 Shopify Narrative Theme 物有所值。
解决方案
推荐阅读
- css - Max Mega Menu 中的标签样式
- php - 如何使用 in_array 获取数组中的值而不是 true?
- javascript - 多个日历 DIALOGFLOW
- git - 我的大更新的 github 推送错误:rpc 失败
- python - python 3中的函数调用
- javascript - 遍历对象并根据现有值更新值
- python-3.x - 使用 bash 脚本在子目录中运行机器人框架测试
- scipy - 使用单个 GPU 时的内存分配
- java - selenium java 为 xlink:href 属性加载图像
- elasticsearch - 什么时候在 Lucene 中应用删除