简体   繁体   English

删除 PayPal Express Checkout 中的送货地址选项

[英]Remove shipping address option in PayPal Express Checkout

I am using the JS script recommended by PayPal. It's working well, however it is showing a "Ship to" address of the buyers.我正在使用 PayPal 推荐的 JS 脚本。它运行良好,但显示买家的收货地址”。

I am trying to search the inte.net and found that https://api.sandbox.paypal.com/v1/payment-experience/web-profiles/ requested with "no_shipping": 1, can do the trick.我正在尝试搜索 inte.net,发现https://api.sandbox.paypal.com/v1/payment-experience/web-profiles/ requested with "no_shipping": 1,可以解决问题。 But for that we need to make a curl request before the payment.create , so that we can pass it returned id in the function.但是为此我们需要在payment.create之前发出一个 curl 请求,这样我们就可以传递它在 function 中返回的 id。

Is this possible in JS?这在 JS 中可行吗?

Or is there a much better and simpler way to remove it using the following 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>

To expand on Bluepnume's answer, here is a complete example: 为了扩展Bluepnume的答案,这是一个完整的例子:

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

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

You can pass an experience options like so: 您可以通过以下体验选项:

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

This is how it needs to be done in ngx-paypal version 11这是在 ngx-paypal 版本 11 中需要完成的方式

application_context:
{
  shipping_preference: "NO_SHIPPING"
}

ngx-paypal: "^11.0.0" ngx-paypal:“^11.0.0”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM