AMSElement
Use the AMSElement class to create a Payment Element instance on the frontend page. When creating the instance, you need to pass configuration information, including the environment, language, and payment session data (paymentSessionData) obtained from the server. The instance can be used to embed payment components, initiate payments, and other operations.
Method signature
When calling this method, please use the following standard method signature format.
new AMSElement(options: IElementOptions)Parameters
Parameter | Data type | Required | Description |
environment | String | No | It is used to pass in environmental information. Valid values are:
|
locale | String | No | It is used to pass in language information. You can choose the value to pass based on the region of the payment method. Valid values are:
|
sessionData | String | Yes | Payment session data. Use this parameter to create the configuration object: Pass the full paymentSessionData parameter obtained from the createPaymentSession (One-time Payments) API response to this parameter. |
Sample
CDN
// Get the browser language
let language = navigator.language || navigator.userLanguage;
language = language.replace("-", "_"); // Replace "-" with "_"
// Create Payment Element instance
const elementPayment = new window.AMSElement({
environment: "sandbox",
locale: "en_US",
sessionData:sessionData
})npm
import { AMSElement, ThemeType, PaymentElementLayout } from '@alipay/ams-checkout' // Package management
// Get the browser language
let language = navigator.language || navigator.userLanguage;
language = language.replace("-", "_"); // Replace "-" with "_"
// Create Payment Element instance
const elementPayment = new AMSElement({
environment: "sandbox",
locale: "en_US",
sessionData:sessionData
})