AMSPaymentElement.Builder
Note: Translation in progress.
AMSPaymentElement.Builder 是一个构建器类,用于逐步配置并最终创建 AMSPaymentElement 实例。通过其构造函数传入必要的参数后,必须调用 build() 方法在主线程中完成实例的构建。
构造
Java
Kotlin
copy
new AMSPaymentElement.Builder(Activity activity, AMSBaseConfiguration configuration)参数
创建 AMSPaymentElement.Builder 实例时,需要传入以下参数。
参数 | 类型 | 是否必需 | 描述 |
activity | Activity | 是 | 当前 Activity 上下文。 |
configuration | AMSBaseConfiguration | 是 |
|
返回值
返回 AMSPaymentElement.Builder 实例,用于继续配置并构建 AMSPaymentElement 对象。
build()
在完成 Builder 初始化后,调用 build() 构建 AMSPaymentElement 实例。
方法签名
Java
Kotlin
copy
public AMSPaymentElement build()参数
此方法无入参。
返回值
返回已构建的 AMSPaymentElement 实例。该实例包含以下主要方法:
注意:若 configuration 为
null则返回null。如果未在主线程调用,则将抛出 RuntimeException。
| 方法名 | 描述 |
preload() | 用于预加载 WebApp 页面和 KYC 页面资源。 |
createComponent() | 用于创建并展示支付组件 UI。该方法与 |
confirmPayment() | 用于针对当前组件实例提交并确认已存卡支付。该方法与 |
reset() | 用于重置支付流程,清除当前状态。 |
用于销毁实例并释放所有关联资源。 |
示例
copy
AMSBaseConfiguration configuration = new AMSBaseConfiguration();
configuration.setLocale(new Locale("en", "US"));
configuration.setOption("sandbox", true);
AMSPaymentElement paymentElement = new AMSPaymentElement.Builder(activity, configuration).build();