Paypal智能按钮在批准时检查邮政编码



问题:我正试图弄清楚如何检查邮政编码(在贝宝智能按钮结账时输入(是否符合特定要求。我有createOrder,在Approve对象属性上,我想在捕获付款之前检查邮政编码,这样我就可以拒绝它并取消订单。

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调用来获取批准订单的详细信息,然后再捕获它

最新更新