【问题标题】:Paypal Smart Button Check Postal Code onApprovePaypal 智能按钮检查邮政编码 onApprove
【发布时间】:2020-07-13 19:03:48
【问题描述】:

问题: 我试图弄清楚如何检查邮政编码(在贝宝智能按钮结账期间输入)是否符合特定要求。 我有 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');

【问题讨论】:

    标签: paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:
    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 调用来获取已批准订单的详细信息,然后再捕获它。

    【讨论】:

      猜你喜欢
      • 2014-08-26
      • 2015-01-22
      • 2020-10-19
      • 2020-06-28
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多