Accessing order information at the time of buyer login
If you create an order at the time of buyer login, you can access order details by adding the onSignIn function to the Amazon Pay button that creates the order reference object.
When the order reference object has been created, you can make a call to the GetOrderReferenceDetails API to obtain the OrderReferenceDetails.
The following code sample shows the onSignIn function that creates an order reference object when the buyer signs in.
<div id="AmazonPayButton"/>
<script type="text/javascript">
var authRequest;
var accessToken;
OffAmazonPayments.Button("AmazonPayButton", "YOUR_SELLER_ID", {
type: "ENTER_TYPE_PARAMETER",
color: "ENTER_COLOR_PARAMETER",
size: "ENTER_SIZE_PARAMETER",
language: "ENTER_LANGUAGE_PARAMETER",
authorization: function() {
loginOptions = {scope: "ENTER_SCOPES",
popup: "ENTER_POPUP_PARAMETER"};
authRequest = amazon.Login.authorize (loginOptions,
function(response) {
accessToken = response.access_token;
});
},
onSignIn: function (orderReference) {
var referenceId = orderReference.getAmazonOrderReferenceId();
if (!referenceId) {
errorHandler(new Error('referenceId missing'));
} else {
window.location = "YOUR_REDIRECT_URL" + '?referenceId=' +
orderReference.getAmazonOrderReferenceId() +
"&access_token=" + accessToken;
}
},
onError:errorHandler || function(error) {
// your error handling code
}
});
</script>
Tip Get the access token by using this section of the code sample above:
authorization: function() {
loginOptions = {scope: "ENTER_SCOPES",
popup: "ENTER_POPUP_PARAMETER"};
authRequest = amazon.Login.authorize (loginOptions,
function(response) {
accessToken = response.access_token;
});