1

I am trying to run an example of the Payment request API as shown on https://www.youtube.com/watch?v=yelPlCVZLEE . I have followed the process as they describe and i Have also run the following code:

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);
  });
 }

and I get the following error: Uncaught ReferenceError: PaymentRequest is not defined.

If I run the test from : http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html It's says it's defined. What I am doing wrong?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
remind_hill
  • 11
  • 1
  • 4

1 Answers1

3

The site you linked, http://github.adrianba.net/paymentrequest-demo/tests/payment-tests.html, pulls in a file:

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

which defines its own implementation of 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

To get PaymentRequest in Chrome, you have to enable it in chrome://flags/#enable-experimental-web-platform-features

jeffcarp
  • 53
  • 1
  • 5
  • Thank you very much for your reply. i Did it and it worked but now, after following the steps on https://www.w3.org/TR/payment-request/ and calling the api by doing: – remind_hill Jun 28 '16 at 09:03
  • Thanks! I thought I had to enable the `#web-payments` flag - but no! Cheers :) – Darragh Enright Jun 24 '17 at 19:55