Merci de votre visite. Cette page est disponible en anglais uniquement.

Add the Amazon Pay button

The Amazon Pay checkout experience starts when the buyer clicks on the Amazon Pay button. Add Amazon Pay to the payment selection at the end of checkout of your shop. You have 2 options for adding AmazonPay button: Call AmazonPay’s renderButton method to render AmazonPay button and handle button click, or create a custom button and call AmazonPay’s initCheckout method to handle button click.

Android

1. Add .aar file under your “lib” folder of your Android app project

Copy the .aar file from the Android bundle you’ve downloaded to the /app/lib folder in your Android project directory.

2. Add Dependencies

In your module-level build.gradle file, add the following dependencies:

apply plugin: 'kotlin-kapt'

dependencies {

    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    releaseImplementation files('libs/AmazonPayAndroidLib-release.aar')

    implementation 'androidx.activity:activity-compose:1.9.0'
    implementation platform('androidx.compose:compose-bom:2024.06.00')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.ui:ui-graphics'
    implementation 'androidx.compose.ui:ui-tooling-preview'
    implementation 'androidx.compose.material3:material3'

    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.core:core-ktx:1.13.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.22'
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.9.22'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'androidx.browser:browser:1.8.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.3'
    implementation 'com.google.dagger:dagger:2.51.1'
    kapt 'com.google.dagger:dagger-compiler:2.51.1'
    implementation 'com.google.dagger:dagger-android:2.51.1'
    implementation 'com.google.dagger:dagger-android-support:2.51.1'
    kapt 'com.google.dagger:dagger-android-processor:2.51.1'
}

After you have added the dependencies in your module-level build.gradle file, got to the Android Studio menu, select File, and then click Sync Projects with Gradle Files to make sure the project is synchronized with the updated dependencies.

3. Render Button

To render the button, you have 2 options:

  1. Invoke renderButton to display a Composable Amazon Pay button.
  2. Create your button and call initCheckout when clicked.
3.1 Call renderButton method

The renderButton method accepts a JSON object as input and returns a Composable button. You can use the JSON object to trigger one of the 5 supported flows by using the 1. Button render parameters

Here is an example of creating a Composable Amazon Pay button with the Saved Wallet Setup Only flow by calling the renderButton method:

import com.amazonpay.android.AmazonPayButton

@Composable
fun SavedWalletSetupOnlyButton() {

    // Initiate a JSONObject as the input of renderButton() method
    val jsonObject = JSONObject()
    jsonObject.put("merchantId", "A2Y3FXLHM8H7PR")
    jsonObject.put("placement", "Cart")
    jsonObject.put("checkoutLanguage", "en_US")
    jsonObject.put("ledgerCurrency", "USD")
    jsonObject.put("productType", "PayOnly")
    jsonObject.put("sandbox", false)
    jsonObject.put("useUniversalLink", true)

    // Creating checkoutSessionConfig
    val checkoutSessionConfig = JSONObject()

    // Adding storeId
    checkoutSessionConfig.put("storeId", "amzn1.application-oa2-client.456a4c3b15d24aae96256d2f82afdd73")

    // Creating webCheckoutDetails 
    val webCheckoutDetails = JSONObject()
    webCheckoutDetails.put("checkoutResultReturnUrl", "https://www.testMerchant.com/return")
    webCheckoutDetails.put("checkoutCancelUrl", "https://www.testMerchant.com/cancel")
    webCheckoutDetails.put("checkoutErrorUrl", "https://www.testMerchant.com/error")

    // Adding webCheckoutDetails to checkoutSessionConfig
    checkoutSessionConfig.put("webCheckoutDetails", webCheckoutDetails)

    // Creating scopes array
    val scopesArray = JSONArray()
    scopesArray.put("name")
    scopesArray.put("email")
    scopesArray.put("phoneNumber")
    scopesArray.put("billingAddress")

    // Adding scopes to checkoutSessionConfig
    checkoutSessionConfig.put("scopes", scopesArray)

    // Creating paymentDetails object
    val paymentDetails = JSONObject()
    paymentDetails.put("paymentIntent", "Confirm")
    paymentDetails.put("canHandlePendingAuthorization", false)

    // Adding paymentDetails to checkoutSessionConfig
    checkoutSessionConfig.put("paymentDetails", paymentDetails)
    
    //Creating PMOF fields
    checkoutSessionConfig.put("chargePermissionType", "PaymentMethodOnFile")
    
    val paymentMethodOnFileMetadata = JSONObject()
    paymentMethodOnFileMetadata.put("setupOnly", true)

    checkoutSessionConfig.put("paymentMethodOnFileMetadata", paymentMethodOnFileMetadata)

    // Adding checkoutSessionConfig to main jsonObject
    jsonObject.put("checkoutSessionConfig", checkoutSessionConfig)

    // Pass jsonObject as the input, and call RenderButton method
    AmazonPayButton.RenderButton(config = jsonObject)
}
3.2 Render your Own Button & call InitCheckout method

You can create your own Amazon Pay button by downloading the official Amazon Pay logo.

This section provides the steps for downloading the official Pay with Amazon button label and pairing it with an Android button.

1. Download Amazon Pay button labels.

Name
Usage
Download-Link
Primary label
Default label
svg
Secondary label
Use on dark background only
svg

2. Go to the directory app > res > drawable, and then click New > Vector Asset.

3. Add the svg files you downloaded.

4. To give your button an ID, do the following:

In the button’s XML declaration, set the android:id attribute to @+id/apayButton. The Amazon Pay button is available in three variations: gold, squidInk and white. Configure the logo and background accordingly.

- gold button
  - Set android:drawableLeft="@drawable/squid_ink_pwa" and android:background="@drawable/apay_button_background_gold"/>
- squidInk button
  - Set android:drawableLeft="@drawable/white_pwa" and android:background="@drawable/apay_button_background_dark"/>
- white button
  - Set android:drawableLeft="@drawable/squid_ink_pwa" and android:background="@drawable/apay_button_background_light"/>

The following code sample shows how to create an Amazon Pay button with customizable backgrounds in an Android app.

<!--Declare button xml in app/res/layout/activity_main.xml-->
<Button android:id="@+id/apayButton"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:drawableLeft="@drawable/squid_ink_pwa"
        android:paddingLeft="55dp"
        android:paddingTop="17dp"
        android:paddingBottom="12dp"
        android:paddingRight="55dp"
        android:gravity="center"
        android:background="@drawable/apay_button_background_gold"/>
<!--Declare background xml in app/res/drawable/apay_button_background_light.xml-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="4dp" />
    <stroke android:width="1.5dp" android:color="#232F3E" />
    <solid android:color="#FFFFFF" />
</shape>
<!--Declare background xml in app/res/drawable/apay_button_background_dark.xml-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="4dp" />
    <stroke android:width="1.5dp" android:color="#232F3E" />
    <solid android:color="#232F3E" />
</shape>
<!--Declare background xml in app/res/drawable/apay_button_background_gold.xml-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="4dp" />
    <stroke android:width="1.5dp" android:color="#FFD814" />
    <solid android:color="#FFD814" />
</shape>

4. After initializing the Amazon Pay button in the layout XML, you can reference it in your MainActivity and attach an OnClickListener. Following code sample shows how to use the OnClickListener.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.apayButton).apply {
          setOnClickListener { onButtonClicked() }
        }
    }
}

5. Load your app and make sure the button shows the text “Pay with Amazon”. Confirm the button renders correctly across all supported screen densities. For guidance on handling multiple screen densities on Android, refer to the Supporting Multiple Screens” topic’s Alternative Layouts in the "Supporting Multiple Screens" topic on developer.android.com.

Inside the button’s click listener, call AmazonPayButton.initCheckout(). The method requires 2 parameters: context and jsonObject.

The following code sample shows how to call the initCheckout method for the Saved Wallet Setup Only flow.

@Composable
fun InitCheckoutSavedWalletSetupOnlyFlowButton() {
    val jsonObject = JSONObject()
    jsonObject.put("merchantId", "A3LVSV45M75151")
    jsonObject.put("placement", "Cart")
    jsonObject.put("checkoutLanguage", "en_US")
    jsonObject.put("ledgerCurrency", "USD")
    jsonObject.put("productType", "PayOnly")
    jsonObject.put("sandbox", false)
    jsonObject.put("useUniversalLink", true)
    jsonObject.put("buttonColor", "GOLD")

    val checkoutSessionConfig = JSONObject()

    // Adding storeId
    checkoutSessionConfig.put("storeId", "amzn1.application-oa2-client.e091e1fe6fdc498886a1e654170c1af5")

    // Creating webCheckoutDetails
    val webCheckoutDetails = JSONObject()
    webCheckoutDetails.put("checkoutResultReturnUrl", "https://www.testMerchant.com/return")
    webCheckoutDetails.put("checkoutCancelUrl", "https://www.testMerchant.com/cancel")
    webCheckoutDetails.put("checkoutErrorUrl", "https://www.testMerchant.com/error")

    // Adding webCheckoutDetails to checkoutSessionConfig
    checkoutSessionConfig.put("webCheckoutDetails", webCheckoutDetails)

    // Creating scopes array
    val scopesArray = JSONArray()
    scopesArray.put("name")
    scopesArray.put("email")
    scopesArray.put("phoneNumber")
    scopesArray.put("billingAddress")

    // Adding scopes to checkoutSessionConfig
    checkoutSessionConfig.put("scopes", scopesArray)

    // Creating paymentDetails object
    val paymentDetails = JSONObject()
    paymentDetails.put("paymentIntent", "Confirm")
    paymentDetails.put("canHandlePendingAuthorization", false)

    // Adding paymentDetails to checkoutSessionConfig
    checkoutSessionConfig.put("paymentDetails", paymentDetails)

    // Creating PMOF fields
    checkoutSessionConfig.put("chargePermissionType", "PaymentMethodOnFile")

    val paymentMethodOnFileMetadata = JSONObject()
    paymentMethodOnFileMetadata.put("setupOnly", true)

    checkoutSessionConfig.put("paymentMethodOnFileMetadata", paymentMethodOnFileMetadata)

    // Adding checkoutSessionConfig to main jsonObject
    jsonObject.put("checkoutSessionConfig", checkoutSessionConfig)

    val context = LocalContext.current
    Button(
        onClick = {
            AmazonPayButton.initCheckout(context = context as AppCompatActivity, config = jsonObject)
        },
        modifier = Modifier
            .size(300f.dp, 70f.dp),
        colors = ButtonDefaults.buttonColors(Color.Magenta)) {
        Text(text = "Customized AmazonPay Button")
    }
}

IOS

1. Add the Amazon Pay SDK library to your iOS project

1.In Xcode, navigate to the Build Phase Tab.

2.Expand Link Binary with Libraries, and then click the + icon.

3.Select Add files, and then add the downloaded framework file.

4.Go to the general tab and scroll down to the Frameworks, Libraries and Embedded Content section.

5.Select Embed and Sign from the dropdown.

2. Add dependencies

To invoke the API, ensure the library is correctly imported: - import AmazonPayIosMSDKLib

3. Render the Amazon Pay button

To render the button, you have 2 options:

  1. Invoke renderButton to display a Composable Amazon Pay button.
  2. Create your button and call initCheckout when clicked.
3.1 Call renderButton method

The renderButton method accepts a multiline string literal as input and returns a UIbutton. You can trigger one of the 5 supported flows by following these parameters.

Here is an example of creating a Composable Amazon Pay button with the Saved Wallet Setup Only by calling the renderButton method:

import UIKit
import AmazonPayIosMSDKLib

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        config=""" 
        {  
           "merchantId": "A2Y3FXLHM8H7PR",  
           "placement": "Cart",  
           "checkoutLanguage": "en_US",  
           "ledgerCurrency": "USD",  
           "productType": "PayOnly",  
           "sandbox": false,  
           "useUniversalLink": true,  
           "checkoutSessionConfig": 
           {  
               "storeId": "amzn1.application-oa2-client.456a4c3b15d24aae96256d2f82afdd73",  
               "webCheckoutDetails": 
               {  
                   "checkoutResultReturnUrl": "https://www.testMerchant.com/return",  
                   "checkoutCancelUrl": "https://www.testMerchant.com/cancel",  
                   "checkoutErrorUrl": "https://www.testMerchant.com/error"
               },  
               "scopes": [  "name",  "email",  "phoneNumber",  "billingAddress"  ],  
               "paymentDetails": 
               {  
                   "paymentIntent": "Confirm",  
                   "canHandlePendingAuthorization": false
               }, 
               "chargePermissionType": "PaymentMethodOnFile",
               "paymentMethodOnFileMetaData": {
                   "setupOnly":true
               }
           } 
        } 
        """
        ButtonRenderer.renderButton(config: config)
}

Render your Own Button & call InitCheckout method

You can create your own Amazon Pay button by downloading the official Amazon Pay logo.

This section provides the steps for downloading the official Pay with Amazon button label and pairing it with an iOS button.

1. Download Amazon Pay button labels.

Name
Usage
Download-Link
Primary label
Default label
svg
Secondary label
Use on dark background only
svg

2. Add a custom UIButton. The Amazon Pay button is available in three variations: gold, squidInk and white. 3. Configure the required color as a parameter to applyApayButtonStyle. 4. Add the TouchUpInside event for the button to a method named onButtonClicked. Leave the implementation empty for now.

The following code sample shows how to create an Amazon Pay button with customizable backgrounds in an iOS app.

import UIKit

extension UIButton {

    //Styling extension for Amazon Pay Button
    func applyApayButtonStyle(buttonColor: String, x: Int, y: Int) {
        struct apayColorScheme {
            static var white: UIColor {return UIColor(red:1,green:1,blue:1,alpha:1)}
            static var squidInk: UIColor {return  UIColor(red:35/255,green:47/255,blue:62/255,alpha:1)}
            static var gold: UIColor {return UIColor(red:1,green:216/255,blue:20/255,alpha:1)}
        }
        switch buttonColor {
                case "white": 
                self.backgroundColor = apayColorScheme.white
                self.layer.borderColor = apayColorScheme.squidInk.cgColor
                    self.setImage(UIImage(named: "squid_ink_pwa"), for: .normal)
                case "squidInk":
                    self.backgroundColor = apayColorScheme.squidInk
                    self.layer.borderColor = apayColorScheme.squidInk.cgColor
                    self.setImage(UIImage(named: "white_pwa"), for: .normal)
                case "gold": fallthrough
                default:
                self.backgroundColor = apayColorScheme.gold
                    self.layer.borderColor = apayColorScheme.gold.cgColor
                    self.setImage(UIImage(named: "squid_ink_pwa"), for: .normal)
        }
        
        self.layer.borderWidth = 1.5
        self.imageView?.contentMode = .scaleAspectFit
        self.imageEdgeInsets = UIEdgeInsets(top: 12, left: 8, bottom: 8, right: 8)
        self.layer.cornerRadius = 4
        self.layer.masksToBounds = true
        self.frame = CGRect(x: x, y: y, width: 200, height: 40)
        self.tintColor = .clear
    }
}
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let button = UIButton(type: .custom)
        button.applyApayButtonStyle(buttonColor: "gold")
        button.addTarget(self, action: #selector(onButtonClicked), for: .touchUpInside)
        self.view.addSubview(button)
    }
    
    @objc func onButtonClicked(_ sender: Any) {
    }
}    

Then inside onButtonClicked listener, call AmazonPay’s initCheckout method. initCheckout requires 2 inputs: context and JSONObject.

Here is an example for calling initCheckout method with Saved Wallet Setup Only flow:

@objc func onButtonClicked(_ sender: Any) {
   config=""" 
    {  
        "merchantId": "A2Y3FXLHM8H7PR",  
        "placement": "Cart",  
        "checkoutLanguage": "en_US",  
        "ledgerCurrency": "USD",  
        "productType": "PayOnly",  
        "sandbox": false,  
        "useUniversalLink": true,  
        "checkoutSessionConfig": 
        {  
            "storeId": "amzn1.application-oa2-client.456a4c3b15d24aae96256d2f82afdd73",  
            "webCheckoutDetails": 
            {  
                "checkoutResultReturnUrl": "https://www.testMerchant.com/return",  
                "checkoutCancelUrl": "https://www.testMerchant.com/cancel",  
                "checkoutErrorUrl": "https://www.testMerchant.com/error"
            },  
            "scopes": [  "name",  "email",  "phoneNumber",  "billingAddress"  ],  
            "paymentDetails": 
            {  
                "paymentIntent": "Confirm",  
                "canHandlePendingAuthorization": false
            },
            "chargePermissionType": "PaymentMethodOnFile",
            "paymentMethodOnFileMetaData": {
                "setupOnly":true
            }
        } 
    } 
    """
    ButtonRenderer.initCheckout(context: self, config: config)
 } 

Button render parameters

Parameter
Description
merchantId
(required)

Type: string
Amazon Payments merchant account identifier
createCheckoutSessionConfig
(required)

Type: buttonConfig
Checkout Session configuration
Note : This is a required field if you use PayAndShip or PayOnly productType
placement
(required)

Type: string
Amazon Pay button placement 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 corresponding Merchant ID

Supported values:
  • 'USD' - US merchants
  • 'EUR' - EU merchants
  • 'GBP' - UK merchants
  • 'JPY' - JP merchants
estimatedOrderAmount

Type: price
Estimated checkout order amount. It doesn’t match the final order amount if the buyer updates their order after starting checkout. Amazon Pay uses this value to assess transaction risk and prevent buyers from selecting incompatible payment methods for the order
productType

Type: string
Product type selected for checkout

Supported values:
  • PayAndShip
  • PayOnly
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

Supported values: 
  • 'en_US' - US merchants
  • 'en_GB', 'de_DE', 'fr_FR', 'it_IT', 'es_ES' - EU/UK merchants
  • 'ja_JP' - JP merchants
sandbox

Type: boolean
Sets button to Sandbox environment

Function that sets button to Sandbox environment

Default value: false
buttonLength

Type: integer
Amazon Pay button length value in pixels

Default value: 40
buttonWidth

Type: integer
The width value of AmazonPay button in px

Default value: 200
useUniversalLink

Type: boolean
Setting determining if MSDK redirects buyer from merchant’s App to the Amazon app for checkout when the Amazon app is installed

Default value: true

CheckoutSessionConfig Fields

Name Location Description
storeId
(required)

Type: string
Body Amazon Pay store ID. Retrieve this value from Integration Central: US, EU, JP
webCheckoutDetails

Type: webCheckoutDetails
Body URLs associated with the Checkout Session used to complete checkout.
Note: URLs must use HTTPS protocol and be configured as Universal links in iOS, or App links in Android.
Use checkoutMode to specify whether the buyer completes checkout on the Amazon Pay hosted page immediately after clicking the Amazon Pay button.
paymentDetails

Type: paymentDetails
Body Payment details specified by the merchant, such as order amount and method for charging the buyer.
addressDetails

Type: addressDetails
Body Shipping address provided by the buyer.
Note: Only use this parameter if checkoutMode is ProcessOrder and productType is PayAndShip.
scopes

Type: list<string>
Body Buyer details you're requesting access to. Specify whether you need shipping address using the productType parameter. Supported values:
  • 'name' - Buyer name
  • 'email' - Buyer email
  • 'phoneNumber' - Buyer phone number. You must also request billingAddress scope or use payAndShip productType to retrieve the billing address or shipping address phone number.
  • 'billingAddress' - Default billing address
  • 'shippingAddress' - Default shipping address
Note: You must also request billingAddress scope or use payAndShip productType to retrieve the billing address or shipping address phone number.
Default value: All buyer information (except billing address) is requested if the scopes parameter is not set.
chargePermissionType

Type: string
Body Type of charge permission requested
Supported values:
  • 'OneTime' - The Charge Permission can only be used for a single order
  • 'Recurring' - Charge permission can be used for recurring orders.
Default value: 'OneTime'
deliverySpecifications

Type: deliverySpecifications
Body Shipping restrictions to prevent buyers from selecting unsupported addresses from their Amazon address book.
merchantMetadata

Type: merchantMetadata
Body Order details provided by the merchant.

Type: webCheckoutDetails

Parameter Description
checkoutResultReturnUrl

Type: string
This value must be a Universal link or App link with the merchant domain. It’s triggered after the buyer pays for the order.
checkoutCancelUrl

Type: string
This value must be a Universal link or App link with the merchant domain. It’s triggered after the buyer cancels the checkout flow (where the onCancel() callback is triggered in the Falcon web flow).
checkoutErrorUrl

Type: string
This value must be a Universal link or App link with the merchant domain. It’s triggered after the buyer clicks Cancel and redirects to a merchant error page.
checkoutMode

Type: string
This value must be ProcessOrder.

Type: paymentDetails

Parameter Description Required fields based on type of integration
OneTime Saved Wallet
(Setup and Pay)
Saved Wallet
(Setup Only)
Saved Wallet
(Update Only)
Saved Wallet
(Sign In and Setup)
paymentIntent

Type: string
Payment flow for charging the buyer

Supported values:
  • 'Confirm' - Create a Charge Permission to authorize and capture funds at a later time
  • 'Authorize' - Authorize funds immediately and capture at a later time
  • 'AuthorizeWithCapture' - Authorize and capture funds immediately. If you use this `paymentIntent` you can't set `canHandlePendingAuthorization` to true
required required must be `Confirm` must be `Confirm` must be null
canHandlePendingAuthorization

Type: boolean
Boolean that indicates whether merchant can handle pending response

If set to true:
  • One-time checkout: Dynamic authorization is enabled. The Charge will either be in an "Authorized", "Declined", or "AuthorizationInitiated" state. If the Charge is in an "AuthorizationInitiated" state, Amazon Pay will process the authorization asynchronously and you will receive authorization results within 24 hours. See asynchronous processing and Charge states for more info
  • Recurring checkout: Amazon Pay will process the authorization asynchronously and you will receive authorization results within 24 hours. See asynchronous processing for more info

required required required required must be null