感谢您的访问。此页面目前仅提供英语版本。我们正在开发中文版本。谢谢您的理解。

Amazon Sign-in

Implement Amazon Sign-in if you need buyer details before the buyer 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 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 API. At the end of this page, you will be able to render an Amazon Sign-in button and retrieve buyer details after the buyer signs in.

You must add the domains where the Amazon Pay button will be rendered to Seller Central. See Add domains to Seller Central for more information.


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>
<script src="https://static-fe.payments-amazon.com/checkout.js"></script>

2. Generate the Sign-in payload

To render the Amazon 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)

Type: string
Amazon 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
Amazon Pay store ID. Retrieve this value from Amazon Pay Integration Central: US, EU, JP
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
signInCancelUrl

Type: string
Sign-in cancellation URL provided by the merchant. Amazon Pay will redirect to this URL if the buyer cancels sign-in on the Amazon 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 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,
        'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2'
    );

    $client = new Amazon\Pay\API\Client($amazonpay_config);
    $payload = '{"signInReturnUrl":"https://a.com/merchant-page","storeId":"amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId","signInScopes":["name", "email", "postalCode", "shippingAddress", "phoneNumber"]}';
    $signature = $client->generateButtonSignature($payload);
    echo $signature . "\n";
?>

Source code

SignInScope[] scopes = { 
    SignInScope.Name, 
    SignInScope.Email, 
    SignInScope.PostalCode,
    SignInScope.ShippingAddress,
    SignInScope.PhoneNumber
};

var request = new SignInRequest
(
    signInReturnUrl: "https://example.com/account.html",
    storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
    signInScopes: scopes
);

string signature = client.GenerateButtonSignature(request);

Source code

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 (AmazonPayClientException e) {
    e.printStackTrace();
}

AmazonPayClient client = new AmazonPayClient(payConfiguration);

String payload = "{\"signInReturnUrl\":\"https://a.com/merchant-page\",\"storeId\":\"amzn1.application-oa2-client.xxxxx\",\"signInScopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\"]}";
String signature = client.generateButtonSignature(payload);

Source code

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.AmazonPayClient(config);
const payload = {
    "signInReturlUrl": "https://a.com/merchant-page",
    "storeId": "amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
    "signInScopes": ["name", "email", "postalCode", "shippingAddress", "phoneNumber"] 
};
const signature = testPayClient.generateButtonSignature(payload);

Source code

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 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

Function parameters

Parameter
Description
merchantId
(required)

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

Type: signInConfig
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' - Initial or main page
  • 'Product' - Product details page
  • 'Cart' - Cart review page before buyer starts checkout
  • 'Checkout' - Any page after buyer starts checkout
  • 'Other' - Any page that doesn't fit the previous descriptions
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
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

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.

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

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@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
}