【问题标题】:How can we add tax and shipping charge in braintree paypal checkout我们如何在 Braintree paypal 结帐中添加税费和运费
【发布时间】:2018-03-11 09:48:55
【问题描述】:

我正在使用braintree paypal checkout,它对我来说工作正常,但我无法添加税费和运费,我试图获取一些信息,但这对我也不起作用,这是我目前的Braintree结帐代码

var form = document.querySelector('#payment-form');
var client_token = "<?php echo \Braintree\ClientToken::generate(); ?>";
 // Render the PayPal button

    paypal.Button.render({

        // Pass in the Braintree SDK

        braintree: braintree,

        // Pass in your Braintree authorization key

        client: {
            sandbox: client_token,
            production: '<insert production auth key>'
        },

        // Set your environment

        env: 'sandbox', // sandbox | production

        // Wait for the PayPal button to be clicked

        payment: function(data, actions) {

            // Make a call to create the payment

            return actions.payment.create({
                payment: {
                    transactions: [
                        {
                            amount: { 
                                total: <?php echo $cart_total_amount; ?>, 
                                currency: 'USD'
                            }
                        }
                    ]
                }
            });
        },

        // Wait for the payment to be authorized by the customer

        onAuthorize: function(data, actions) {

            // Call your server with data.nonce to finalize the payment

            console.log('Braintree nonce:', data.nonce);

            // Get the payment and buyer details

            return actions.payment.get().then(function(payment) {
                $("div#divLoading").addClass('show');
                console.log('Payment details:', payment);
                var payment_id = payment.id;
                var total_amount = '<?php echo $cart_total_amount; ?>';
                $.ajax({
                            type: 'POST',
                            url : '<?php $_SERVER["DOCUMET_ROOT"] ?>/media/secure_checkout/create_order_braintree.php',
                            data : 'payment_id='+payment_id+'&total_amount='+total_amount,
                            dataType : 'json',
                            success: function(msg) {
                                $("div#divLoading").removeClass('show');
                                if(msg.status == '1') {
                                    //$("#myModal").modal('show');
                                    document.location.href= 'http://<?php  echo $_SERVER['HTTP_HOST']; ?>/media/secure_checkout/checkout.php?payment=confirm';
                                }
                            },
                            error: function(msg) {
                                $("div#divLoading").removeClass('show');
                            }
                });
            });
        }

    }, '#paypal-button-container');

谁能告诉我我需要做什么才能在其中添加税金和运费?

【问题讨论】:

    标签: paypal paypal-sandbox braintree braintree-sandbox


    【解决方案1】:

    全面披露:我在 Braintree 工作。如果您还有任何问题,请随时联系 support@braintreepayments.com。

    Braintree 没有 taxshipping 的参数。您需要自己创建此逻辑并将总数传递给amount 参数。

    【讨论】:

    • 但如果是定期/订阅,我该如何管理税收?不同省或国家的税率不同。那么根据买家的位置创建不同的计划并不是一个好习惯。
    • Erica,你能确认或更正my answer中的信息吗?谢谢!
    • @harishsharma 这个问题与定期/订阅无关,但my answer 可能会为您提供一些有用的信息。您可以覆盖计划金额(或者创建一个“税”插件,并覆盖该金额)。
    【解决方案2】:

    您似乎正在关注Integrate PayPal Checkout Using the Braintree SDK 的代码。查看actions.payment.create() 呼叫here 的可用选项。请注意,taxshipping 在那里。有关Payments API page 的更多详细信息。注意:你仍然需要计算总数,所以它包括税费和运费,就像 Erica 说的那样。

    如果您想创建支付服务器端,您似乎可以将 taxAmountshippingAmount 传递给 Braintree 的 transaction::sale() 方法。也可以在订单项级别传递这些。同样,您需要计算总数,使其包括税费和运费。看来您还必须包含其他一些字段,因为 taxAmountLevel 2 字段,而 shippingAmountLevel 3 字段。我没有使用它,所以我不能说它是如何工作的,或者它的工作情况如何。如果 PayPal 用作付款方式,我想(希望)这些字段会传递到 PayPal。

    对于经常性交易:我看不到任何特定于税收/运费的字段,但您可以在创建订阅时覆盖 price 以包含税金(至少使用服务器端 Braintree API)。或者,我认为如果您创建一个税收附加组件,您可以在订阅创建时覆盖它而不知道订阅价格。无论哪种方式,我不确定您是否可以随着税率的变化(随着法律的变化)轻松更新订阅。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2012-08-06
      • 2011-07-15
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多