Paypal Smart Buttons 按州销售税

问题描述 投票:0回答:3

如果订单位于德克萨斯州,但在客户输入后才知道地址,则必须收取销售税。唯一看似合理的事件是 onShippingChange,但在客户单击“继续”后,PayPal 发回一个错误页面,称该事件未按预期工作。我不可能是唯一需要使用这些新的“智能”按钮收取销售税的人。

<script>
    const baseOrderAmount = 20.00;
    function initPayPalButton() {
        paypal.Buttons({
            style: {
                shape: 'pill',
                color: 'blue',
                layout: 'vertical',
                label: 'paypal',
            },
            createOrder: function(data, actions) {
                return actions.order.create({
                    purchase_units: [
                        {
                            "description": "Add product to buy",
                            "custom_id": "xxx-yyy-zzz",
                            "amount": {
                                "currency_code": "USD",
                                "value": baseOrderAmount,
                                "breakdown": {
                                    "item_total": {
                                        "currency_code": "USD",
                                        "value": baseOrderAmount
                                    },
                                    "tax_total": {
                                        "currency_code": "USD",
                                        "value": 0
                                    }
                                }
                            }
                        }]
                });
            },
            onShippingChange: function (data, actions) {
                const taxAmount = (data.shipping_address.state === 'TX' || data.shipping_address.state === 'Texas') ? baseOrderAmount * 0.0825 : '0.00';
                return actions.order.patch([
                    {
                        op: 'replace',
                        path: "/purchase_units/@@referenceId='default'/amount",
                        value: {
                            currency_code: 'USD',
                            value: (parseFloat(baseOrderAmount) + parseFloat(taxAmount)).toFixed(2),
                            breakdown: {
                                item_total: {
                                    currency_code: 'USD',
                                    value: baseOrderAmount
                                },
                                tax_total: {
                                    currency_code: 'USD',
                                    value: taxAmount
                                }
                            }
                        }
                    }
                ]);
            },
            onApprove: function(data, actions) {
                return actions.order.capture().then(function(orderData) {
                    const element = document.getElementById('paypal-button-container');
                    element.innerHTML = '';
                    element.innerHTML = '<h3>Thank you for your payment!</h3>';
                });
            },
            onError: function(err) {
                console.log(err);
            }
        }).render('#paypal-button-container');
    }

    initPayPalButton();
</script>
javascript paypal
3个回答
0
投票

在浏览器开发者工具的“网络”选项卡中,您可以看到补丁操作的 422 或 400 响应。

{
    "debug_id": "8ff787b4dd2c7",
    "details": [
        {
            "description": "Path should be a valid JSON Pointer https://tools.ietf.org/html/rfc6901 that references a location within the request where the operation is performed.",
            "field": "path",
            "issue": "INVALID_JSON_POINTER_FORMAT",
            "location": "body",
            "value": "/purchase_units/@@referenceId=default/amount"
        }
    ],
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_JSON_POINTER_FORMAT",
            "method": "GET",
            "rel": "information_link"
        }
    ],
    "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
    "name": "UNPROCESSABLE_ENTITY"
}

显然您的路径中有一个额外的@符号,并且格式错误...请参阅SDK参考:https://developer.paypal.com/sdk/js/reference/#onshippingchange

那里提供的内容有效:

path: "/purchase_units/@reference_id==\'default\'/amount",

0
投票

对于尝试实现的其他人,您必须修改脚本 url 以添加 commit=false,如下所示:

<script src="https://www.paypal.com/sdk/js?client-id=<Insert your client Id>&enable-funding=venmo&currency=USD&commit=false" data-sdk-integration-source="button-factory"></script>

在 paypal 脚本块上方放置一个代码块。

@{
    var url = @"/purchase_units/@reference_id==\'default\'/amount";
}

然后更改补丁中的路径

path: "@Html.Raw(url)",

0
投票

有关 PayPal 智能按钮和动态税务计算的宝贵见解。如需简化 IRS 申报,请探索 TaxZerone,这是一家 IRS 授权的电子报税服务提供商。在 www.taxzerone.com.

安全地简化消费税、就业税、延期税、信息申报表和免税表格
© www.soinside.com 2019 - 2024. All rights reserved.