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



无法获得paypal阴性测试场景。尝试将模拟标头添加到onApprove回调。

我想测试融资失败,最后一部分https://developer.paypal.com/docs/business/checkout/server-side-api-calls/handle-funding-failures/

我想我在正确的地方添加了模拟头,但没有做任何事情,它一直说交易完成。正确的说法是什么?贝宝说:

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 += 'nn' + 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 + 'nnSee console for all available details');
});
}
}).render('#paypal-button-container');
以上是我的代码。请帮助。提前感谢

当JS代码从你的服务器(在你的例子中是'/demo/checkout/api/paypal/order/)上获取路由时,不需要添加头信息。

当服务器调用v2/checkout/orders API来捕获订单时,标头将在这些路由中添加

最新更新