gpt4 book ai didi

javascript - Paypal Checkout 集成 - onShippingChange 不适用于新的 SDK

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:54 26 4
gpt4 key购买 nike

我跟着教程 https://developer.paypal.com/docs/checkout/integrate/并且还想根据运送国家/地区更改运费,如此处所示 https://developer.paypal.com/docs/checkout/integration-features/shipping-callback/

我的“Paypal-Button”代码如下所示

<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXX&currency=EUR">
</script>
</head>
<body>

<h2>Checkout</h2>

<div id="paypal-button-container"></div>
<script>
const baseOrderAmount = '15.00';
const addFloats = (...floats) => floats.reduce((v, t) => parseFloat(t) + parseFloat(v), 0).toFixed(2);

paypal.Buttons({

createOrder: function(data, actions) {
// Set up the transaction
return actions.order.create({
purchase_units: [{
amount: {
value: baseOrderAmount
}
}]
});
},

onApprove: function(data, actions) {
// Capture the funds from the transaction
return actions.order.capture().then(function(details) {
// Show a success message to your buyer
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/paypal-transaction-complete.php', {
method: 'post',
body: JSON.stringify({
orderID: data.orderID
})
});
});
},

onShippingChange: function(data, actions) {

// Reject all others
if ((data.shipping_address.country !== 'DE') || (data.shipping_address.country !== 'AT') || (data.shipping_address.country !== 'CH')) {
return actions.reject();
}

// Patch the shipping amount
var shippingAmount = 10.0;
if (data.shipping_address.country == 'AT') {
shippingAmount = 20.0;
}
if (data.shipping_address.country == 'CH') {
shippingAmount = 30.0;
}

return actions.order.patch([
{
op: 'replace',
path: "/purchase_units/@reference_id=='default'/amount",
value: {
currency_code: 'EUR',
value: addFloats(baseOrderAmount, shippingAmount),
breakdown: {
item_total: {
currency_code: 'EUR',
value: baseOrderAmount
},
shipping: {
currency_code: 'EUR',
value: shippingAmount
}
}
}
}]);
}
}).render('#paypal-button-container');
</script>
</body>
</html>

其他一切正常,但是当我包含 onShippingChange() 时,我总是从 paypal 收到消息,“卖家不在这个国家发货,使用不同的地址......”(但我使用德国地址)。

最佳答案

更改以下行:

data.shipping_address.country

收件人:

data.shipping_address.country_code

最好的问候,托马斯

关于javascript - Paypal Checkout 集成 - onShippingChange 不适用于新的 SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54890408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com