【问题标题】:Is there any method for PaymentResponse api to check response of payment?PaymentResponse api有什么方法可以检查付款响应吗?
【发布时间】:2020-06-01 01:15:18
【问题描述】:

因为我们可以检查是否支持支付 api 的状态。使用窗口对象:

window.PaymentRequest

有没有什么方法可以在付款后仅使用 window 对象检查 PaymentResponse 的状态?

我无权访问付款代码,我正在尝试仅使用窗口对象检查状态。

【问题讨论】:

    标签: javascript payment-method payment-request-api


    【解决方案1】:

    您可以得到回复。看到这个

    // global
    const { PaymentRequest } = window;
    
    // Selectors
    const buttons = document.querySelectorAll('button');
    
    // config
    const paymentMethods = [
      {
        supportedMethods: ['basic-card']
      }
    ];
    
    const paymentDetails = {
      total: {
        label: 'What you pay',
        amount: {
          currency: 'USD',
          value: 10
        }
      }
    };
    
    
    const paymentRequest = PaymentRequest && new PaymentRequest(
      paymentMethods,
      paymentDetails
    );
    
    const addItemToCart = ({target}) => {
      paymentRequest
      .show()
      .then(paymentResponse => {
        return paymentResponse.complete().then(response => {
          console.log(response)
        });
      })
      .catch(reason => console.error(`Error occurred: ${reason}`));
    };
    
    buttons.forEach(button => button.addEventListener('click', addItemToCart));
    

    这是一个codepen链接

    https://codepen.io/elmahdim/pen/yodVzw?editors=1111

    【讨论】:

    • 我已经提到我无权访问代码。我只想检查使用窗口对象
    • 如果是这样的话,那就没有办法了。那是出于安全原因。
    • 我猜是有办法的,因为他们提供了对 paymentrequest 的支持,所以可能有办法只检查付款是否完成。这可能不会导致任何安全问题
    • 但是你需要访问你的代码才能做到这一点
    猜你喜欢
    • 2017-12-23
    • 2019-09-06
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 2015-07-16
    • 2021-07-25
    • 1970-01-01
    • 2015-09-17
    相关资源
    最近更新 更多