1

我正在尝试运行https://www.youtube.com/watch?v=yelPlCVZLEE上所示的付款请求 API 示例。我已经按照他们描述的过程进行了操作,并且我还运行了以下代码:

function go() {
   console.log('Pay');
   var request = new PaymentRequest([{
            supportedMethods:['urn:payment:visa','urn:payment:mc','urn:payment:amex']
         }],
         {
            total: {
            label: "Total due",
            amount: { currencyCode: "USD", value: "60.00" }, // US$60.00
         }
     }
   );

request.show()
  .then(function(response) {
    // process transaction response here
    return response.complete(true);
  })
  .then(function() {
    alert("Buy!");
  })
  .catch(function(e) {
    alert(e.name);
  });
 }

我收到以下错误:未捕获的 ReferenceError:PaymentRequest 未定义。

如果我从以下位置运行测试:http: //github.adrianba.net/paymentrequest-demo/tests/payment-tests.html 它说它已定义。我做错了什么?

4

1 回答 1

3

您链接的站点http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html拉入一个文件:

<script src="../lib/paymentrequest.js"></script>

它定义了自己的实现PaymentRequest

function PaymentRequest(methodData,details,options) {
  // Constructor code
  if(!Array.isArray(methodData) || methodData.length===0) throw new TypeError("methodData must be a non-empty sequence of PaymentMethodData");
  methodData.forEach(d => {
  ...

http://github.adrianba.net/paymentrequest-demo/lib/paymentrequest.js

要进入PaymentRequestChrome,您必须在 chrome://flags/#enable-experimental-web-platform-features 中启用它

于 2016-06-24T22:23:23.020 回答