Paypal 智能按钮检查邮政编码 onApprove

Paypal Smart Button Check Postal Code 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;如果您想从此客户端实现切换到使用服务器上的代码进行验证的实现,则有服务器端等效的 APIs。在那种情况下,前端看起来更像这样: https://developer.paypal.com/demo/checkout/#/pattern/server ,并且有一个 v2/orders API 调用在捕获之前获取已批准订单的详细信息。