paypal - Paypal 智能按钮检查邮政编码 onApprove
问题描述
问题:我试图弄清楚如何检查邮政编码(在贝宝智能按钮结帐期间输入)是否满足特定要求。我有 createOrder 和 onApprove 对象属性我想在捕获付款之前检查邮政编码,以便我可以拒绝它并取消订单。
paypal.Buttons(
{
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units:
[
{
description: "Raffle Tickets",
custom_id: $('#cartID').val(),
soft_descriptor: "soft_descriptor",
amount: {
currency_code: "CAD",
value: cartVal,
breakdown: {
item_total: {
currency_code: "CAD",
value: cartVal
}
}
},
items: itemList
}
]
});
},
onApprove: function(data, actions) {
//id like to check the postal code here, or maybe do an ajax call then on success, call the
//capture function below to finalize the payment.
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
$('#details').val(JSON.stringify(details));
$('#frmConfirm').submit();
});
}
}).render('#paypal-button-container');
解决方案
return actions.order.get().then(function(data,actions) {
console.log(data);
/* if logic on data.payer.address.postal_code goes here */
actions.order.capture().then(function(details) {
$('#details').val(JSON.stringify(details));
$('#frmConfirm').submit();
}
});
你提到了 AJAX;如果您想从这个客户端实现切换到使用服务器上的代码进行验证的实现,则有服务器端等效的 API。在这种情况下,前端看起来更像这样:https ://developer.paypal.com/demo/checkout/#/pattern/server ,并且有一个 v2/orders API 调用来获取已批准订单的详细信息在捕获它之前。
推荐阅读
- bash - 即使对于单行输入,unix 的“读取”命令也无法在没有 while 循环的情况下工作
- javascript - React fetch 没有返回正确的值?
- python - 添加新艺术家时,Matplotlib FuncAnimation 框架未渲染
- c++ - 在 Visual Studio 2019 中安装 Magick++
- docker-compose - docker-compose:如何将文件从容器映射到卷
- python - Python pandas groupby 按类别占总数的百分比
- etw - 如何列出所有活动的 ETW 会话及其输出位置,可能在 Powershell 中?
- node.js - 我想知道如何在 PM2 中使用 ngrok
- javascript - 如何按id对推送的数组进行排序?
- html - 我使用 Bootstrap4 制作的网页上未显示字体真棒图标