簡體   English   中英

Paypal 智能按鈕銷售稅 state

[英]Paypal Smart Buttons sales tax by state

如果訂單在德克薩斯州,則必須收取銷售稅,但在客戶輸入地址之前不知道地址。 唯一看起來合理的事件是 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>

在瀏覽器開發人員工具的網絡選項卡中,您可以看到補丁操作的 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",

對於任何其他嘗試實施的人,您必須修改腳本 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)",

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM