gpt4 book ai didi

javascript - 通过 Paypal Express Checkout 客户端 JS 按钮实现使用负测试

转载 作者:行者123 更新时间:2023-12-03 06:51:49 25 4
gpt4 key购买 nike

我目前正在使用客户端 JS 方法进行 PayPal Express 结帐集成以进行付款。我希望利用他们的“负面测试”功能来尝试模拟潜在错误并向客户提供适当的响应。

只需引用相关文档页面 here以供引用

似乎可以启用负面测试,您需要在付款请求中传递一个额外的 header ,指定您希望为该付款触发的特定错误。

这是我当前用于设置交易的 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 请求,下面是需要传递的额外 header :

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

我只是不知道如何通过 JS 方法做到这一点。负面测试只能与服务器端实现一起使用吗?

希望这一切都足够清楚!

最佳答案

我自己也有类似的问题,我得到的官方回答是它不可用:

"I understand this is a frustrating situation. Unfortunately we do nothave any way to offer negative testing for client side integrations.It may possible for you to do so using Postman, however, we do nothave documentation to offer."


但这真的很可悲,例如,其他支付提供商对于某些错误场景有固定的卡号,或者有特殊的基于支付值(value)的代码。 PayPal 仅具有用于 Payflow 集成的功能,并且基于请求 header 的模拟内容也只有在您直接调用他们的 REST API 时才有可能。
PayPal 在这些方面确实很蹩脚,因为即使您正在模拟服务器集成的行为(不是那么难,至少他们有适当的代码示例),这种模拟是明确的并且您可以控制错误。如果它是隐含的,例如源自一张实际验证但无效的卡片,它会更现实。

关于javascript - 通过 Paypal Express Checkout 客户端 JS 按钮实现使用负测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45866325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com