Skip to content

Instantly share code, notes, and snippets.

@kypflug
Last active February 14, 2017 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kypflug/14dec252e272a62ef7aa0aa127a66101 to your computer and use it in GitHub Desktop.
Save kypflug/14dec252e272a62ef7aa0aa127a66101 to your computer and use it in GitHub Desktop.
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)
@phistuck
Copy link

document.getElementById('#checkout').addEventListener('click', startPaymentRequestCheckout)
Should be -
document.getElementById('checkout').addEventListener('click', startPaymentRequestCheckout)
(checkout instead of #checkout)

@phistuck
Copy link

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