HAQM Sign-in
Implement HAQM Sign-in if you need buyer details before the buyer starts HAQM Pay checkout. Once checkout has started, you can use Get Checkout Session and Get Charge Permission to retrieve buyer information.
The steps for implementing HAQM Sign-in are very similar to the steps for rendering the HAQM Pay Checkout button. You will need to add the HAQM Pay script, configure sign-in settings, render the sign-in button, and then retrieve buyer details using the Get Buyer API. At the end of this page, you will be able to render an HAQM Sign-in button and retrieve buyer details after the buyer signs in.
You must add the domains where the HAQM Pay button will be rendered to Seller Central. See Add domains to Seller Central for more information.
- 1. Add the HAQM Pay script
- 2. Generate the Sign-in payload
- 3. Sign the payload
- 4. Render the button
- 5. Retrieve Buyer details
1. Add the HAQM Pay script
Add the HAQM Pay script to your HTML file. Be sure you select the correct region.
<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>
2. Generate the Sign-in payload
To render the HAQM Sign-in button, you will need to provide a payload that HAQM Pay can use to determine which buyer details to share and where to redirect the buyer after they sign in.
Set the signInReturnUrl
parameter to the URL that the buyer should be redirected to after they sign in. The URL will have a token that you can use to retrieve buyer details appended as a query parameter.
Payload example
{
"signInReturnUrl":"http://a.com/merchant-page",
"storeId":"amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
"signInScopes":["name", "email", "postalCode", "shippingAddress", "phoneNumber"]
}
Parameter
|
Description
|
signInReturnUrl (required) Type: string |
HAQM Pay will redirect to this URL after the buyer signs in Note: In the Live environment, URLs must use HTTPS protocol. The URL domain must be added to Seller Central. See Add domains to Seller Central for more information. In Sandbox environment, you don't need a SSL certificate and can use the HTTP protocol if you're testing on localhost (http://localhost). You don't need to add URLs to the JavaScript Origins in SellerCentral |
storeId (required) Type: string |
HAQM Pay store ID. Retrieve this value from HAQM Pay Integration Central: US, EU, JP
|
signInScopes Type: list<signInScope> |
The buyer details that you're requesting access for. Note that HAQM Pay will always return buyerId even if no values are set for this parameter
|
signInCancelUrl Type: string |
Sign-in cancellation URL provided by the merchant. HAQM Pay will redirect to this URL if the buyer cancels sign-in on the HAQM Pay hosted page
|
Type: signInScope
Parameter
|
Description
|
name
|
Request access to buyer name
|
email
|
Request access to buyer email address
|
postalCode
|
Request access to buyer default shipping address postal code and country code
|
shippingAddress
|
Request access to buyer default shipping address
|
billingAddress
|
Request access to buyer default billing address
|
phoneNumber
|
Request access to buyer default billing address phone number
|
3. Sign the payload
You must secure the payload using a signature. The payload does not include a timestamp so you can re-use the signature as long as the payload does not change.
Option 1 (recommended): Generate a signature using the helper function provided in the HAQM Pay SDKs. The signature generated by the helper function is only valid for the button and not for API requests.
<?php
include 'vendor/autoload.php';
$amazonpay_config = array(
'public_key_id' => 'MY_PUBLIC_KEY_ID',
'private_key' => 'keys/private.pem',
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2'
);
$client = new HAQM\Pay\API\Client($amazonpay_config);
$payload = '{"signInReturnUrl":"http://a.com/merchant-page","storeId":"amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId","signInScopes":["name", "email", "postalCode", "shippingAddress", "phoneNumber"]}';
$signature = $client->generateButtonSignature($payload);
echo $signature . "\n";
?>
SignInScope[] scopes = {
SignInScope.Name,
SignInScope.Email,
SignInScope.PostalCode,
SignInScope.ShippingAddress,
SignInScope.PhoneNumber
};
var request = new SignInRequest
(
signInReturnUrl: "http://example.com/account.html",
storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
signInScopes: scopes
);
string signature = client.GenerateButtonSignature(request);
PayConfiguration payConfiguration = null;
try {
payConfiguration = new PayConfiguration()
.setPublicKeyId("YOUR_PUBLIC_KEY_ID")
.setRegion(Region.YOUR_REGION_CODE)
.setPrivateKey("YOUR_PRIVATE_KEY_STRING")
.setEnvironment(Environment.SANDBOX)
.setAlgorithm("AMZN-PAY-RSASSA-PSS-V2");
}catch (HAQMPayClientException e) {
e.printStackTrace();
}
HAQMPayClient client = new HAQMPayClient(payConfiguration);
String payload = "{\"signInReturnUrl\":\"http://a.com/merchant-page\",\"storeId\":\"amzn1.application-oa2-client.xxxxx\",\"signInScopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\"]}";
String signature = client.generateButtonSignature(payload);
const fs = require('fs');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');
const config = {
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2'
};
const testPayClient = new Client.HAQMPayClient(config);
const payload = {
"signInReturlUrl": "http://a.com/merchant-page",
"storeId": "amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
"signInScopes": ["name", "email", "postalCode", "shippingAddress", "phoneNumber"]
};
const signature = testPayClient.generateButtonSignature(payload);
Option 2: Build the signature manually by following steps 2 and 3 of the signing requests guide.
4. Render the button
Use the values from the previous two steps to render the HAQM Pay button to a HTML container element. The button will be responsive and it will inherit the size of the container element, see responsive button logic for details.
Code sample
Function parameters
Parameter
|
Description
|
merchantId (required) Type: string |
HAQM Pay merchant account identifier
|
signInConfig (required) Type: signInConfig |
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:
|
ledgerCurrency (required) Type: string |
Ledger currency provided during registration for the given merchant identifier Supported values:
|
productType Type: string |
Product type selected for checkout Supported values:
|
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:
|
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 |
5. Retrieve Buyer details
Get Buyer to retrieve buyer details. Get Buyer will only return buyerId
by default. You must explicitly request access to additional buyer details using the button signInScopes
parameter.
HAQM Pay will only provide the token required to retrieve buyer details after the buyer signs in. It will be appended to the signInReturnUrl
as a query parameter and expires after 24 hours.
Request
Request parameters
Name
|
Location
|
Description
|
buyerToken (required) Type: string |
Path Parameter
|
Token used to retrieve buyer details. This value is appended as a query parameter to signInReturnUrl Max length: 1000 characters/bytes |
Sample Code
Response
{
"name": "John Example",
"email": "johnexample@haqm.com",
"postalCode": "12345",
"countryCode": "US",
"buyerId": "DIRECTEDBUYERID",
"phoneNumber": "1234567811" // default billing address phone number
"shippingAddress": {
"name": "John",
"addressLine1": "15th Street",
"addressLine2": "",
"addressLine3": "",
"city": "Seattle",
"county": "",
"district": "",
"stateOrRegion": "WA",
"country": "USA",
"postalCode": "98121",
"phoneNumber": "1234567899"
},
"billingAddress": null,
"primeMembershipTypes": null
}