# Overview

> Antom SDK provides secure and reliable cross-platform payment capabilities, helping developers quickly integrate payment processes into Android applications. This topic introduces how to integrate the Android SDK package through Maven and manual methods and provides the essential steps for rapidly using the SDK package.

 Antom SDK provides secure and reliable cross-platform payment capabilities, helping developers quickly integrate payment processes into Android applications. This topic introduces how to integrate the Android SDK package through Maven and manual methods and provides the essential steps for rapidly using the SDK package.

## Integration preparations {#mKMme}

 Before beginning the integration, ensure that you have completed the following environment preparations:

 - Android Studio latest version is installed.
- The target runtime environment must be API level 26 or higher.
- Use Gradle 4.1 or higher version.
- Configure a physical device or emulator to run your application.

## Getting started {#wrRoP}

### Step 1: Integrate the SDK package {#gyciq}

<!-- ToggleTab query="platform" -->

**Tab: Maven integration**

Follow the steps to integrate the SDK package via Maven.

#### 1\. Add Maven repository {#JZp9X}

 Add the following code configuration in the     *build.gradle*      file in the project root directory:

 ```groovy
allprojects {
    repositories {
        maven{
            credentials{
                username "antomsdk@aliyun.com"
                password "Admin1234"
            }
            url "https://globaltech.alipay.com/api/v1/file/repository/antom/"
        }
        // other repositories
        // -------
    }
}
```

#### 2\. Add Maven dependency {#GeDiC}

 Before adding Maven dependencies, please choose the appropriate integration form according to your business requirements.

<!-- TabGroup -->

**Tab: Modular integration**

1. Follow the steps below to add the base library Maven dependency:

   1. Use the following code to add the dependency in the     *build.gradle*     file.

 ```groovy
// Add in the app's build.gradle
//  If there are conflicts with existing SDKs, exclude them
dependencies {
    implementation 'com.alipay.antom.sdk:foundation:${antom_version}'
}
```

   2. Replace the value of   `ANTOM_VERSION`   in the code below with   [the latest version number](https://docs.antom.com/ac/sdks/sdk_release_note.md?platform=android)  to externalize the version number in the     *build.gradle*     file for code upgrade management.

 ```groovy
ext {
    antom_version = 'ANTOM_VERSION'
}
```

 2. Follow the steps below to add the corresponding product's Maven dependencies:

   1. Use the following code to add dependencies in the _build.gradle_ file. The sample code includes all payment products. Please add dependencies according to your product needs.

 ```groovy
// Add in the app's build.gradle
// If there are conflicts with existing SDKs, exclude them
dependencies {
    // Payment Element product dependency
    implementation 'com.alipay.antom.sdk:element:${antom_version}'

    // If you need to integrate Google Pay plugin through Payment Element, also add the following dependency
    // If using base SDK version 2.1.0+ (including 2.1.0), Google Pay plugin must use version 2.1.0. If using base SDK version below 2.0.0, Google Pay plugin must use version 1.0.0.
    implementation 'com.alipay.antom.sdk:${antom_version}'

    // EasySafePay payment product dependency
    implementation 'com.alipay.antom.sdk:easy-safe-pay:${antom_version}'

    // Tokenized payment product dependency (for ACH Direct Debit integration)
    implementation 'com.alipay.antom.sdk:auto-debit-pay:${antom_version}'
}
```

 > **[INFO]** **Note**    : When integrating Alipay under EasySafePay, you also need to manually import the AlipaySDK aar package (please contact the Antom technical team to obtain the aar package):  `implementation(name: 'alipaysdk-android-15.8.35', ext: 'aar')`  。

   2. Replace the value of  `ANTOM_VERSION`  in the code below with   [the latest version number](https://docs.antom.com/ac/sdks/sdk_release_note.md?platform=android)  .

 ```groovy
ext {
    antom_version = 'ANTOM_VERSION'
}
```

**Tab: Full integration**

1. To integrate the SDK for all products, please directly add the following dependency:

 ```groovy
// Add in the app's build.gradle
//  If there are conflicts with existing SDKs, exclude them
dependencies {
    implementation 'com.alipay.antom.sdk:all:${antom_version}'
}
```

 2. Replace the value of   `ANTOM_VERSION`   in the code below with  [the latest version number](https://docs.antom.com/ac/sdks/sdk_release_note.md?platform=android)  to externalize the version number in the     *build.gradle*     file for code upgrade management.

 ```groovy
ext {
    antom_version = 'ANTOM_VERSION'
}
```

<!-- /TabGroup -->

#### (Optional) 3. Integrate security extension package {#WK6tC}

 To reduce additional security challenges during the payment process, Antom provides you with an SDK security extension package. Follow the steps below to integrate the security extension package:

 > **[INFO]** **Note**: If you are integrating [EasySafePay](https://docs.antom.com/ac/easypay/overview.md), ensure that you install this security extension package.

 1. Use the following code to add the Maven dependency in the _build.gradle_ file.

 ```groovy
dependencies {
	implementation "com.alipay.antom.sdk:securitysdk:1.2.0"
}
```

 2. After integrating the security extension package, you need to complete the following Apache HttpClient configuration:
1. Declare the use of the _org.apache.http.legacy_ library in the _build.gradle_ configuration file in the project root directory.

 ```groovy
android {
    useLibrary 'org.apache.http.legacy' // Support HttpClient
    ......
        }
```

   2. Declare the use of the _org.apache.http.legacy_ library in the manifest file _AndroidManifest.xml._

 ```xml
<application>
  <uses-library android:name="org.apache.http.legacy" android:required="false"/>
</application>
```

 3. Add the [fastjson](https://github.com/alibaba/fastjson/wiki) parsing library in the _build.gradle_ file:

 ```groovy
dependencies {
    implementation 'com.alibaba:fastjson:1.1.70.android'
}
```

**Tab: Manual integration**

If you are not using Maven integration, you can follow the manual integration method provided by Antom:

 1. Contact Antom technical support to obtain the     *.aar*     file for the corresponding product..
2. Place the extracted     *.aar*     compilation file into the _libs_ folder under the current project application.
3. Declare the reference dependency of the _.aar_ compilation file in the _build.gradle_ file in the project root directory.

 ```groovy
dependencies {
    // Configure SDK aar package. Ensure integration of all resource packages for the corresponding product.
    implementation(name: 'ams-foundation-release-xxxxx', ext: 'aar')

    // Configure EasySafePay package.
    implementation(name: 'ams-easysafepay-release-xxxxx', ext: 'aar')

    // For integrating Alipay under the EasySafePay product, additional configuration of the AlipaySDK aar package is required
    implementation(name: 'alipaysdk-android-15.8.35', ext: 'aar')
}
```

#### (Optional) Manual integration of Google Pay {#Ikla8}

 To manually integrate the Google Pay payment method in Payment Element, you need to manually add the following dependencies to the project's     *build.gradle*     file to ensure that the relevant resources can be referenced correctly:

 ```groovy
dependencies {
    // 18.1.3 is the version number depended by the Antom Google Pay plugin. For the latest version, please refer to the Play Services Wallet Maven repository: https://mvnrepository.com/artifact/com.google.android.gms/play-services-wallet
    implementation 'com.google.android.gms:play-services-wallet:18.1.3'
}
```

<!-- /ToggleTab -->

### (Optional) Step 2: Preload the SDK  **[Client-side]** {#caoWK}

 Before creating a payment session or vaulting session, it is strongly recommended that you preload the SDK to improve the rendering speed of the checkout page and reduce the waiting time for buyers during the payment process. Perform the preload operation according to the following code example:

 > **[INFO]** **Note**    : According to your business requirements, replace {ClassName} in the following sample code with the corresponding class name, for example,   `AMSPaymentElement`  .

 ```java
{ClassName}.preload(getApplicationContext());
```

### Step 3: Create a session  **[Server-side]** {#nlnfw}

 According to the business scenario, pass in the order information to call the corresponding API to create a payment session or vaulting session, and obtain the _paymentSessionData_ or _vaultingSessionData_ to invoke the SDK:

 - Payment Element: Call the   [**createPaymentSession (One-time Payments)**](https://docs.antom.com/ac/ams/session_cashier.md)   API to create a payment session.
- Vaulting Element: Call the **[createVaultingSession](https://docs.antom.com/ac/ams/vaulting_session.md)** API to create a vaulting session.
- EasySafePay: Call the   [**createPaymentSession (EasySafePay)**](https://docs.antom.com/ac/ams/createpaymentsession_easypay.md)   API to create a payment session.

## Next steps {#OkNgC}

 After completing the SDK integration, you can use the SDK in your desired payment scenarios. For specific operations, refer to the corresponding integration guides:

 - [Payment Element integration guide](https://docs.antom.com/ac/cashierpay/element.md)
- Vaulting Element integration guide
- [EasySafePay integration guide](https://docs.antom.com/ac/easypay/integration_guide.md)

### Upgrade notes {#TJyFG}

 Antom SDK has been upgraded from 1.x.x to 2.x.x. The 2.x.x version supports modular integration. When upgrading from older versions, take note of the following:

<!-- TabGroup -->

**Tab: Upgrade from version 2.x.x**

If you have integrated the full 2.0 SDK package and wish to switch to modular integration, you can integrate according to the following code by product:  
 ```groovy
dependencies {
    // Delete the following codes
    implementation 'com.alipay.antom.sdk:all:${antom_version}'
    // Add the following codes
    implementation 'com.alipay.antom.sdk:foundation:${antom_version}'
    implementation 'com.alipay.antom.sdk:element:${antom_version}'

}
```

**Tab: Upgrade from version 1.x.x**

- If you have integrated the 1.0 Component SDK and are using one or more products including checkout or card binding, modular integration upgrade is not supported in this case. Please perform a full integration upgrade according to the following code.

 ```groovy
dependencies {
    // Delete the following codes
    implementation 'com.alipay.antom.sdk:payment-component:${antom_version}'
    // Add the following codes
    implementation 'com.alipay.antom.sdk:all:${antom_version}'
  
}
```

 - If you are using one or more products including [EasySafePay](https://docs.antom.com/ac/easypay/overview.md), [Payment Element](https://docs.antom.com/ac/cashierpay/element.md?platform=android) or [Tokenized Payment](https://docs.antom.com/ac/tokenized/overview.md), you can choose to use modular integration or full integration to complete the upgrade based on your requirements for the SDK package size:

<!-- TabGroup -->

**Tab: Modular integration**

If you use modular integration, integrate according to the product-specific code examples below:  
 ```groovy
dependencies {
    // Delete the following codes
    implementation 'com.alipay.antom.sdk:payment-component:${antom_version}'
    // Add the following codes
    implementation 'com.alipay.antom.sdk:foundation:${antom_version}'
    implementation 'com.alipay.antom.sdk:element:${antom_version}'

}
```

**Tab: Full integration**

If you are not sensitive to the SDK package size, you can perform a full integration upgrade according to the following code:

 ```groovy
dependencies {
    // Delete the following codes
    implementation 'com.alipay.antom.sdk:payment-component:${antom_version}'
    // Add the following codes
    implementation 'com.alipay.antom.sdk:all:${antom_version}'
  
}
```

<!-- /TabGroup -->

<!-- /TabGroup -->
