Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

APM payments (Android)

The Antom SDK is a pre-built UI component that simplifies the process of integrating Antom payment services. This component offers a simple and quick way to integrate all payment methods supported by Antom, including credit cards, digital wallets, bank transfers, online banking, and more.

The SDK component can automatically adapt to the buyer's device and location, performing tasks such as information collection, redirection, switching between apps, displaying QR codes, and more based on the characteristics of the payment method. You can easily provide a comprehensive payment solution on your website or application, saving a significant amount of time and resources required to build each payment interface and process.

User experience

The following figures show the user journey of paying on an App:

image.png

Note: If you want to provide buyers with an Alipay+ unified payment experience instead of the above user experience, see Alipay+ unified payment cashier and contact Antom technical support for more integration details.

Payment flow

For each payment method, the payment flow is composed of the following steps:

333.webp

  1. The buyer lands on the checkout page.
  1. Create the createPaymentSession request
    After the buyer selects a payment method and submits the order, you can obtain the payment session by calling the createPaymentSession interface.
  2. Invoke the client SDK
    On the client side, invoke the SDK through the payment session. The SDK will handle information collection, redirection, app invocation, QR code display, verification, and other processes based on the payment method's characteristics.
  3. Get the payment result
    Obtain the payment result by using one of the following two methods:
    • Asynchronous Notification: Specify the paymentNotifyUrl in the createPaymentSession interface to set the address for receiving asynchronous notifications. When the payment is successful or expires, Antom will use notifyPayment to send asynchronous notifications to you.
    • Synchronous Inquiry: Call the inquiryPayment interface to check the payment status.

Integration steps

Start your integration by taking the following steps:

  1. Create a payment session
  2. Create and invoke the SDK
  3. Obtain payment result

Step 1: Create a payment session Server-side

When a buyer selects a payment method provided by Antom, you need to collect key information such as the payment request ID, order amount, payment method, order description, payment redirect URL, and payment result notification URL, call the createPaymentSession API to create a payment session, and return the payment session to the client.

Antom provides server-side API libraries for multiple languages. The following codes use Java as an example. You need to install Java 6 or higher.

Install an API library

You can find the latest version on GitHub.

copy
<dependency>
<groupId>com.alipay.global.sdk</groupId>
<artifactId>global-open-sdk-java</artifactId>
<version>2.0.21</version>
</dependency>

Initialize request instance

Create a singleton resource to make a request to Antom.

copy
String merchantPrivateKey = "YOUR PRIVATE KEY";
String alipayPublicKey = "ALIPAY PUBLIC KEY"
AlipayClient defaultAlipayClient = new DefaultAlipayClient(EndPointConstants.SG,
                                                           merchantPrivateKey, alipayPublicKey);

Create a payment session

Creating a payment session includes the following parameters:

Parameter name

Required

Description

productCode

The value is fixed to CASHIER_PAYMENT.

paymentRequestId

The unique ID generated by the merchant, a new ID is required every time a payment is initiated.

paymentAmount

Payment amount, should be set according to the smallest unit of the order currency, e.g. CNY for cents, KRW for dollars.

paymentMethod

Payment method enumeration

paymentRedirectUrl

Merchant's payment result page, according to the server-side results, not a fixed success page.

order

Order information, including order amount, order ID, and order description on the merchant side.

paymentNotifyUrl

Payment result notification address, which can be passed in through the interface or set as a fixed value through the portal.

settlementStrategy

Settlement currency of the payment, if the business has signed more than one settlement currency, you need to specify it in the interface.

The above parameters are the basic parameters for creating a payment session, for full parameters and additional requirements for certain payment methods please refer to createPaymentSession (Checkout Payment).

Sample code of calling the createPaymentSession API

The following sample code shows how to call the createPaymentSession API:

copy

AlipayPaymentSessionRequest alipayPaymentSessionRequest = new AlipayPaymentSessionRequest();
alipayPaymentSessionRequest.setClientId(CLIENT_ID);
alipayPaymentSessionRequest.setPath("/ams/sandbox/api/v1/payments/createPaymentSession");
alipayPaymentSessionRequest.setProductCode(ProductCodeType.CASHIER_PAYMENT);

// replace to your paymentRequestId
alipayPaymentSessionRequest.setPaymentRequestId("paymentRequestId01");
// set amount
Amount amount = new Amount();
amount.setCurrency("MYR");
amount.setValue("4200");
alipayPaymentSessionRequest.setPaymentAmount(amount);

// set paymentMethod
PaymentMethod paymentMethod = new PaymentMethod();
paymentMethod.setPaymentMethodType("ONLINEBANKING_FPX");
alipayPaymentSessionRequest.setPaymentMethod(paymentMethod);

// set order Info
Order order = new Order();
order.setReferenceOrderId("referenceOrderId01");
order.setOrderDescription("antom sdk test order");
order.setOrderAmount(amount);
Buyer buyer = new Buyer();
buyer.setReferenceBuyerId("yourBuyerId");
order.setBuyer(buyer);
order.setOrderAmount(amount);
alipayPaymentSessionRequest.setOrder(order);

// replace to your redirect url
alipayPaymentSessionRequest.setPaymentRedirectUrl("https://www.yourMerchantWeb.com");
alipayPaymentSessionRequest.setPaymentNotifyUrl("https://www.yourNotifyUrl");

AlipayPaymentSessionResponse alipayPaymentSessionResponse = null;
try {
    alipayPaymentSessionResponse = defaultAlipayClient.execute(alipayPaymentSessionRequest);
} catch (AlipayApiException e) {
    String errorMsg = e.getMessage();
    // handle error condition
}

The following code shows a sample of the request message:

copy
{
  "paymentNotifyUrl": "https://www.yourNotifyUrl",
  "paymentRequestId": "paymentRequestId01",
  "paymentAmount": {
    "currency": "MYR",
    "value": "4200"
  },
  "productCode": "CASHIER_PAYMENT",
  "paymentRedirectUrl": "https://www.yourMerchantWeb.com",
  "paymentMethod": {
    "paymentMethodType": "ONLINEBANKING_FPX"
  },
  "order": {
    "orderAmount": {
      "currency": "MYR",
      "value": "4200"
    },
    "referenceOrderId": "referenceOrderId01",
    "orderDescription": "antom sdk test order",
    "buyer": {
      "referenceBuyerId": "yourBuyerId"
    }
  }
}

The following code shows a sample of the response, which contains the following parameters:

  • paymentSessionData: the payment session to be returned to the frontend
  • paymentSessionExpiryTime: the expiration time of the payment session.
copy
{
  "paymentSessionData": "UNvjVWnWPXJA4BgW+vfjsQj7PbOraafHY19X+6EqMz6Kvvmsdk+akdLvoShW5avHX8e8J15P8uNVEf/PcCMyXg==&&SG&&111",
  "paymentSessionExpiryTime": "2023-04-06T03:28:49Z",
  "paymentSessionId": "UNvjVWnWPXJA4BgW+vfjsQj7PbOraafHY19X+6EqMz6Ikyj9FPVUOpv+DjiIZqMe",
  "result": {
    "resultCode": "SUCCESS",
    "resultMessage": "success.",
    "resultStatus": "S"
  }
}

FAQs

Can Chinese characters be used in the request?

Do not use Chinese characters for the fields in the request including paymentRequestId, referenceOrderId, orderDescription, and goods to avoid incompatible payment methods, such as QRIS and Mastercard.

How to set the payment result notification address?

Antom will send the payment result through the notifyPayment, which you can specify in the createPaymentSession API via the paymentNotifyUrl parameter. If the address of each payment is the same, you can also configure it in the Antom Dashboard. If you have configured the address and set the parameter in the API, Antom will use the address set in the AP

Step 2: Create and invoke the SDK Client-side

The Antom SDK is a component used for handling payment processes. You initiate the SDK by creating a payment session to collect information, switch between apps, and display QR codes based on the payment method specified in createPaymentSession API.

After the buyer selects a payment method on the page, you need to create the SDK and initiate it with a payment session.

Install

Version Requirements: target at least Android 4.4 (API level 19) or higher.

To integrate the SDK package, please refer to Integrate the SDK Package.

Instantiate the SDK

Create the SDK instance by using the AMSCashierPayment and specify basic configurations. Creating a configuration object includes the following methods:

Method name

Required

Description

setLocale

It is used to pass in language information. Valid values are listed as follows. You can choose the value to pass based on the region of the payment method. If other values are passed, the local language is used by default:

  • en_US: English
  • pt_BR: Portuguese
  • ko_KR: Korean
  • es_ES: Spanish
  • ms_MY: Malay
  • in_ID: Indonesian
  • tl_PH: Tagalog
  • th_TH: Thai
  • vi_VN: Vietnamese
  • fr_FR: French
  • nl_NL: Dutch
  • it_IT: Italian
  • de_DE: German
  • zh_CN: Simplified Chinese
  • zh_HK: Traditional Chinese

setOption

It is used to specify whether to use the default loading pattern and the sandbox environment. Valid values are:

  • "sandbox", "true": Sandbox environment
  • "sandbox", "false": Production environment
  • "showLoading", "true": Use the default loading pattern.
  • "showLoading", "false": Do not use the default loading pattern.

setOnCheckoutListener

Create an instance of the OnCheckoutListener API, which is used for event handling in the subsequent process. The API includes the following method:

  • onEventCallback: Required. A callback function that monitors payment events on the checkout page, returning eventCode and eventResult.

The following sample code shows how to instantiate the SDK:

copy
AMSCashierPaymentConfiguration configuration = new AMSCashierPaymentConfiguration();
configuration.setLocale(new Locale("en", "US"));
// Specify showLoading as true (default value) to use the default loading pattern. Specify it as false to customize the loading animation based on onEventCallback.
configuration.setOption("showLoading", "true");
onfiguration.setOption("showLoading", "true");
// Set the sandbox environment. If you leave it empty, the production environment is used by default.
configuration.setOption("sandbox", "true");
// Set the callback to monitor payment events on the checkout page.
configuration.setOnCheckoutListener(new OnCheckoutListener() {
    @Override
    public void onEventCallback(String eventCode, AMSEventResult eventResult) {
        Log.e(TAG, "onEventCallback eventCode=" + eventCode + " eventResult=" + eventResult.toString());
    }
});
// Instantiate AMSCashierPayment.
AMSCashierPayment checkout = new AMSCashierPayment.Builder(activity, configuration).build();

Invoke the SDK

Call the createComponent method:

Parameter name

Required

Description

sessionData

Create a configuration object by using the sessionData parameter: Pass the complete data in the paymentSessionData parameter obtained in the response through the createpaymentSession (Checkout Payment) API to the sessionData parameter.

Call the onDestroy method to free SDK component resources in the following situations:

  • When the buyer exits the checkout page, free the component resources created in the createPaymentSession.
  • When the buyer initiates multiple payments, free the component resources created in the previous createPaymentSession.

The following sample code shows how to invoke the SDK:

copy
checkout.createComponent(activity, sessionData);

//Free SDK component resources
checkout.onDestroy();

Display payment results

You can use the payment component to handle payment methods which require a redirect (asynchronous payments), and those that do not (synchronous payments).

Redirect payment

The payment process of some payment methods needs to leave the original web page and jump to the organization's page to complete the payment, such as the payment method of online banking. In this case, the buyer is redirected to the paymentRedirectUrl that you provided in createPaymentSession API after completing the payment. You can obtain the payment result by active query and and show it to the buyer in that URL.

Non-redirect payment

For payment without redirection, the payment result will be given through the onEventCallback function. The payment result here is only for front-end display, and the final order status is subject to the server side. You need to customize the processing flow you want for each payment result through the data in the result of onEventCallback.

The following are the possible event codes of the payment result returned by onEventCallback.

Event code

Message

Solution

SDK_PAYMENT_SUCCESSFUL

Payment was successful.

Suggest redirecting buyers to the payment result page.

SDK_PAYMENT_PROCESSING

Payment was being processed.

We suggest that you check the value of paymentResultCode in the onEventCallback result data for details. Guide buyers to retry the payment based on the provided information.

SDK_PAYMENT_FAIL

Payment failed.

We suggest that you check the value of paymentResultCode in the onEventCallback result data for details. Guide buyers to retry the payment based on the provided information.

SDK_PAYMENT_CANCEL

The buyer exits the payment page without submitting the order.

The SDK can be re-invoked with a paymentSessionData within the validity period; if it has expired, the paymentSessionData needs to be re-requested.

SDK_PAYMENT_ERROR

The payment status was abnormal.

We suggest that you check the value of paymentResultCode in the onEventCallback result data for details. Guide buyers to retry the payment based on the provided information.

The following sample code shows how to process the onEventCallback:

copy
@Override
public void onEventCallback(String eventCode, AMSEventResult eventResult) {
    AlipayLog.e(TAG, "onEventCallback eventCode=" + eventCode + " eventResult=" + eventResult.toString());

    if (!TextUtils.isEmpty(eventCode)) {
        if ("SDK_PAYMENT_SUCCESSFUL".equals(eventCode)) {
            // Payment was successful. Redirect buyers to the payment result page.
        } else if ("SDK_PAYMENT_PROCESSING".equals(eventCode)) {
            // Payment was being processed. Guide buyers to retry the payment based on the provided information.
        } else if ("SDK_PAYMENT_FAIL".equals(eventCode)) {
            // Payment failed. Guide buyers to retry the payment based on the provided information.
        }else if ("SDK_PAYMENT_CANCEL".equals(eventCode)) {
            // Guide buyers to retry the payment.
        } else if ("SDK_PAYMENT_ERROR".equals(eventCode)) {
            // The payment status was abnormal. Guide buyers to retry the payment based on the provided information.
        } else if ("SDK_END_OF_LOADING".equals(eventCode)) {
            // End your custom loading animation.
        }
    }
}

Step 3: Obtain payment result Server-side

After the buyer completes the payment or the payment times out, Antom sends the corresponding payment results to you through server interactions, you can obtain the payment result by one of the following methods:

  • Receive the asynchronous notification
  • Inquire about the result

Receive the asynchronous notification

When the payment reaches a final status of success or failure, Antom sends an asynchronous notification to the paymentNotifyUrl specified in the createPaymentSession API through the notifyPayment API. When you receive the notification from Antom, you are required to return a response as instructed in Requirements.

Antom allows you to specify the URL in the paymentNotifyUrl parameter within the createPaymentSession API. If the URL for each payment is the same, you can also configure it in the Antom Dashboard.

The following code shows a sample of notification request:

copy
{
  "notifyType": "PAYMENT_RESULT",
  "result": {
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "success"
  },
  "paymentRequestId": "paymentRequestId01",
  "paymentId": "2020010123456789XXXX",
  "paymentAmount": {
    "value": "4200",
    "currency": "MYR"
  },
  "paymentCreateTime": "2020-01-01T12:01:00+08:30",
  "paymentTime": "2020-01-01T12:01:01+08:30"
}

How to verify the signature of the notification and make a response to the notification, see Sign a request and verify the signature.

FAQs

When will the notification be sent?

It depends on whether the payment is completed:

  • If the payment is successfully completed, Antom will usually send you an asynchronous notification within 3 to 5 seconds. For some payment methods like OTC, the notification might take a bit longer.
  • If the payment is not completed, Antom needs to close the order first before sending an asynchronous notification. The time it takes for different payment methods to close the order varies, usually defaulting to 14 minutes.
Will the asynchronous notification be re-sent?

If you receive an asynchronous notification from Antom, you are required to return the response in the Sample code format. If you do not respond to the asynchronous notification as required, or the asynchronous notification is not delivered due to network reasons, the notification will be automatically resent within 24 hours. The notification can be resent up to 8 times or until a correct response is received to terminate delivery. The sending intervals are as follows: 0 minutes, 2 minutes, 10 minutes, 10 minutes, 1 hour, 2 hours, 6 hours, and 15 hours.

Do I need to add a digital signature to the response?

If you receive an asynchronous notification from Antom, you are required to return the response in the Sample code format, but you do not need to add a digital signature to your response.

How do I understand the meaning of the following key fields?
  • result: the payment result of the order.
  • paymentRequestId: the payment request ID generated by the merchant used for querying, canceling, and reconciliation.
  • paymentId: the payment order ID generated by Antom used for refund and reconciliation.
  • paymentAmount: if there is a need for amount reconciliation, you can consume this field.

Inquire about the result

You can call the inquiryPayment API to initiate a query on the result of an order.

Parameter name

Required

Description

paymentRequestId

The payment request ID generated by the merchant.

The parameter is not a full set of parameters, please refer to the inquiryPayment API for full set of parameters and additional requirements for certain payment methods.

The following sample code shows how to call the inquiryPayment API:

copy

AlipayClient defaultAlipayClient = new DefaultAlipayClient(EndPointConstants.SG,
                                                           merchantPrivateKey, alipayPublicKey);

AlipayPayQueryRequest alipayPayQueryRequest = new AlipayPayQueryRequest();
alipayPayQueryRequest.setClientId(CLIENT_ID);
alipayPayQueryRequest.setPath("/ams/sandbox/api/v1/payments/inquiryPayment");
alipayPayQueryRequest.setPaymentRequstId("paymentRequestId01");

AlipayPayQueryResponse alipayPayQueryResponse;
try {
    alipayPayQueryResponse = defaultAlipayClient.execute(alipayPayQueryRequest);
} catch (AlipayApiException e) {
    String errorMsg = e.getMessage();
    // handle error condition
}

The following code shows a sample of the request message:

copy
{
  "paymentRequestId": "paymentRequestId01"
}

The following code shows a sample of the response message:

copy
{
  "result": {
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "Success"
  },
  "paymentStatus": "SUCCESS",
  "paymentRequestId": "paymentRequestId01",
  "paymentId": "2019060811401080010018882020035XXXX",
  "paymentAmount": {
    "value": "4200",
    "currency": "MYR"
  },
  "paymentCreateTime": "2019-06-01T12:01:01+08:30",
  "paymentTime": "2019-06-01T12:01:01+08:30",
  "transactions": null
}

FAQs

How do I understand the meaning of the following key fields?
  • result: the result of the API call. It only indicates the result of the inquiryPayment API call. The order result should be determined based on the paymentStatus. SUCCESS and FAIL indicate final results, while PROCESSING indicates that the transaction is still in progress.
  • paymentAmount: amount verification. If there is a need for amount verification, this field can be used.
How frequently should I initiate the query?

It is recommended to initiate a round-robin query at an interval of 2 seconds until either the final payment result is retrieved or an asynchronous payment notification is received.

Sample codes

Full sample codes for front-end:

copy
AMSCashierPaymentConfiguration configuration = new AMSCashierPaymentConfiguration();
configuration.setLocale(new Locale("en", "US"));
// Specify showLoading as true (default value) to use the default loading pattern. Specify it as false to customize the loading animation based on onEventCallback.
configuration.setOption("showLoading", "true");
// Set the sandbox environment. If you leave it empty, the production environment is used by default.
configuration.setOption("sandbox", "true");
// Set the callback to monitor payment events on the checkout page.
configuration.setOnCheckoutListener(new OnCheckoutListener() {
    @Override
    public void onEventCallback(String eventCode, AMSEventResult eventResult) {
        AlipayLog.e(TAG, "onEventCallback eventCode=" + eventCode + " eventResult=" + eventResult.toString());

        if (!TextUtils.isEmpty(eventCode)) {
            if ("SDK_PAYMENT_SUCCESSFUL".equals(eventCode)) {
                // Payment was successful. Redirect buyers to the payment result page.
            } else if ("SDK_PAYMENT_PROCESSING".equals(eventCode)) {
                // Payment was being processed. Guide buyers to retry the payment based on the provided information.
            } else if ("SDK_PAYMENT_FAIL".equals(eventCode)) {
                // Payment failed. Guide buyers to retry the payment based on the provided information.
            }else if ("SDK_PAYMENT_CANCEL".equals(eventCode)) {
                // Guide buyers to retry the payment.
            } else if ("SDK_PAYMENT_ERROR".equals(eventCode)) {
                // The payment status was abnormal. Guide buyers to retry the payment based on the provided information.
            } else if ("SDK_END_OF_LOADING".equals(eventCode)) {
                // End your custom loading animation.
            }
        }
    }
});
// Instantiate AMSCashierPayment.
AMSCashierPayment checkout = new AMSCashierPayment.Builder(activity, configuration).build();

checkout.createComponent(activity, sessionData);

checkout.onDestroy();

Event codes

You might see two types of event codes:

  • Status codes: Returned by onEventCallback during the component's runtime lifecycle.
  • Error codes: Returned by onEventCallback or onError during the component initialization phase.

Type

Code

Description

Further action

Status codes

SDK_START_OF_LOADING

The loading animation starts to play during the payment component creation.

No further action.

SDK_END_OF_LOADING

The loading animation ends during the payment component creation.

No further action.

Error codes

SDK_INTERNAL_ERROR

The internal error of the SDK occurs.

Contact Antom Technical Support to resolve the issue.

SDK_CREATEPAYMENT_PARAMETER_ERROR

The parameters passed into the createComponent method are incorrect.

Ensure the parameters are passed correctly and send a new request.

SDK_CALL_URL_ERROR

Represents one of the following cases:

  • The redirection to the merchant page failed to be executed.
  • The parameter paymentRedirectUrl in your createpaymentSession (Cashier Payment) request is not passed or passed incorrectly.

Contact Antom Technical Support to resolve the issue.

SDK_INTEGRATION_ERROR

Dependencies are not found.

Ensure that the dependencies are added correctly and retry the integration process.