Skip to content

Instantly share code, notes, and snippets.

@danielneu
Created March 15, 2016 12:06
Show Gist options
  • Save danielneu/0953e2506fee71a082d6 to your computer and use it in GitHub Desktop.
Save danielneu/0953e2506fee71a082d6 to your computer and use it in GitHub Desktop.
Order of asynchronous Widgetss.js loading
<style type="text/css">
#addressBookWidgetDiv{
width: 400px;
height: 228px;
}
</style>
<!-- first place the diff wherever the widget should appear -->
<div id="addressBookWidgetDiv"></div>
<script type='text/javascript'>
// this callback is essential and needs to be in place beofre the Widgets.js file gets loaded
// it is called as soon as the login SDK is fully loaded
window.onAmazonLoginReady = function(){
amazon.Login.setClientId('<?php echo $clientId; ?>');
};
// this callback is called once the paymeent part is completely loaded
// you can use it to e.g. create the widgets
window.onAmazonPaymentsReady = function(){
var oro = '';
new OffAmazonPayments.Widgets.AddressBook({
sellerId: '<?php echo $sellerId; ?>',
onOrderReferenceCreate: function(orderReference) {
oro = orderReference.getAmazonOrderReferenceId();
},
onAddressSelect: function(orderReference) {
console.log("onAddressSelected");
},
design: {
designMode: 'responsive'
},
onError: function(error) {
// your error handling code
}
}).bind("addressBookWidgetDiv");
}
</script>
<!--load the Widgets.js after the callbacks are defined (aasync) -->
<script async="async" src='https://static-eu.payments-amazon.com/OffAmazonPayments/uk/sandbox/lpa/js/Widgets.js'></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment