loadAntom()
loadAntom() is the entry function for loading an Antom SDK instance. By accepting configuration parameters, it asynchronously loads and returns the Antom instance, which is used for subsequent operations such as creating Elements, updating configuration parameters, initiating payments, or binding payment methods.
Note:
- The SDK uses a singleton pattern internally. Multiple calls to loadAntom() will return the same instance.
- loadAntom() is an asynchronous function. You must use await or .then() to retrieve the instance.
- When using the npm package, if script loading fails due to network issues, the method will return reject. It is recommended to check your network connection and refresh the page, or directly visit the corresponding CDN link to verify if the resource is accessible.
Method signature
When calling this method, please use the following standard method signature format:
JavaScript
loadAntom(config);TypeScript
loadAntom(config: LoadAntomConfig): Promise<antom>Parameters
This method accepts a configuration object that is used to initialize the SDK’s runtime environment and core behavior.
Parameter | Type | Required | Description |
|---|---|---|---|
| config | Object | No | SDK configuration object, which is used to set the environment, language, and debugging mode. |
config
Parameter | Type | Required | Description |
|---|---|---|---|
| env | String | No | Environment configuration options. Valid values are:
|
| environment | String | No | The alias for env. If both are set, the value of env takes precedence. Valid values are:
Note: The env and environment parameters serve the same function; it is recommended to use the env parameter consistently. |
| debug | Boolean | No | Used to enable debug mode. Enabling it will output detailed logs, making it easier for developers to troubleshoot issues. Valid values are:
|
| locale | String | No | Used to set the internal display language for the SDK (such as error messages and prompts). Valid values are:
Note: If the parameter is omitted or contains an unsupported value, the system will default to English. |
Object | No | Preload Element resources that may be used later. This capability is only for performance optimization and does not change the Element usage workflow. For details, see Best practices. |
preload
Parameter | Type | Required | Description |
|---|---|---|---|
elements | Array | No | The types of Element resources to be preloaded. Valid values are:
|
Return values
This method returns a Promise object, which resolves to an antom instance that provides the following main methods:
Function | Description |
|---|---|
| antom.createElement() | |
| antom.confirmPayment() | Initiate payment confirmation for saved card scenarios. |
| antom.confirmCardSetup() | Confirm card information for card binding scenarios. |
| antom.updateConfig() | Update SDK configuration parameters. |
Destroy the antom instance and free up all related resources. |
Best practices
When to use preload
- It is recommended to configure and use preload as early as possible before the user starts the flow, so resources can be loaded in advance and payment page loading performance can be optimized.
- Only preload the Element resources that may be used later to optimize loading performance. Do not preload all resources, to avoid unnecessary resource consumption.
Execution and failure behavior
- The Promise returned by loadAntom() only indicates that the Antom SDK is available; it does not mean that all preloaded resources have finished loading.
- SDK loading, Element resource preloading, and network connection prewarming may run in parallel.
- If preloading fails or is skipped due to network conditions, it will automatically degrade gracefully and will not affect subsequent calls to antom.createElement() or element.mount().
- Preloading depends on the browser environment and cannot be executed during server-side rendering.
Sample
CDN
const antom = await window.loadAntom();When introducing SDK through CDN, it is recommended to add CDN link of the latest antom sdk in the page. If the project is Typescript used, @ alipay/ams-checkout/antom can be added to compilerOptions.types in the tsconfig to get typescript input prompt when writing code. The following is a sample configuration:
{
"compilerOptions": {
"types": ["@alipay/ams-checkout/antom"]
}
}npm
import { loadAntom } from "@alipay/ams-checkout";
// Load the production environment SDK
const antom = await loadAntom();