Step2 Get SDK and prepare for button rendering
1. Download SDK
Amazon Pay provides SDK and sample code for PHP, Java, .NET(C#), Node.js, Ruby and Perl. Download SDK.
2. Prepare fundamental parts to put in Amazon Pay button rendering script
Parts sample
OneTime/Recurring x PayAndShip/PayOnly sample parts as below.
caution
Note that payloadJSON should be written in one line, but below sample is broken in line for readbility
- OneTime-PayAndShip
- OneTime-PayOnly
- Recurring-PayAndShip
- Recurring-PayOnly
{
"merchantId": "xxxxxx",
"ledgerCurrency": "JPY",
"sandbox": true,
"checkoutLanguage": "ja_JP",
"productType": "PayAndShip",
"placement": "Cart",
"buttonColor": "Gold",
"createCheckoutSessionConfig": {
"payloadJSON": '{
"webCheckoutDetails": {
"checkoutReviewReturnUrl": "http://localhost:3000/review/",
"checkoutCancelUrl": "http://localhost:3000/cancel/"
},
"storeId": "amzn1.application-oa2-client.ccxxxxxx",
"chargePermissionType": "OneTime",
"deliverySpecifications": {
"addressRestrictions": {
"type": "Allowed",
"restrictions": {
"JP": {
"statesOrRegions": ["東京都"],
"zipCodes": ["1530064"]
}
}
}
},
"paymentDetails": {
"allowOvercharge": false,
"extendExpiration": false
},
"scopes": ["name","email","phoneNumber","billingAddress"]
}',
"signature": "xxxxxxx",
"publicKeyId": "SANDBOX-xxxxxx"
}
}
{
"merchantId": "xxxxxx",
"ledgerCurrency": "JPY",
"sandbox": true,
"checkoutLanguage": "ja_JP",
"productType": "PayOnly",
"placement": "Cart",
"buttonColor": "Gold",
"createCheckoutSessionConfig": {
"payloadJSON": '{
"webCheckoutDetails": {
"checkoutReviewReturnUrl": "http://localhost:3000/review/",
"checkoutCancelUrl": "http://localhost:3000/cancel/"
},
"storeId": "amzn1.application-oa2-client.ccxxxxxx",
"chargePermissionType": "OneTime",
"paymentDetails": {
"allowOvercharge": false,
"extendExpiration": false
},
"scopes": ["name","email","phoneNumber","billingAddress"]
}',
"signature": "xxxxxx",
"publicKeyId": "SANDBOX-xxxxxx"
}
}
{
"merchantId": "xxxxxx",
"ledgerCurrency": "JPY",
"sandbox": true,
"checkoutLanguage": "ja_JP",
"productType": "PayAndShip",
"placement": "Cart",
"buttonColor": "Gold",
"createCheckoutSessionConfig": {
"payloadJSON": '{
"webCheckoutDetails": {
"checkoutReviewReturnUrl": "http://localhost:3000/review/",
"checkoutCancelUrl": "http://localhost:3000/cancel/"
},
"storeId": "amzn1.application-oa2-client.ccxxxxx",
"chargePermissionType": "Recurring",
"deliverySpecifications": {
"addressRestrictions": {
"type": "Allowed",
"restrictions": {
"JP": {
"statesOrRegions": ["東京都"],
"zipCodes": ["1530064"]
}
}
}
},
"scopes": ["name","email","phoneNumber","billingAddress"],
"recurringMetadata": {
"frequency": {
"unit": "Month",
"value": "1"
},
"amount": {
"amount": "1000",
"currencyCode": "JPY"
}
}
}',
"signature": "xxxxxx",
"publicKeyId": "SANDBOX-xxxxx"
}
}
{
"merchantId": "xxxxxx",
"ledgerCurrency": "JPY",
"sandbox": true,
"checkoutLanguage": "ja_JP",
"productType": "PayOnly",
"placement": "Cart",
"buttonColor": "Gold",
"createCheckoutSessionConfig": {
"payloadJSON": {
"webCheckoutDetails": {
"checkoutReviewReturnUrl": "http://localhost:3000/review/",
"checkoutCancelUrl": "http://localhost:3000/cancel/"
},
"storeId": "amzn1.application-oa2-client.ccxxxxxx",
"chargePermissionType": "Recurring",
"scopes": ["name","email","phoneNumber","billingAddress"],
"recurringMetadata": {
"frequency": {
"unit": "Month",
"value": "1"
},
"amount": {
"amount": "1000",
"currencyCode": "JPY"
}
}
},
"signature": "xxxxxx",
"publicKeyId": "SANDBOX-xxxxxx"
}
}
- merchantId: Set merchantId you get from Step1 Get storeId, merchantId, publicKey and privateKey
- ledgerCurrency: Always set "JPY".
- sandbox: Set true if you are using sandbox
- checkoutLanguage: Always set "ja_JP"
- productType: Set "PayAndShip" in case shipping of goods is involved, or set "PayOnly" in case of digital contents.
- See placement
Regardless of which value you set in placement, Amazon Pay button look and its behavior won't change. However, we use placement value to understand which Amazon Pay button on your site is used to initaite respective checkout, and may use such metrics to provide you with further insights and improvement proposal in the future. So please use different plamcent value for each Amazon Pay button depending on the button location or checkout scenario. If you need any advise on placement value, please kindly contact Amazon Pay members. - See buttonColor
- webCheckoutDetails
- checkoutReviewReturnUrl: Set URL where Amazon Pay redirects buyer when buyer completes login on Amazon hosted page.
- checkoutCancelUrl: Set URL where Amazon Pay redirects buyer when buyer clicks on "cancel" link on Amazon hosted page.
- storeId: Set store ID you got from Step1 Get storeId, merchantId, publicKey and privateKey.
- chargePermissionType: OneTime or Recurring
- See deliverySpecification
- paymentDetails
- See allowOvercharge
- See extendExpiration
- scopes: Set scopes if you want to get such data during checkout session
- recurringMetadata: Only in case of Recurring checkout. See this page
- signature: Set signature for payload. There are two ways to generate signature which is explained in "Sign the payload" below.
- publicKeyId: Set publicKeyId you got from Step1 Get storeId, merchantId, publicKey and privateKey.
Sign the payload
payload
is the part shown below within Parts sample.
{
"webCheckoutDetails": {
.
.
.
"scopes": ["name","email","phoneNumber","billingAddress"]
}
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.
There are two ways to generate signature.
- Generate a signature using the helper function provided in the Amazon Pay SDKs: Integration Guide - Sign the payload
- Build the signature manually: Integration Guide - Signing requests