Amazon Pay script


Amazon Pay script

Add the Amazon Pay script to your HTML file to enable front-end functionality on your website.

<script src="https://static-na.payments-amazon.com/checkout.js"></script>
<script src="https://static-eu.payments-amazon.com/checkout.js"></script>
<script src="https://static-fe.payments-amazon.com/checkout.js"></script>

Render the Amazon Pay button

Use amazon.Pay.renderButton() to render the Amazon Pay Checkout and Sign In buttons to a HTML container element.

Code sample for Amazon Pay Checkout

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-na.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'USD',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_US',
            productType: 'PayAndShip',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure Create Checkout Session request
            createCheckoutSessionConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }   
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'EUR',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_GB',
            productType: 'PayAndShip',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure Create Checkout Session request
            createCheckoutSessionConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }   
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'GBP',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_GB',
            productType: 'PayAndShip',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure Create Checkout Session request
            createCheckoutSessionConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }   
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-fe.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'JPY',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'ja_JP',
            productType: 'PayAndShip',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure Create Checkout Session request
            createCheckoutSessionConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }   
        });
    </script>
</body>

Documentation

Code sample for Amazon Sign-in

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-na.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'USD',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_US',
            productType: 'SignIn',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure sign in
            signInConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }  
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'EUR',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_GB',
            productType: 'SignIn',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure sign in
            signInConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }   
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'GBP',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'en_GB',
            productType: 'SignIn',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure sign in
            signInConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            }  
        });
    </script>
</body>

Documentation

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-fe.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            // set checkout environment
            merchantId: 'merchant_id',
            ledgerCurrency: 'JPY',
            sandbox: true,               
            // customize the buyer experience
            checkoutLanguage: 'ja_JP',
            productType: 'SignIn',
            placement: 'Cart',
            buttonColor: 'Gold',
            // configure sign in
            signInConfig: {                     
                payloadJSON: payload, // payload generated in step 2
                signature: 'xxxx', // signature generatd in step 3
                publicKeyId: 'xxxxxxxxxx' 
            } 
        });
    </script>
</body>

Documentation

Parameters

Parameter
Description
merchantId
(required)

Type: string
Amazon Pay merchant account identifier
createCheckoutSessionConfig
(required)

Type: buttonConfig
Create Checkout Session configuration. This is a required field if you use PayAndShip or PayOnly productType
signInConfig
(required)

Type: buttonConfig
Amazon Sign-in configuration. This is a required field if you use SignIn productType
placement
(required)

Type: string
Placement of the Amazon Pay button on your website

Supported values: ‘Home’, ‘Product’, ‘Cart’, ‘Checkout’, and 'Other'
ledgerCurrency
(required)

Type: string
Ledger currency provided during registration for the given merchant identifier

Supported values:
  • US merchants - 'USD'
  • EU merchants - 'EUR'
  • UK merchants - 'GBP'
  • JP merchants - 'JPY'
productType

Type: string
Product type selected for checkout

Supported values:
  • 'PayAndShip' - Offer checkout using buyer's Amazon wallet and address book. Select this product type if you need the buyer's shipping details
  • 'PayOnly' - Offer checkout using only the buyer's Amazon wallet. Select this product type if you do not need the buyer's shipping details
  • 'SignIn' - Offer Amazon Sign-in. Select this product type if you need buyer details before the buyer starts Amazon Pay checkout. See Amazon Sign-in for more information.
Default value: 'PayAndShip'
buttonColor

Type: string
Color of the Amazon Pay button

Supported values: 'Gold', 'LightGray', 'DarkGray'
Default value: 'Gold'
checkoutLanguage

Type: string
Language used to render the button and text on Amazon Pay hosted pages. Please note that supported language(s) is dependent on the region that your Amazon Pay account was registered for

Supported values: 
  • US merchants - 'en_US'
  • EU/UK merchants - 'en_GB', de_DE', 'fr_FR', 'it_IT', 'es_ES'
  • JP merchants - 'ja_JP'
sandbox

Type: boolean
Sets button to Sandbox environment

Default value: false

Type: buttonConfig

Parameter
Description
payloadJSON
(required)

Type: string
For createCheckoutSessionConfig, Amazon Pay will use this value to create a Checkout Session object. This is the same as the request body for the Create Checkout Session API

For signInConfig, Amazon Pay will this value to determine which buyer details to share and where to redirect the buyer after they sign in
signature
(required)

Type: string
String used to verify the identity of the requestor and protect the data during transit
publicKeyId
(required)

Type: string
Credential provided by your Amazon Pay. See Get you publicKeyId for more info

Decoupling button render and checkout initiation

If you need control of the Amazon Pay button click event, you can decouple the button render action and checkout initiation. Use amazon.Pay.renderButton() to render the button and amazonPayButton.initCheckout() to initiate Amazon Pay checkout.

var amazonPayButton = amazon.Pay.renderButton('#AmazonPayButton', {
   merchantId: 'xxxxx',
   ledgerCurrency: 'USD',          
   sandbox: true, 
   checkoutLanguage: 'en_US', 
   productType: 'PayAndShip', 
   placement: 'Cart',
   buttonColor: 'Gold'
});

amazonPayButton.onClick(function(){
  // define your custom actions here
  
  amazonPayButton.initCheckout({
    createCheckoutSessionConfig: {  
      payloadJSON: payload,
      signature: 'xxxx',
      publicKeyId: 'xxxxxxxxxx'
    }
  });
});
var amazonPayButton = amazon.Pay.renderButton('#AmazonPayButton', {
   merchantId: 'xxxxx',
   ledgerCurrency: 'EUR',          
   sandbox: true, 
   checkoutLanguage: 'en_GB', 
   productType: 'PayAndShip', 
   placement: 'Cart',
   buttonColor: 'Gold'
});

amazonPayButton.onClick(function(){
  // define your custom actions here
  
  amazonPayButton.initCheckout({
    createCheckoutSessionConfig: { 
      payloadJSON: payload,
      signature: 'xxxx',
      publicKeyId: 'xxxxxxxxxx'
    }
  });
});
var amazonPayButton = amazon.Pay.renderButton('#AmazonPayButton', {
   merchantId: 'xxxxx',
   ledgerCurrency: 'GBP',          
   sandbox: true, 
   checkoutLanguage: 'en_GB', 
   productType: 'PayAndShip', 
   placement: 'Cart',
   buttonColor: 'Gold'
});

amazonPayButton.onClick(function(){
  // define your custom actions here
  
  amazonPayButton.initCheckout({
    createCheckoutSessionConfig: { 
      payloadJSON: payload,
      signature: 'xxxx',
      publicKeyId: 'xxxxxxxxxx'
    }
  });
});
var amazonPayButton = amazon.Pay.renderButton('#AmazonPayButton', {
   merchantId: 'xxxxx',
   ledgerCurrency: 'JPY',          
   sandbox: true, 
   checkoutLanguage: 'ja_JP', 
   productType: 'PayAndShip', 
   placement: 'Cart',
   buttonColor: 'Gold'
});

amazonPayButton.onClick(function(){
  // define your custom actions here
  
  amazonPayButton.initCheckout({
    createCheckoutSessionConfig: { 
      payloadJSON: payload,
      signature: 'xxxx',
      publicKeyId: 'xxxxxxxxxx'
    }
  });
});

Render button using a Checkout Session object

Instead of generating a payload that Amazon Pay will use to create a Checkout Session object, you can also set up an endpoint on your server that calls Create Checkout Session. Set that endpoint in the button render code and the Amazon Pay script will POST a request to that URL each time the button is clicked.

Code sample

<body>
    <div id="AmazonPayButton"></div>
    <script src="https://static-na.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#AmazonPayButton', {
            merchantId: 'merchant_id',
            createCheckoutSession: {
                url: 'https://mystore/amazonpay/createcheckoutsession'
            },
            sandbox: true, // dev environment
            ledgerCurrency: 'USD', // Amazon Pay account ledger currency
            checkoutLanguage: 'en_US', // render language
            productType: 'PayAndShip', // checkout type
            placement: 'Cart', // button placement
            buttonColor: 'Gold'
        });
    </script>
</body>

Responsive button logic

The Amazon Pay button is responsive and inherits the size of the container element according to the following logic:

  • If no height or width is specified, the button container defaults to 450px by 45px.
  • If only width is specified, the button container height will be set to 45px. The provided width must be between 150px and 500px or container width will be resized to the closest supported value.
  • If only height is specified, the button container width will be set to 500px. The provided height must be between 45px and 192px or container height will be resized to the closest supported value.
  • If both height and width are specified, the button container will be resized to meet these conditions:
    • The container width must be between 150px and 500px. If the provided width is outside those limits, the container width will be resized to the closest supported value.
    • The container height must be between 45px and 192px. If the provided height is outside those limits, the container height will be resized to the closest supported value.
    • The container height:width ratio must be between 1:10 and 1:2.6. If the ratio is outside those limits, the container width will be set to the provided value and the container height will be adjusted to a supported ratio value.

Enable checkout info updates

Use amazon.Pay.bindChangeAction() to enable updates in case the buyer wants to select a different shipping address or payment method.

Code sample

<script type="text/javascript" charset="utf-8">
    amazon.Pay.bindChangeAction('#changeButton1', {
      amazonCheckoutSessionId: 'xxxx',
      changeAction: 'changeAddress'
    });
</script>

Parameters

Parameter
Description
amazonCheckoutSessionId
(required)

Type: string
Amazon Pay Checkout Session identifier
changeAction
(required)

Type: string
Update requested by the buyer

Supported values: 'changeAddress', 'changePayment'

Sign out from Amazon

Use amazon.Pay.signout() to give buyers the option of signing out from their Amazon account.

Best practice: Give buyers the option of signing out after they complete checkout. Bind the function to a “Sign out from Amazon” link on your order confirmation page.

Code sample

<script type="text/javascript">
  document.getElementById('Signout').onclick = function() {
    amazon.Pay.signout();
  };
</script>