Skip to content

Instantly share code, notes, and snippets.

@danielneu
Created October 4, 2019 14:56
Show Gist options
  • Save danielneu/fd526c4f546b26399d7c7d2e18c46020 to your computer and use it in GitHub Desktop.
Save danielneu/fd526c4f546b26399d7c7d2e18c46020 to your computer and use it in GitHub Desktop.
Order Independent callback logic
// add Login and Pay callbacks
window.onAmazonPaymentsReady = () => {
this.createButton(sellerId, scope, type, color, size, mountLocation);
}
// if the OffAmazonPayments namespace is already available, call the callback manually - otherwise wait for Amazon to call it
if (typeof window.OffAmazonPayments !== 'undefined') {
window.onAmazonPaymentsReady();
}
createButton(sellerId, scope, type, color, size, mountLocation) {
window.OffAmazonPayments.Button(mountLocation, sellerId, {
type,
color,
size,
authorization: () => {
const loginOptions = { scope };
window.amazon.Login.authorize(loginOptions, this.onAuthorize);
},
onError: this.onError,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment