0

我正在关注有关新 PaymentRequest API的教程,但出现错误:

未捕获的 TypeError:无法构造“PaymentRequest”:迭代器 getter 不可调用。在 startPayment ((index):45)

function startPayment(){
  if (!window.PaymentRequest) {
    // PaymentRequest API is not available. Forwarding to
    // legacy form based experience.
    location.href = '/checkout';
    return;
  }

  const methods = {
    supportedMethods: "basic-card",
    data: {
      supportedNetworks: [
        'visa', 'mastercard', 'amex', 'discover',
        'diners', 'jcb', 'unionpay'
      ]
    },
  }
  const details = {
    total: {
      label: 'Tyle musisz zabulić',
      amount: { currency: 'PLN', value : '22.15' }
    },
    displayItems: [{
      label: 'Narkotyki',
      amount: { currency: 'PLN', value: '22.15' }
    }],
  }
  const options = {
    requestShipping: true,
    requestPayerEmail: true,
    requestPayerPhone: true,
    requestPayerName: true,
    shippingType: 'delivery'
  };
  const request = new PaymentRequest(methods, details, options) // this line fails
  request.show().then(response => {
    // [process payment]
    // send to a PSP etc.
    response.complete('success');
  });
}

这是什么意思,我该如何解决?MacOS Chrome 版本:72.0.3626.121 64bit

4

1 回答 1

0

付款方式应该是一个数组:

  const methods = [
     {
      supportedMethods: "basic-card",
      data: {
        supportedNetworks: [
          'visa', 'mastercard', 'amex', 'discover',
          'diners', 'jcb', 'unionpay'
        ]
      },
    }
  ]
于 2019-03-10T15:43:44.493 回答