Verify & complete checkout
[Step 6 of 11] The buyer is redirected to checkoutResultReturnUrl after Amazon Pay has processed the transaction. The Amazon Pay checkout session ID will be included as a query parameter.
In this step, you will use the checkout session ID to confirm that the buyer has successfully returned to your site and finalize the paymentIntent. At the end of this step, you will be able to present the buyer with the checkout result.
Note: If your publicKeyId
does not have an environment prefix (does not begin with 'SANDBOX' or 'LIVE') follow
these instructions instead.
Note: If your publicKeyId has an environment prefix (for example: SANDBOX-AFVX7ULWSGBZ5535PCUQOY7B) follow
these instructions instead.
1. Complete Checkout Session
Use Complete Checkout Session to confirm that the buyer has successfully returned to your site. The chargeAmount in the request must match the Checkout Session object paymentDetails.chargeAmount to verify order amount.
Note: Amazon Pay will not finalize the paymentIntent until you confirm checkout with Complete Checkout Session. Any Checkout Session that is not confirmed within 24 hours will be cancelled. If payment authorization was requested it will also be cancelled.
Successful response:
Complete Checkout Session will return a success response if the transaction was processed successfully. Implement the guidance that corresponds to the Checkout Session paymentIntent:
paymentIntent
|
Description
|
AuthorizeWithCapture
|
Payment has been authorized and captured.
1. Store the ChargeId - You must store the ChargeId to process refunds.
2. Store the ChargePermissionId - Store the ChargePermissionId for future payments. For recurring Charge Permissions, see managing recurring payments for more information. You can also use the ChargePermissionId to retrieve buyer and transaction info after checkout.
|
Authorize
|
Payment has been authorized.
1. Store the ChargeId - You must store the ChargeID for deferred payment capture. See deferred transactions for more info.
2. Store the ChargePermissionId - Store the ChargePermissionId for future payments. For recurring Charge Permissions, see managing recurring payments for more information. You can also use the ChargePermissionId to retrieve buyer and transaction info after checkout.
|
Confirm
|
Payment has not been authorized or captured.
1. Store the ChargePermissionId - Store the ChargePermissionId for future payments. For recurring Charge Permissions, see managing recurring payments for more information. Otherwise, see manage deferred payments. You can also use the ChargePermissionId to retrieve buyer and transaction info after checkout.
|
Error response:
Complete Checkout Session will return an error response for failed transactions. The buyer either canceled checkout or was unable to provide a valid payment instrument. You should:
- Redirect the buyer to the start of checkout
- Display a message such as: "Your payment was not successful. Please try another payment method.“
Request
curl "https://pay-api.amazon.com/:version/checkoutSessions/:checkoutSessionId/complete" \
-X POST
-H "authorization:Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE"
-H "x-amz-pay-date:20201012T235046Z"
-d @request_body
curl "https://pay-api.amazon.com/:environment/:version/checkoutSessions/:checkoutSessionId/complete" \
-X POST
-H "authorization:Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE"
-H "x-amz-pay-date:20201012T235046Z"
-H "x-amz-pay-idempotency-key:AVLo5tI10BHgEk2jEXAMPLEKEY"
-d @request_body
Request body
{
"chargeAmount": {
"amount": "14.00",
"currencyCode": "USD"
}
}
Request parameters
Name
|
Location
|
Description
|
checkoutSessionId (required)
Type: string
|
Path parameter
|
Checkout Session identifier
|
chargeAmount (required)
Type: price
|
Body
|
Transaction amount
|
Sample Code
<?php
include 'vendor/autoload.php';
$amazonpay_config = array(
'public_key_id' => 'YOUR_PUBLIC_KEY_ID',
'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation)
'region' => 'YOUR_REGION_CODE',
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2'
);
$payload = array(
'chargeAmount' => array(
'amount' => '14.00',
'currencyCode' => 'USD'
)
);
try {
$client = new Amazon\Pay\API\Client($amazonpay_config);
$result = $client->completeCheckoutSession('bd504926-f659-4ad7-a1a9-9a747aaf5275', $payload);
if ($result['status'] === 202) {
// Charge Permission is in AuthorizationInitiated state
$response = json_decode($result['response'], true);
$checkoutSessionState = $response['statusDetails']['state'];
$chargeId = $response['chargeId'];
$chargePermissionId = $response['chargePermissionId'];
}
else if ($result['status'] === 200) {
$response = json_decode($result['response'], true);
$checkoutSessionState = $response['statusDetails']['state'];
$chargePermissionId = $response['chargePermissionId'];
} else {
// check the error
echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n";
}
} catch (Exception $e) {
// handle the exception
echo $e;
}
?>
using Amazon.Pay.API.Types;
using Amazon.Pay.API.WebStore;
using Amazon.Pay.API.WebStore.Types;
using Amazon.Pay.API.WebStore.CheckoutSession;
public class Sample
{
public WebStoreClient InitiateClient()
{
// set up config
var payConfiguration = new ApiConfiguration
(
region: Region.YOUR_REGION_CODE,
publicKeyId: "YOUR_PUBLIC_KEY_ID",
privateKey: "PATH_OR_CONTENT_OF_YOUR_PRIVATE_KEY",
algorithm: AmazonSignatureAlgorithm.V2
);
// init API client
var client = new WebStoreClient(payConfiguration);
return client;
}
public CheckoutSessionResponse CompleteCheckoutSession(string checkoutSessionId)
{
// prepare the request
var request = new CompleteCheckoutSessionRequest(14.00M, Currency.USD);
// send the request
var result = client.CompleteCheckoutSession(checkoutSessionId, request);
// check if API call was successful
if (!result.Success)
{
// do something, e.g. throw an error
}
return result;
}
}
import com.amazon.pay.api.AmazonPayResponse;
import com.amazon.pay.api.PayConfiguration;
import com.amazon.pay.api.WebstoreClient;
import com.amazon.pay.api.exceptions.AmazonPayClientException;
import com.amazon.pay.api.types.Region;
import org.json.JSONObject;
public void sample() {
PayConfiguration payConfiguration = null;
try {
payConfiguration = new PayConfiguration()
.setPublicKeyId("YOUR_PUBLIC_KEY_ID")
.setRegion(Region.YOUR_REGION_CODE)
.setPrivateKey("YOUR_PRIVATE_KEY")
.setAlgorithm("AMZN-PAY-RSASSA-PSS-V2");
WebstoreClient webstoreClient = new WebstoreClient(payConfiguration);
AmazonPayResponse response = null;
String checkoutSessionId = "bd504926-f659-4ad7-a1a9-9a747aaf5275";
JSONObject payload = new JSONObject();
JSONObject chargeAmount = new JSONObject();
chargeAmount.put("amount", "14.00");
chargeAmount.put("currencyCode", "USD");
payload.put("chargeAmount", chargeAmount);
response = webstoreClient.completeCheckoutSession(checkoutSessionId, payload);
String chargePermissionId = response.getResponse().getString("chargePermissionId");
} catch (AmazonPayClientException e) {
e.printStackTrace();
}
}
const fs = require('fs');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');
const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'YOUR_REGION_CODE',
algorithm: 'AMZN-PAY-RSASSA-PSS-V2'
};
const payload = {
chargeAmount: {
amount: "14.00",
currencyCode: "USD"
}
};
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.completeCheckoutSession('bd504926-f659-4ad7-a1a9-9a747aaf5275', payload);
response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
<?php
include 'vendor/autoload.php';
$amazonpay_config = array(
'public_key_id' => 'YOUR_PUBLIC_KEY_ID',
'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation)
'region' => 'YOUR_REGION_CODE',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2'
);
$payload = array(
'chargeAmount' => array(
'amount' => '14.00',
'currencyCode' => 'USD'
)
);
try {
$client = new Amazon\Pay\API\Client($amazonpay_config);
$result = $client->completeCheckoutSession('bd504926-f659-4ad7-a1a9-9a747aaf5275', $payload);
if ($result['status'] === 202) {
// Charge Permission is in AuthorizationInitiated state
$response = json_decode($result['response'], true);
$checkoutSessionState = $response['statusDetails']['state'];
$chargeId = $response['chargeId'];
$chargePermissionId = $response['chargePermissionId'];
}
else if ($result['status'] === 200) {
$response = json_decode($result['response'], true);
$checkoutSessionState = $response['statusDetails']['state'];
$chargePermissionId = $response['chargePermissionId'];
} else {
// check the error
echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n";
}
} catch (Exception $e) {
// handle the exception
echo $e;
}
?>
using Amazon.Pay.API.Types;
using Amazon.Pay.API.WebStore;
using Amazon.Pay.API.WebStore.Types;
using Amazon.Pay.API.WebStore.CheckoutSession;
public class Sample
{
public WebStoreClient InitiateClient()
{
// set up config
var payConfiguration = new ApiConfiguration
(
region: Region.YOUR_REGION_CODE,
environment: Environment.Sandbox,
publicKeyId: "YOUR_PUBLIC_KEY_ID",
privateKey: "PATH_OR_CONTENT_OF_YOUR_PRIVATE_KEY",
algorithm: AmazonSignatureAlgorithm.V2
);
// init API client
var client = new WebStoreClient(payConfiguration);
return client;
}
public CheckoutSessionResponse CompleteCheckoutSession(string checkoutSessionId)
{
// prepare the request
var request = new CompleteCheckoutSessionRequest(14.00M, Currency.USD);
// send the request
var result = client.CompleteCheckoutSession(checkoutSessionId, request);
// check if API call was successful
if (!result.Success)
{
// do something, e.g. throw an error
}
return result;
}
}
import com.amazon.pay.api.AmazonPayResponse;
import com.amazon.pay.api.PayConfiguration;
import com.amazon.pay.api.WebstoreClient;
import com.amazon.pay.api.exceptions.AmazonPayClientException;
import com.amazon.pay.api.types.Environment;
import com.amazon.pay.api.types.Region;
import org.json.JSONObject;
public void sample() {
PayConfiguration payConfiguration = null;
try {
payConfiguration = new PayConfiguration()
.setPublicKeyId("YOUR_PUBLIC_KEY_ID")
.setRegion(Region.YOUR_REGION_CODE)
.setPrivateKey("YOUR_PRIVATE_KEY")
.setEnvironment(Environment.SANDBOX)
.setAlgorithm("AMZN-PAY-RSASSA-PSS-V2");
WebstoreClient webstoreClient = new WebstoreClient(payConfiguration);
AmazonPayResponse response = null;
String checkoutSessionId = "bd504926-f659-4ad7-a1a9-9a747aaf5275";
JSONObject payload = new JSONObject();
JSONObject chargeAmount = new JSONObject();
chargeAmount.put("amount", "14.00");
chargeAmount.put("currencyCode", "USD");
payload.put("chargeAmount", chargeAmount);
response = webstoreClient.completeCheckoutSession(checkoutSessionId, payload);
String chargePermissionId = response.getResponse().getString("chargePermissionId");
} catch (AmazonPayClientException e) {
e.printStackTrace();
}
}
const fs = require('fs');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');
const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'YOUR_REGION_CODE',
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2'
};
const payload = {
chargeAmount: {
amount: "14.00",
currencyCode: "USD"
}
};
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.completeCheckoutSession('bd504926-f659-4ad7-a1a9-9a747aaf5275', payload);
response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
Response
{
"checkoutSessionId": "bd504926-f659-4ad7-a1a9-9a747aaf5275",
"webCheckoutDetails": null,
"chargePermissionType": "Recurring",
"recurringMetadata": null,
"productType": null,
"paymentDetails": null,
"merchantMetadata": null,
"supplementaryData":null, // Amazon Pay system data
"buyer": null,
"billingAddress": null,
"paymentPreferences": [
null
],
"statusDetails": {
"state": "Completed",
"reasonCode": null,
"reasonDescription": null,
"lastUpdatedTimestamp": "20191015T204327Z"
},
"shippingAddress": null,
"platformId":null,
"chargePermissionId": "S01-5105180-3221187",
"chargeId": "S01-5105180-3221187-C056351",
"constraints": [
null
],
"creationTimestamp": "20191015T204313Z",
"expirationTimestamp": "20191016T204313Z",
"storeId": "amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
"deliverySpecifications": null,
"providerMetadata": null,
"checkoutButtonText": null,
"releaseEnvironment": null
}
2. Add shipment tracking info
Note: This section is only applicable if you ship packages using a supported carrier.
Send shipment tracking information to Amazon Pay using the Delivery Tracker API. Amazon Pay will notify your buyers on their Alexa device when their package is shipped and when their package is delivered. See setting up delivery notifications for more info.