簡體   English   中英

通過 Paypal Express Checkout 客戶端 JS 按鈕實現使用否定測試

[英]Using Negative Testing via Paypal Express Checkout client-side JS button implementation

我目前正在使用客戶端 JS 方法進行 PayPal Express 結賬集成以進行付款。 我希望利用他們的“負面測試”功能來嘗試模擬潛在的錯誤並向客戶提供適當的響應。

只是參考相關文檔頁面here以供參考

它似乎啟用了負面測試,您需要傳遞額外的標頭以及指定要為該付款觸發的特定錯誤的付款請求。

這是我當前用於設置事務的 JS:

<script>

//We need to convert our generated json string into a bonified javascript object
var paypal_transaction = JSON.parse(JSON.stringify(<?php echo $paypal_json; ?>));

paypal.Button.render({

    env: 'sandbox', // 'production'/'sandbox',

    commit: true, // Show a 'Pay Now' button - Allows us to capture the payment right away

    client: {
        sandbox:   'Ab_hPp7h70DoFKChLMSynNxacQQbGcb_tP1cDbzW9jC6a0rYIZH0CkEYYfkw6csvmlyTmfLnagelqB85',
        production:''
    },

    //How we want the button to look
    style: {
        size: 'responsive',
        color: 'gold',
        shape: 'rect',
        label: 'pay'
    },

    headers: {
                '{"mock_application_codes":"INSTRUMENT_DECLINED"}'


    }



    payment: function(data,actions) {


        return actions.payment.create({

            //Pass our created transaction to paypal.
            payment:paypal_transaction,

            /**
             * We have to set the following fields to prevent the client from
             * changing their delivery address when they're at PayPal
             */
            experience: {
                input_fields: {
                    no_shipping: 0,
                    address_override:1
                },
            }


        });

    },

    onAuthorize: function(data, actions) {
        /**
         * [description]
         * @param payment   - The authorised transaction returned from paypal
         * @return redirect - We redirect the cutomer to our confirmation page as soon as we return from PayPal as we're confident we have the correct
         */
        return actions.payment.execute().then(function(payment) {

            actions.redirect();

        });



   },


    onError: function(err) {
        console.log(err);
        // Show an error page here, when an error occurs
    },


    onCancel: function(data, actions) {
        return actions.redirect();
        // Show a cancel page or return to cart
    }


}, '#paypal-button');

基本上我的問題是在上面的實現中我在哪里指定這樣的模擬應用程序代碼。

在文檔中,他們給出了一個示例 cURL 請求,下面是需要傳遞的額外標頭:

"PayPal-Mock-Response:{\\"mock_application_codes\\":\\"INSTRUMENT_DECLINED\\"}"

我只是不知道如何通過 JS 方法來做到這一點。 負面測試只能與服務器端實現一起使用嗎?

希望這一切都足夠清楚了!

我自己也有類似的問題,我得到的官方回答是它不可用:

“我知道這是一個令人沮喪的情況。不幸的是,我們沒有任何辦法為客戶端集成提供負面測試。您可能可以使用 Postman 這樣做,但是,我們沒有提供文檔。”

但這真的很可悲,例如,其他支付提供商針對某些錯誤情況具有固定的卡號,或者具有基於特殊支付價值的代碼。 PayPal 僅具有 Payflow 集成的功能,並且僅當您直接調用他們的 REST API 時,基於請求標頭的模擬內容也是可能的。

貝寶在這些方面真的很蹩腳,因為即使你在模擬服務器集成的行為(不是那么難,至少他們有適當的代碼示例),這種模擬是明確的,你可以控制錯誤。 如果它是隱式的,並且例如源自實際有效但無效的卡,則它會更現實。

暫無
暫無

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

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