---
title: Call finalizeCheckoutSession API
url: mobile-app-saved-wallet-ss/call-finalize-checkoutsession-api.html
---

* TOC
{:toc}
{::options toc_levels="3" /}

To confirm the buyer has returned to your website, use `finalizeCheckoutSession`. AmazonPay will append `CheckoutSessionId` as a parameter to your Universal link or App link `checkoutResultReturnUrl`. In your delegate function (where you handle Universal link/App link), you’ll need to handle `checkoutResultReturnUrl` and retrieve checkoutSessionId. Then call `finalizeCheckoutSession` API to validate button params & get chargePermissionId, buyer details, paymentDescriptor and billingAddress.

<div markdown="span" class="alert alert-info" role="alert"><i class="fa fa-info-circle"></i> <b>Note:</b> Amazon Pay will finalize the paymentIntent after you confirm checkout with finalizeCheckoutSession. Any checkout session that isn’t confirmed within 24 hours will be cancelled. If payment authorization was requested it will also be cancelled.</div>

Sample code to retrieve the checkout-session id:

### Android

```
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    // Get the Intent that started this activity and extract the data
    val data: Uri? = intent?.data

    data?.let { uri ->
        when (uri.host) {
            "[your url of checkoutResultReturnUrl]" -> {
                // 1. retrieve CheckoutSessionId
                // 2. pass CheckoutSessionId to your backend service, 
                // and call finalizeCheckoutSession API with CSId in backend
            }
            "[your url of checkoutCancelUrl]" -> {
                // redirect buyer to your App's page for cancel flow
            }
            else -> {
                // redirect buyer to your App's page for error flow
            }
        }
    }
}
```

### iOS

```
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard let url = userActivity.webpageURL else {
        return false
    }
    
    // Handle checkoutResultReturnUrl for happy path
    if url.host == "[your url of checkoutResultReturnUrl]" {
        // 1. retrieve CheckoutSessionId
        // 2. pass CheckoutSessionId to your backend service, 
        // and call finalizeCheckoutSession API with CSId in backend
    } else if url.host == "[your url of checkoutCancelUrl]" {
        // redirect buyer to your App's page for cancel flow
    } else {
        // redirect buyer to your App's page for error flow
    }
    
    return true
}
```

### Finalize Checkout Session Request

#### Request

<code style="color:black">
curl "https://pay-api.amazon.com/:version/checkoutSessions/:checkoutSessionId/finalize" \ <br />
-X POST <br />
-H "authorization:Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE" <br />
-H "x-amz-pay-date:20201012T235046Z" <br />
-d @request_body
</code>

#### Request body

```
{}
```

#### Request parameters

<table width="100%" border="1">
    <tbody>
        <tr id='ERL9CAipzsl'>
            <td id='s:ERL9CAipzsl;ERL9CAFccoh' style='vertical-align: top; font-weight: bold; width: 30%;' class='bold'>Name
                <br /></td>
            <td id='s:ERL9CAipzsl;ERL9CAjQdu4' style='vertical-align: top; font-weight: bold; width: 20%;' class='bold'>Location
                <br /></td>
            <td id='s:ERL9CAipzsl;ERL9CAxmCJ7' style='vertical-align: top; font-weight: bold; width: 50%;' class='bold'>Description
                <br /></td>
        </tr>
        <tr id='ERL9CA4LMaA'>
            <td id='s:ERL9CA4LMaA;ERL9CAFccoh' style='vertical-align: top;'>checkoutSessionId<br><b>(required)</b><br><br>Type: string
                <br /></td>
            <td id='s:ERL9CA4LMaA;ERL9CAjQdu4' style='vertical-align: top;'>Path parameter
                <br /></td>
            <td id='s:ERL9CA4LMaA;ERL9CAxmCJ7' style='vertical-align: top;'>Checkout Session identifier
                <br /></td>
        </tr>
        <tr id='ERL9CA4LMaA'>
            <td id='s:ERL9CA4LMaA;ERL9CAFccoh' style='vertical-align: top;'>supplementaryData<br><br>Type: string
                <br /></td>
            <td id='s:ERL9CA4LMaA;ERL9CAjQdu4' style='vertical-align: top;'>Body
                <br /></td>
            <td id='s:ERL9CA4LMaA;ERL9CAxmCJ7' style='vertical-align: top;'>Supplementary data about your order</td>
        </tr>
    </tbody>
</table>

#### Finalize Checkout Session Response

Returns HTTP 200 status response code if `paymentIntent` was successful. Returns HTTP 202 status response code if authorization is still pending.

```
{
    "checkoutSessionId": "bd504926-f659-4ad7-a1a9-9a747aaf5275",
    "webCheckoutDetails": null,
    "chargePermissionType": "PaymentMethodOnFile",   
    "recurringMetadata": null,
    "productType": "SignInAndSetup",
    "paymentDetails": null,
    "merchantMetadata": null,
    "supplementaryData":null, // Amazon Pay system data 
    "paymentMethodOnFileMetadata": { 
        "setupOnly": true 
    },
    "buyer": {
        "buyerId": "buyerId",
        "name": "name-1",
        "email": "name@amazon.com",
        "phoneNumber": "800-000-0000"
    },
    "paymentPreferences": [
        null
    ],
    "statusDetails": {
        "state": "Completed",
        "reasonCode": null,
        "reasonDescription": null,
        "lastUpdatedTimestamp": "20191015T204327Z"
    },
    "shippingAddress": null,
    "platformId":null,
    "chargePermissionId": "B01-5105180-3221187",
    "chargeId": "null",
    "constraints": [
        null
    ],
    "creationTimestamp": "20191015T204313Z",
    "expirationTimestamp": null,
    "storeId": null,
    "deliverySpecifications": null,
    "providerMetadata": null,
    "checkoutButtonText": null,
    "releaseEnvironment": null
}
```