How do I get the "address consent token" after logging into Amazon?

I am using OffAmazonPayments JS library so that users can log into their Amazon account, access their address book, and eventually pay for their Amazon account. The AddressBook widget will allow me to get general address information, but without the address consent token, I cannot get the street address.

http://docs.developer.amazonservices.com/en_US/off_amazon_payments/OffAmazonPayments_GetOrderReferenceDetails.html

This link indicates that I can get the address negotiation token from the Button object after authentication, but it's not clear how this works; there is an "onSignIn" response in the login button definition that receives an orderReference object, but this object does not seem to contain such a marker.

+3


source to share


1 answer


Please see Amazon payments documentation .. especially on this page: https://payments.amazon.com/documentation/lpwa/201953150

As you can see in the following code snippet (taken from the specified page), you can extract the token from the amazon.Login.authorize (...) function.

Note. You must first include in the "scope" parameter "payments: shipping_address" as one of your scopes in order to receive the "consent token". I include other areas below so you can see how to list a few.



The CAPS words / parameters will be replaced with your desired parameters.

<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: "profile payments:widget payments:shipping_address", 
                      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> 

      

+1


source







All Articles