Amazon Sign-in
Implement Amazon Pay Sign-in if you need buyer details before the buyers starts Amazon Pay checkout. Once checkout has started, you can use Get Checkout Session and Get Charge Permission to retrieve buyer information.
The steps for implementing Amazon Pay Sign-in are very similar to the steps for rendering the Amazon Pay Checkout button. You will need to add the Amazon Pay script, configure sign-in settings, render the sign-in button, and then retrieve buyer details using the Get Buyer (http://pay.amazon.com/) API. At the end of this page, you will be able to render an Amazon Pay Sign-in button and retrieve buyer details after the buyer signs in.
- 1. Add the Amazon Pay script
- 2. Generate the Sign-in payload
- 3 Sign the payload
- 4. Render the Amazon Pay Sign-in button
- 5. Retrieve Buyer Details
1. Add the Amazon Pay script
Add the Amazon Pay script to your HTML file. Be sure you select the correct region.
<script src="https://static-na.payments-amazon.com/checkout.js"></script>
<script src="https://static-eu.payments-amazon.com/checkout.js"></script>
2. Generate the Sign-in payload
To render the Amazon Pay Sign-in button, you will need to provide a payload that Amazon 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":"https://a.com/merchant-page"
"storeId":"amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
"signInScopes":["name", "email", "postalCode", "shippingAddress", "phoneNumber"]
}
Parameter
|
Description
|
signInReturnUrl (required) |
Amazon Pay will redirect to this URL after the buyer signs in
|
storeId (required) Type: string |
Login with Amazon client ID. Do not use the application ID Retrieve this value from "Login with Amazon" in Seller Central |
signInScopes Type: list[signInScope] |
The buyer details that you're requesting access for. Note that Amazon Pay will always return buyerId even if no values are set for this parameter
|
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 Amazon 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
);
$client = new Amazon\Pay\API\Client($amazonpay_config);
$payload = '{"storeId":"amzn1.application-oa2-client.xxxxx","webCheckoutDetails":{"checkoutReviewReturnUrl":"https://localhost/test/CheckoutReview.php"}}';
$signature = $client->generateButtonSignature($payload);
echo $signature . "\n";
?>
var payConfiguration = new ApiConfiguration (
region: Region.Europe,
environment: Environment.Sandbox,
publicKeyId: "MY_PUBLIC_KEY_ID",
privateKey: "PATH_OR_CONTENT_OF_MY_PRIVATE_KEY"
);
var canonicalBuilder = new CanonicalBuilder();
var signatureHelper = new SignatureHelper(payConfiguration, canonicalBuilder);
string payload = '{"storeId":"amzn1.application-oa2-client.xxxxx","webCheckoutDetails":{"checkoutReviewReturnUrl":"https://localhost/test/CheckoutReview.php"}}';
string signature = signatureHelper.GenerateSignature(payload, payConfiguration.PrivateKey);
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);
}catch (AmazonPayClientException e) {
e.printStackTrace();
}
AmazonPayClient client = new AmazonPayClient(payConfiguration);
String payload = '{"storeId":"amzn1.application-oa2-client.xxxxx","webCheckoutDetails":{"checkoutReviewReturnUrl":"https://localhost/test/CheckoutReview.php"}}';
String signature = client.generateButtonSignature(payload);
html const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('../src/client');
const config = {
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
};
const testPayClient = new Client.AmazonPayClient(config);
const payload = {
webCheckoutDetails: {
checkoutReviewReturnUrl: 'https://localhost/test/checkoutReview.html'
},
storeId: 'amzn1.application-oa2-client.xxxxx'
};
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 Amazon Pay Sign-in button
Use the values from from the previous to steps to render the Amazon 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
<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',
publicKeyId: 'SANDBOX-xxxxxxxxxx',
// customize the buyer experience
checkoutLanguage: 'en_US',
productType: 'SignIn',
placement: 'Cart',
// configure Create Checkout Session request
signInConfig: {
payloadJSON: 'payload', // payload generated in step 2
signature: 'xxxx' // signature generatd in step 3
}
});
</script>
</body>
<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: 'EUR',
publicKeyId: 'SANDBOX-xxxxxxxxxx',
// customize the buyer experience
checkoutLanguage: 'en_GB',
productType: 'SignIn',
placement: 'Cart',
// configure Create Checkout Session request
signInConfig: {
payloadJSON: 'payload', // payload generated in step 2
signature: 'xxxx' // signature generatd in step 3
}
});
</script>
</body>
<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: 'GBP',
publicKeyId: 'SANDBOX-xxxxxxxxxx',
// customize the buyer experience
checkoutLanguage: 'en_GB',
productType: 'SignIn',
placement: 'Cart',
// configure Create Checkout Session request
signInConfig: {
payloadJSON: 'payload', // payload generated in step 2
signature: 'xxxx' // signature generatd in step 3
}
});
</script>
</body>
Function parameters
Parameter
|
Description
|
merchantId (required) Type: string |
Amazon Pay merchant account identifier
|
createCheckoutSessionConfig (required) Type: checkoutSessionConfig |
Create Checkout Session configuration. This is a required field if you use PayAndShip or PayOnly productType
|
placement (required) Type: string |
Placement of the Amazon 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:
Default value: 'PayAndShip' |
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:
|
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
Call 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.
Amazon 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
curl "https://pay-api.amazon.com/:version/buyers/:buyerToken" \
-X GET
-H "authorization:Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE"
-H "x-amz-pay-date:20201012T235046Z"
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: 500 characters/bytes |
Response
{
"name": "John Example",
"email": "johnexample@amazon.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
}