Reputation: 11
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?
Upvotes: 1
Views: 3820
Reputation: 53
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
Upvotes: 3