[英]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.