---
title: Steps to integrate with Amazon Pay's hosted update page
url: amazon-pay-paymentmethodonfile/steps-to-integrate-with-amazon-pay-hosted-update-page.html
---

You can integrate with Amazon Pay’s solution that handles the payment and address update for the buyer. 

Follow below steps to integrate the solution:
* Add the Amazon Pay script
* Provide a payload that Amazon Pay will use to create a Checkout Session object that will be used for the update. Amazon Pay will use the Checkout Session object to manage the buyer’s activity during the update.
* Sign the payload. 
* Render a custom button and call Amazon Pay’s init checkout API
* Once buyer updates the address/PI and returns to youryou website, use Complete Checkout Session to confirm that the buyer has successfully returned to your site.
* <a href="../amazon-pay-paymentmethodonfile/set-up-instant-payment-notifications.md" target="_blank" rel="noopener noreferrer">Set up IPNs</a> to receive notifications whenever buyers update their payment method or address.

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

***

### 1. Add the Amazon Pay script

Add the Amazon Pay script to your HTML file. Be sure you select the correct region.

<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#ustab" data-toggle="tab">US</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#eutab" data-toggle="tab">EU / UK</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#jptab" data-toggle="tab">JP</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="ustab">   
<div markdown="block">
```html
<script src="https://static-na.payments-amazon.com/checkout.js"></script>
```
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="eutab">
<div markdown="block">
```html
<script src="https://static-eu.payments-amazon.com/checkout.js"></script>
```
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="jptab">
<div markdown="block">
```html
<script src="https://static-fe.payments-amazon.com/checkout.js"></script>
```
</div>
  </div>
</div>

***

### 2. Generate the Create Checkout Session payload

Provide a payload that Amazon Pay will use to create a <a href="../amazon-pay-paymentmethodonfile/checkout-session.md" target="_blank" rel="noopener noreferrer">Checkout Session</a> object that will be used for the update. Amazon Pay will use the Checkout Session object to manage the buyer’s activity during the update.

**Instructions for generating button payload for the update flow:**

* Set `checkoutResultReturnUrl` parameter to the URL that the buyer is redirected to after they select their preferred payment method. The Checkout Session ID will be appended as a query parameter.
* Set `chargePermissionId` to the *Saved Wallet* charge permission id value stored for the buyer.
* Set `chargePermissionType` to `PaymentMethodOnFile`
* Set `productType` as “PayAndShip”
  * If buyer intends to update an address
  * If buyer intends to update payment method for a charge permission id that has an associated address
  * If you intend to update theSaved Wallet Charge Permission Id from a “PayOnly” product type to a “PayAndShip” productType.
* Set `productType` as “PayOnly” if the Saved Wallet Charge Permission Id stored on your systems was of type “PayOnly” and buyer's intention is to update the payment method alone.
* Provide details for `paymentMethodOnFileMetadata`: Provide `setupOnly = true` to initiate a update payment method or address flow for a Saved Wallet charge permission id.
* Set `paymentIntent = Confirm` since there is no transaction happening in update flow.

**Optional integrations steps:**
* Use the `deliverySpecifications` parameter to specify shipping restrictions to prevent buyers from selecting unsupported addresses from their Amazon address book. See [address restriction samples](../amazon-pay-checkout/v1-address-restriction-samples.html) for samples how to handle common use-cases.

#### Payload example

```
{
    "webCheckoutDetails": {
        "checkoutResultReturnUrl": "https://a.com/merchant-result-page"
    },
    "storeId": "amzn1.application-oa2-client.8b5e45312b5248b69eeaStoreId",
    "chargePermissionId": "B01-0000000-0000000",
    "chargePermissionType": "PaymentMethodOnFile",
    "paymentMethodOnFileMetadata": {
        "setupOnly": true
    },
    "paymentDetails": {
        "paymentIntent": "Confirm",
        "canHandlePendingAuthorization": false        
    }    
    "deliverySpecifications": {
        "specialRestrictions": ["RestrictPOBoxes"],
        "addressRestrictions": {
            "type": "Allowed",
            "restrictions": {
                "US": {
                    "statesOrRegions": ["WA"],
                    "zipCodes": ["95050", "93405"]
                },
                "GB": {
                    "zipCodes": ["72046", "72047"]
                },
                "IN": {
                    "statesOrRegions": ["AP"]
                },
                "JP": {}
            }
        }
    }
} 
```

<table width="100%" border="1">
    <tbody>
        <tr id='SPI9CAupGTX'>
            <td id='s:SPI9CAupGTX;SPI9CAPMpxx' style='vertical-align: top; font-weight: bold; width: 30%' class='bold'>Name
                <br /></td>
            <td id='s:SPI9CAupGTX;SPI9CAm9zzw' style='vertical-align: top; font-weight: bold; width: 20%' class='bold'>Location
                <br /></td>
            <td id='s:SPI9CAupGTX;SPI9CAMemY9' style='vertical-align: top; font-weight:bold;  width: 50%' class='bold'>Description
                <br /></td>
        </tr>
        <tr id='SPI9CAI5yKv'>
            <td id='s:SPI9CAI5yKv;SPI9CAPMpxx' style='vertical-align: top;'>webCheckoutDetails<br><b>(required)</b><br /><br />Type: <a href="../amazon-pay-paymentmethodonfile/checkout-session.md#type-webcheckoutdetails" target="_blank" rel="noopener noreferrer">webCheckoutDetails</a>
                <br /></td>
            <td id='s:SPI9CAI5yKv;SPI9CAm9zzw' style='text-align: left;vertical-align: top;'>Body
                <br /></td>
            <td id='s:SPI9CAI5yKv;SPI9CAMemY9' style='vertical-align: top;'>URLs associated to the Checkout Session used to complete checkout. The URLs must use HTTPS protocol
                <br /></td>
        </tr>
        <tr id='SPI9CAQrHNB'>
            <td id='s:SPI9CAQrHNB;SPI9CAPMpxx' style='vertical-align: top;'>storeId<br><b>(required)</b><br><br>Type: string
                <br /></td>
            <td id='s:SPI9CAQrHNB;SPI9CAm9zzw' style='vertical-align: top;'>Body
                <br /></td>
            <td id='s:SPI9CAQrHNB;SPI9CAMemY9' style='vertical-align: top;'>Amazon Pay store ID. Retrieve this value from Amazon Pay Integration Central: <a href="https://sellercentral.amazon.com/gp/pyop/seller/integrationcentral/" target="_blank" rel="noopener noreferrer">US</a>, <a href="https://sellercentral-europe.amazon.com/gp/pyop/seller/integrationcentral/" target="_blank" rel="noopener noreferrer">EU</a>, <a href="https://sellercentral-japan.amazon.com/gp/pyop/seller/integrationcentral/" target="_blank" rel="noopener noreferrer">JP</a>
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>scopes<br /><br />Type: list &lt;scope&gt;
                <br /></td>
            <td id='' style='text-align: left;vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>The buyer details that you're requesting access to. Specify whether you need shipping address using button <code>productType</code> parameter in Step 4.<br><br>Supported values:
                    <ul>
                      <li>'name' - Buyer name</li>
                      <li>'email' - Buyer email</li>
                      <li>'phoneNumber' - Default billing address phone number</li>
                      <li>'billingAddress' - Default billing address</li>
                    </ul>
            Default value: all buyer information except billing address is requested if the <code>scopes</code> parameter is not set
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>chargePermissionId<br /><br />Type: string
                <br /></td>
            <td id='' style='text-align: left;vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>The buyer's Saved Wallet charge permission id with the merchant
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>chargePermissionType<br /><br />Type: string
                <br /></td>
            <td id='' style='text-align: left;vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>The type of Charge Permission requested<br><br>Supported values:
                    <ul>
                      <li>'OneTime' - The Charge Permission can only be used for a single order</li>
                      <li>'Recurring' - The Charge Permission can be used for recurring orders</li>
                      <li>'PaymentMethodOnFile' - The Charge Permission can be used for Saved Wallet orders</li>
                    </ul>
            Default value: 'OneTime"
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>paymentDetails<br><br>Type: <a href="../amazon-pay-paymentmethodonfile/checkout-session.md#type-paymentdetails" target="_blank" rel="noopener noreferrer">paymentDetails</a>
                <br /></td>
            <td id='' style='vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>Payment details specified by the merchant such as the amount and method for charging the buyer<br><br>Modifiable: Multiple times before the buyer is redirected to the <code>amazonPayReturnUrl</code>
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>merchantMetadata<br><br>Type: <a href="../amazon-pay-paymentmethodonfile/checkout-session.md#type-merchantmetadata" target="_blank" rel="noopener noreferrer">merchantMetadata</a>
                <br /></td>
            <td id='' style='vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>External order details provided by the merchant<br><br>Modifiable: Multiple times before the buyer is redirected to the <code>amazonPayReturnUrl</code>
                <br /></td>
        </tr>
        <tr id=''>
            <td id='' style='vertical-align: top;'>paymentMethodOnFileMetadata<br /><br />Type: <a href="../amazon-pay-paymentmethodonfile/checkout-session.md#type-paymentmethodonfilemetadata" target="_blank" rel="noopener noreferrer">paymentMethodOnFileMetadata</a>
                <br /></td>
            <td id='' style='text-align: left;vertical-align: top;'>Body
                <br /></td>
            <td id='' style='vertical-align: top;'>Metadata about how Saved Wallet charge permission will be used.
                <br /></td>
        </tr>
    </tbody>
</table>

***

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

<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#phptab" data-toggle="tab">PHP</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#dotnettab" data-toggle="tab">.NET</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#javatab" data-toggle="tab">Java</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#nodejstab" data-toggle="tab">Node.js</a></li>
</ul>
<div class="tab-content">
  <div role="tabpanel" class="tab-pane active" id="phptab">   
<div markdown="block">
```
<?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":{"checkoutResultReturnUrl":"https://example.com/review.html"},"chargePermissionId": "B01-0000000-0000000","chargePermissionType":"PaymentMethodOnFile","paymentMethodOnFileMetadata":{"setupOnly": true}, "paymentDetails": {"paymentIntent": "Confirm", "canHandlePendingAuthorization": false}}';
    $signature = $client->generateButtonSignature($payload);
    echo $signature . "\n";
?>
```
<a href="https://github.com/amzn/amazon-pay-api-sdk-php/blob/master/Amazon/Pay/API/Client.php#L400"  target="_blank" rel="noopener noreferrer">Source code</a>
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="dotnettab">
<div markdown="block">
```
var payConfiguration = new ApiConfiguration
(
    region: Region.Europe,
    environment: Environment.Sandbox,
    publicKeyId: "MY_PUBLIC_KEY_ID",
    privateKey: "PATH_OR_CONTENT_OF_MY_PRIVATE_KEY"
);

var request = new  CreateCheckoutSessionRequest
(
    checkoutReviewReturnUrl: "https://example.com/review.html",
    storeId: "amzn1.application-oa2-client.xxxxx",
    chargePermissionId: "B01-0000000-0000000"
);

request.ChargePermissionType = ChargePermissionType.PaymentMethodOnFile;
request.PaymentMethodOnFileMetadata.SetupOnly = true;
request.PaymentDetails.PaymentIntent = PaymentIntent.Confirm;
request.PaymentDetails.CanHandlePendingAuthorization = false;

// generate the payload signature
var signature = client.GenerateButtonSignature(request);

// the payload as JSON string that you must assign to the button in the next step
var payload = request.ToJson(); 
```
<a href="https://github.com/amzn/amazon-pay-api-sdk-dotnet/#generate-button-signature" target="_blank" rel="noopener noreferrer">Source code</a>
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="javatab">
<div markdown="block">
```
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.xxxxxx\",\"webCheckoutDetails\":{\"checkoutResultReturnUrl\":\"https://example.com/review.html\"},\"chargePermissionId\":\"B01-0000000-0000000\",\"chargePermissionType\":\"PaymentMethodOnFile\",\"paymentMethodOnFileMetadata\":{\"setupOnly\": true}, \"paymentDetails\": {\"paymentIntent\": \"Confirm\", \"canHandlePendingAuthorization\": false}}";
String signature = client.generateButtonSignature(payload);

```
<a href="https://github.com/amzn/amazon-pay-api-sdk-java/blob/bbbf89c480f07f8a7217a0a50e88131832612f59/src/com/amazon/pay/api/AmazonPayClient.java#L105"  target="_blank" rel="noopener noreferrer">Source code</a>
</div>
  </div>
  <div role="tabpanel" class="tab-pane" id="nodejstab">
<div markdown="block">
```html
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
};

const testPayClient = new Client.AmazonPayClient(config);
const payload = {
    "webCheckoutDetails": {
        "checkoutResultReturnUrl": "https://example.com/review.html"
    },
    "storeId": "amzn1.application-oa2-client.xxxxx",
    "chargePermissionId": "B01-0000000-0000000",
    "chargePermissionType": "PaymentMethodOnFile",   
    "paymentMethodOnFileMetadata": {
        "setupOnly": true
    },
    "paymentDetails": {
        "paymentIntent": "Confirm",
        "canHandlePendingAuthorization": false
    }
};
const signature = testPayClient.generateButtonSignature(payload);
```
<a href="https://github.com/amzn/amazon-pay-api-sdk-nodejs/blob/23c3f03f06a4deab437a42885e1d1f548287e7f3/src/client.js#L60"  target="_blank" rel="noopener noreferrer">Source code</a>
</div>
  </div>
</div>

**Option 2:** Build the signature manually by following steps 2 and 3 of the <a href="../amazon-pay-api-v2/signing-requests.md" target="_blank" rel="noopener noreferrer">signing requests</a> guide.

***

### 4. Render an UI element and call Amazon Pay's init checkout API

Any UI element can be rendered to trigger the payment method and/or address update. UI element click should be bound to call amazon pay’s init update function as shown in the example below. Once the UI element is clicked buyer will be redirected to Amazon’s page where they can update the payment method or address.

After the successful update buyer is redirected back to the `checkoutResultReturnUrl` that was set in the payload.

**NOTE:** The amzon.Pay.initUpdate() function is not yet available, to test the update flow, please use amazon.Pay.initCheckout() function instead.

#### Code sample

<div>
<ul id="profileTabs" class="nav nav-tabs">
  <li class="nav-item"><a class="active nav-link noExtIcon" href="#usButtonTab" data-toggle="tab">US</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#euButtonTab" data-toggle="tab">EU</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#ukButtonTab" data-toggle="tab">UK</a></li>
  <li class="nav-item"><a class="nav-link noExtIcon" href="#jpButtonTab" data-toggle="tab">JP</a></li>
</ul>
<div class="tab-content">


  <div role="tabpanel" class="tab-pane active" id="usButtonTab">   
<div markdown="block">
```html
<body>
    <button onclick="initAmazonPayUpdate()">Update</button>
    <script src="https://static-na.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        function initAmazonPayUpdate() {
            amazon.Pay.initUpdate({
                merchantId: 'merchant_id',
                ledgerCurrency: 'USD',
                sandbox: false,            
                checkoutLanguage: 'en_US',
                productType: 'PayAndShip',
                createCheckoutSessionConfig: {                     
                    payloadJSON: 'payload', 
                    signature: 'xxxx',
                    publicKeyId: 'xxxxxxxxxx'
                }   
            });
        }
    </script>
</body>
```
</div>
  </div>

  <div role="tabpanel" class="tab-pane" id="euButtonTab">
<div markdown="block">
```html
<body>
    <button onclick="initAmazonPayUpdate()">Update</button>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        function initAmazonPayUpdate() {
            amazon.Pay.initUpdate({
                merchantId: 'merchant_id',
                ledgerCurrency: 'EUR',
                sandbox: false,            
                checkoutLanguage: 'en_GB',
                productType: 'PayAndShip',
                createCheckoutSessionConfig: {                     
                    payloadJSON: 'payload', 
                    signature: 'xxxx',
                    publicKeyId: 'xxxxxxxxxx'
                }   
            });
        }
    </script>
</body>
```
</div>
  </div>

<div role="tabpanel" class="tab-pane" id="ukButtonTab">
<div markdown="block">
```html
<body>
    <button onclick="initAmazonPayUpdate()">Update</button>
    <script src="https://static-eu.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        function initAmazonPayUpdate() {
            amazon.Pay.initUpdate({
                merchantId: 'merchant_id',
                ledgerCurrency: 'GBP',
                sandbox: false,            
                checkoutLanguage: 'en_GB',
                productType: 'PayAndShip',
                createCheckoutSessionConfig: {                     
                    payloadJSON: 'payload', 
                    signature: 'xxxx',
                    publicKeyId: 'xxxxxxxxxx'
                }   
            });
        }
    </script>
</body>
```
</div>
  </div>  

  <div role="tabpanel" class="tab-pane" id="jpButtonTab">
<div markdown="block">
```html
<body>
    <button onclick="initAmazonPayUpdate()">Update</button>
    <script src="https://static-fe.payments-amazon.com/checkout.js"></script>
    <script type="text/javascript" charset="utf-8">
        function initAmazonPayUpdate() {
            amazon.Pay.initUpdate({
                merchantId: 'merchant_id',
                ledgerCurrency: 'JPY',
                sandbox: false,            
                checkoutLanguage: 'ja_JP',
                productType: 'PayAndShip',
                createCheckoutSessionConfig: {                     
                    payloadJSON: 'payload', 
                    signature: 'xxxx',
                    publicKeyId: 'xxxxxxxxxx'
                }   
            });
        }
    </script>
</body>
```
</div>
  </div>
</div>
</div>

***

### 5. Set up Instant Payment Notifications (IPN)

<a href="../amazon-pay-paymentmethodonfile/set-up-instant-payment-notifications.md" target="_blank" rel="noopener noreferrer">Set up IPNs</a> to receive notifications whenever buyers update their payment method or address.