【问题标题】:Remove shipping address option in PayPal Express Checkout删除 PayPal Express Checkout 中的送货地址选项
【发布时间】:2017-04-17 20:54:48
【问题描述】:

我正在使用 PayPal 推荐的 JS script。它运行良好,但显示的是买家的“收货”地址。

我正在尝试搜索互联网,发现使用"no_shipping": 1, 请求的https://api.sandbox.paypal.com/v1/payment-experience/web-profiles/ 可以解决问题。但是为此我们需要在payment.create之前发出一个curl请求,这样我们就可以在函数中传递它返回的id。

这在 JS 中可行吗?

或者有没有更好更简单的方法来使用下面的 JS 来移除它?

<script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script>
<script>

    paypal.Button.render({
        env: 'sandbox', // Optional: specify 'sandbox' or 'production'
        client: {
            sandbox:    '{{$data['SandboxId']}}',
            production: '{{$data['ProductionId']}}'
        },

        payment: function() {
            var amount = document.getElementById("amount").value;
            var env    = this.props.env;
            var client = this.props.client;

            return paypal.rest.payment.create(env, client, {
                transactions: [
                    {
                        amount: {
                            total: amount,
                            currency: "USD",
                            details: {
                                subtotal: amount,
                                tax: "0.00",
                                shipping: "0.00"
                            }
                        },
                        description: "This is payment description.",
                        item_list: { 
                            items:[
                                {
                                    quantity:"1", 
                                    name:"Orders", 
                                    price:amount,  
                                    sku:"product12345", 
                                    currency:"USD"
                                }
                            ],
                        },

                    }],

            });
        },

        commit: false, // Optional: show a 'Pay Now' button in the checkout flow

        onAuthorize: function(data, actions) {
                console.log(data);
                 alert('confirmation here');
                // Optional: display a confirmation page here

            return actions.payment.execute().then(function() {
                alert('Success here');
                // Show a success page to the buyer
            });
        },
    }, '#paypal-button');
</script><div id="paypal-button" ></div>

【问题讨论】:

    标签: paypal express-checkout


    【解决方案1】:

    为了扩展 Bluepnume 的答案,这里有一个完整的例子:

      payment: function(data, actions) {
            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: { total: '1.00', currency: 'USD' }
                        }
                    ]
                },
    
                experience: {
                    input_fields: {
                        no_shipping: 1
                    }
                }
            });
        },
    

    【讨论】:

    • 注:好像只有贝宝主沙盒账户被授权指定“经验”,附属沙盒账户没有。 (PayPal 帐户在 paypal.Button.render 的客户端字段中指定)我提到这一点是因为当我尝试使用非主沙箱客户端 ID 时传入体验参数的上述代码时,我在 javascript 控制台中收到 401 未经授权的错误.
    【解决方案2】:

    你可以像这样传递一个体验选项:

    paypal.rest.payment.create({
        // payment options here
    }, {
        // experience options here
    });
    

    【讨论】:

    • 嗨,Blueprnum!有这方面的文件吗?我尝试将 NOSHIPPING 添加为体验选项,但没有成功。
    猜你喜欢
    • 2011-05-16
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2015-10-05
    • 2017-09-06
    • 2014-04-16
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多