简体   繁体   English

Javascript PayPal 按钮 SDK:如何获得负面测试场景?

[英]Javascript PayPal button SDK : How to get the negative test scenarios?

Not able to get the paypal negative test scenarios.无法获得 paypal 负测试场景。 Tried adding the mock headers to the onApprove callback.尝试将模拟标头添加到 onApprove 回调。

I want to test funding failures,the last part https://developer.paypal.com/docs/business/checkout/server-side-api-calls/handle-funding-failures/我想测试资金失败,最后一部分https://developer.paypal.com/docs/business/checkout/server-side-api-calls/handle-funding-failures/

I think I add the mock header in the right place but is doing nothing it keeps saying Transaction completed.我想我在正确的位置添加了模拟 header 但什么也没做,它一直说交易已完成。 Whats the proper way to put it?正确的表达方式是什么? Paypal says: Paypal 说:

paypal.Buttons({
        createOrder: function(data, actions) {
            return fetch('/demo/checkout/api/paypal/order/create/', {
                method: 'post'
            }).then(function(res) {
                return res.json();
            }).then(function(orderData) {
                return orderData.id;
            });
        },

        onApprove: function(data, actions) {
            return fetch('/demo/checkout/api/paypal/order/' + data.orderID + '/capture/', {
                method: 'post',
                headers: {
                    'content-type': 'application/json',
                    'PayPal-Mock-Response': '{"mock_application_codes" : "INSTRUMENT_DECLINED" }'
                },
            }).then(function(res) {
                return res.json();
            }).then(function(orderData) {
                var errorDetail = Array.isArray(orderData.details) && orderData.details[0];
                console.log('paypal error errorDetail', orderData)

                if (errorDetail && errorDetail.issue === 'INSTRUMENT_DECLINED') {
                    return actions.restart();
                }

                if (errorDetail) {
                    var msg = 'Sorry, your transaction could not be processed.';
                    if (errorDetail.description) msg += '\n\n' + errorDetail.description;
                    if (orderData.debug_id) msg += ' (' + orderData.debug_id + ')';
                    return alert(msg); 
                }

                console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
                var transaction = orderData.purchase_units[0].payments.captures[0];
                alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
            });
        }

    }).render('#paypal-button-container');

the above is my code.以上是我的代码。 Please help.请帮忙。 Thanks in advance提前致谢

The headers are not to be added when the JS code fetches from routes on your server ( '/demo/checkout/api/paypal/order/ in your example).当 JS 代码从您服务器上的路由获取时,不会添加标头(在您的示例中'/demo/checkout/api/paypal/order/ )。

The headers are to be added inside those routes, in the code on your server, when it calls the v2/checkout/orders API to capture the order.当它调用 v2/checkout/orders API 来捕获订单时,将这些路由中添加标头,在您服务器上的代码中。

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

相关问题 PayPal JavaScript SDK:如何将“立即购买”按钮更改为“立即付款”? - PayPal JavaScript SDK: How to change the 'Buy Now' button to 'Pay Now'? 从JavaScript测试自动化项目中获取功能和场景的总数 - To get total number of features and scenarios from JavaScript test automation project 在 Braintree 上隐藏 PayPal Credit 按钮 JavaScript v4 SDK - Hiding the PayPal Credit button on Braintree JavaScript v4 SDK 贝宝结帐按钮获取javascript中的json响应 - paypal checkout button get json response in javascript 如何在玩笑中检查消极和积极的场景? - how to check negative and positive scenarios in jest? 在JavaScript中负零有很大不同的任何示例/方案中? - Any examples / scenarios where negative zero in JavaScript make a big difference? Paypal javascript sdk - 送货地址 - Paypal javascript sdk - shipping address Paypal Javascript SDK 及计费协议 - Paypal Javascript SDK and billing agreement 如何使用新的PayPal JavaScript SDK关闭送货 - How to Turn off shipping with new PayPal JavaScript SDK 如何将用于 React SPA 的 Paypal Javascript SDK 与后端服务器验证集成? - How to integrate Paypal Javascript SDK for React SPA with backend server validation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM