在PayPal快速结账中删除运送地址选项

4
我正在使用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>
3个回答

5
为了补充Bluepnume的回答,这里提供一个完整的例子:

在此提供一个完整的示例:

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

            experience: {
                input_fields: {
                    no_shipping: 1
                }
            }
        });
    },

1
请注意:似乎只有主要的PayPal沙盒账户被授权指定“体验”,而子沙盒账户则没有。 (PayPal账户在paypal.Button.render的客户端字段中指定)我提到这一点是因为当我尝试使用非主要沙盒客户端ID并传递体验参数时,JavaScript控制台会显示401未经授权的错误。 - Michael Stalcup

1
您可以像这样传递体验选项:
paypal.rest.payment.create({
    // payment options here
}, {
    // experience options here
});

1
你好,Blueprnum!这个有文档吗?我尝试将NOSHIPPING添加为体验选项,但没有成功。 - jhk

0

这就是在 ngx-paypal 版本 11 中需要完成的方式。

application_context:
{
  shipping_preference: "NO_SHIPPING"
}

ngx-paypal: "^11.0.0"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接