/paymentRequestFullExample.js Secret
Last active
February 14, 2017 19:07
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function startPaymentRequestCheckout() { | |
var methodData = [ | |
{ | |
supportedMethods: ['basic-card'], | |
data: { | |
supportedNetworks: ['visa', 'mastercard', 'amex'], | |
supportedTypes: ['credit'] | |
} | |
} | |
]; | |
var details = { | |
displayItems: [ | |
{ | |
label: "Sub-total", | |
amount: { currency: "USD", value : "100.00" }, // US$100.00 | |
}, | |
{ | |
label: "Sales Tax", | |
amount: { currency: "USD", value : "9.00" }, // US$9.00 | |
} | |
], | |
total: { | |
label: "Total due", | |
amount: { currency: "USD", value : "109.00" }, // US$109.00 | |
} | |
}; | |
var options = { | |
requestShipping: true | |
}; | |
var request = new PaymentRequest(methodData, details, options); | |
//Show the Native UI | |
request.show() | |
//When the promise is fulfilled, pass the results to your server for processing | |
.then(result => { | |
return process(result).then(response => { | |
if (response.status === 200) { | |
//Show that the transaction was successful in the UI | |
return result.complete('success'); | |
} else { | |
//Show in the Native UI that the transaction failed | |
return result.complete('fail'); | |
} | |
}) | |
}); | |
request.addEventListener("shippingaddresschange", function (changeEvent) { | |
// Process shipping address change | |
}); | |
request.addEventListener("onshippingoptionchange", function (changeEvent) { | |
// Process shipping option change (e.g. "one day shipping") | |
}); | |
} | |
document.getElementById('#checkout').addEventListener('click', startPaymentRequestCheckout) |
Also, function() startPaymentRequestCheckout {
should be function startPaymentRequestCheckout() {
(the parentheses should be after the name of the function...).
Did anyone even bother to run this code (or just pass it through a JavaScript interpreter for syntax checking)? :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
document.getElementById('#checkout').addEventListener('click', startPaymentRequestCheckout)
Should be -
document.getElementById('checkout').addEventListener('click', startPaymentRequestCheckout)
(
checkout
instead of#checkout
)