Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active August 29, 2015 14:27
Show Gist options
  • Save domenic/1392875f2df87f758ba0 to your computer and use it in GitHub Desktop.
Save domenic/1392875f2df87f758ba0 to your computer and use it in GitHub Desktop.
var promise = paymentRequest(supportedInstruments, details, schemeData);
promise.then(function (paymentConfigurator) { // needs a slightly better name
paymentConfigurator.addEventListener("shippingAddressChange", function () { // no need for event
var newAddress = paymentConfigurator.address;
console.log(newAddress.street, newAddress.city, newAddress.state, newAddress.zip, newAddress.country);
// Return back new shipping options
paymentConfigurator.updateShippingOptions(newShippingOpions);
});
return paymentConfigurator.instrumentResponse;
})
.then(function (response) {
console.log("hurray, valid response from ", response.instrumentName, response.details);
})
.catch(function (err) {
console.error("oh no, either popping up the configurator dialog or " +
"performing the transaction failed", err);
});
// Simpler:
promise.then(function (paymentConfigurator) { // needs a slightly better name
return paymentConfigurator.instrumentResponse;
})
.then(function (response) {
console.log("hurray, valid response from ", response.instrumentName, response.details);
})
.catch(function (err) {
console.error("oh no, either popping up the configurator dialog or " +
"performing the transaction failed", err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment