Amazon Pay and Login with Amazon integration guide

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 addressConsentToken;
  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) {
          addressConsentToken = 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=" + addressConsentToken;
      }
    },
    onError:errorHandler || function(error) {
      // your error handling code
    }
  });
</script>  

Tip  Get the address consent 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) {
          addressConsentToken = response.access_token;
        });

See also


Copyright © 2009-2017 Amazon.com, Inc. or its affiliates. Amazon and Amazon.com are registered trademarks of Amazon.com, Inc. or its affiliates. All other trademarks are the property of their respective owners.