首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何关闭支付界面,如果支付失败在Stripe谷歌支付?

如何关闭支付界面,如果支付失败在Stripe谷歌支付?
EN

Stack Overflow用户
提问于 2022-02-15 08:22:53
回答 2查看 352关注 0票数 0

如果付款失败,需要关闭付款界面。现在它显示错误而不是关闭。

代码语言:javascript
复制
paymentRequest.on('paymentmethod', function(ev) {
    console.log('ev response',ev)
    
    that.accountService.makePaymentIntent(totAmt).then((data)=>{
      console.log("Promise resolved with: " + JSON.stringify(data));
      let clientSecret = data.data.client_secret;
      // Confirm the PaymentIntent without handling potential next actions (yet).
      stripe.confirmCardPayment(
        clientSecret,
        {payment_method: ev.paymentMethod.id},
        {handleActions: false}
      ).then(function(confirmResult) {
        console.log('confirmResult',confirmResult);

        if (confirmResult.error) {
          // Report to the browser that the payment failed, prompting it to
          // re-show the payment interface, or show an error message and close
          // the payment interface.
          ev.complete('fail');
        } else {
          // Report to the browser that the confirmation was successful, prompting
          // it to close the browser payment method collection interface.
          ev.complete('success');
          // Check if the PaymentIntent requires any actions and if so let Stripe.js
          // handle the flow. If using an API version older than "2019-02-11"
          // instead check for: `paymentIntent.status === "requires_source_action"`.
          if (confirmResult.paymentIntent.status === "requires_action") {
            // Let Stripe.js handle the rest of the payment flow.
            stripe.confirmCardPayment(clientSecret).then(function(result) {
              console.log('confirmCardPayment result',result);                  
              if (result.error) {
                // The payment failed -- ask your customer for a new payment method.
              } else {                    
                that.orderComplete(confirmResult, ev);
              }
            });
          } else {                                
            // The payment has succeeded.
            that.orderComplete(confirmResult, ev);                
          }
        }
      });
    }).catch((error)=>{
      ev.complete('success');
      console.log("Promise rejected with " + JSON.stringify(error));
      that.orderFailed(error);
    });
  });    
EN

回答 2

Stack Overflow用户

发布于 2022-02-15 11:31:49

这是不可能的-谷歌/苹果支付的PaymentRequest表的行为是由浏览器控制的。在Chrome上,当您让浏览器知道付款失败(通过调用ev.complete('fail'))时,它会显示一条消息并没有关闭该页。恐怕这不是你能影响的事情。

票数 0
EN

Stack Overflow用户

发布于 2022-05-17 13:23:06

您可以使用ev.complete(“成功”)代替ev.complete(“失败”)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71123131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档