HAQM Pay script


HAQM Pay script

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

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

Render the HAQM Pay button

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

Code sample for HAQM Pay Checkout

Code sample for HAQM Sign-in

Parameters

Parameter
Description
merchantId
(required)

Type: string
HAQM 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
HAQM Sign-in configuration. This is a required field if you use SignIn productType
placement
(required)

Type: string
Placement of the HAQM 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'
estimatedOrderAmount

Type: price
This is the estimated checkout order amount, it does not have to match the final order amount if the buyer updates their order after starting checkout. HAQM Pay will use this value to assess transaction risk and prevent buyers from selecting payment methods that can't be used to process the order
productType

Type: string
Product type selected for checkout

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

Type: string
Color of the HAQM Pay button

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

Type: string
Language used to render the button and text on HAQM Pay hosted pages. Please note that supported language(s) is dependent on the region that your HAQM 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

You do not have to set this parameter if your publicKeyId has an environment prefix (for example: SANDBOX-AFVX7ULWSGBZ5535PCUQOY7B)

Default value: false

Type: buttonConfig

Parameter
Description
payloadJSON
(required)

Type: string
For createCheckoutSessionConfig, HAQM 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, HAQM 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
algorithm

Type: string
String used to identify the hashing algorithm used to sign the request. This value on the front-end should be in sync with the signing algorithm value used in the back-end code or SDK

Possible values: 'AMZN-PAY-RSASSA-PSS-V2' and 'AMZN-PAY-RSASSA-PSS'

AMZN-PAY-RSASSA-PSS-V2 is the latest and recommended signing algorithm using a salt length of 32. AMZN-PAY-RSASSA-PSS is the prior version supporting a salt length of 20, this is the default value if this field is not populated.
publicKeyId
(required)

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

You do not have to set this parameter if your publicKeyId has an environment prefix (for example: SANDBOX-AFVX7ULWSGBZ5535PCUQOY7B)

Decoupling button render and checkout or sign-in initiation

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

Code sample for HAQM Pay Checkout

Code sample for HAQM Sign-in


Render button using a Checkout Session object

Note: New integrations should not use this intergration and instead follow render the HAQM Pay button instructions above. HAQM Pay will continue to support rendering the button using a Checkout Session object you generated on your back end, but new features such as rendering additional payment button will not be available.

Instead of generating a payload that HAQM 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 HAQM Pay script will POST a request to that URL each time the button is clicked.

The response of your endpoint should be in JSON format. You can either return the entire Create Checkout Session response or return a response that includes a checkoutSessionId key. Example: {"checkoutSessionId": "116e5701-a0bf-49f2-a63d-000000000000"}.

Code sample

<body>
    <div id="HAQMPayButton"></div>
    <script src="http://static-na.payments-haqm.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        amazon.Pay.renderButton('#HAQMPayButton', {
            merchantId: 'merchant_id',
            createCheckoutSession: {
                url: 'http://mystore/amazonpay/createcheckoutsession'
            },
            sandbox: true, // dev environment
            ledgerCurrency: 'USD', // HAQM 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 HAQM 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 200px 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.

Provide a specific size for the container element or the HAQM Pay button may stretch or shrink if the buyer adjusts the zoom level on their browser.


Enable checkout info updates

Use amazon.Pay.changeShippingAddress() to enable updates in case the buyer wants to select a different shipping address and amazon.Pay.changePaymentMethod() to enable updates in case the buyer wants to select a different payment method.
This will take you straight to the change shipping address or change payment method page.

Code sample

<script type="text/javascript" charset="utf-8">
    amazon.Pay.changeShippingAddress({
      amazonCheckoutSessionId: 'xxxx'
    });

    amazon.Pay.changePaymentMethod({
      amazonCheckoutSessionId: 'xxxx'
    });
</script>

Parameters

Parameter
Description
amazonCheckoutSessionId
(required)

Type: string
HAQM Pay Checkout Session identifier

Legacy Approach

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
HAQM Pay Checkout Session identifier
changeAction
(required)

Type: string
Update requested by the buyer

Supported values: 'changeAddress', 'changePayment'

Sign out from HAQM

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

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

Code sample

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