Android
In this topic, you'll learn how to integrate the pop-up payment experience SDK into an Android client. This will help you to render cashier pages in a mobile application.
Before the integration, ensure that you have completed the following tasks:
- Install the latest version of Android Studio.
- Target at least API level 19 or later.
- Use Gradle 4.1 or later.
- Configure a physical machine or simulator to run your application.
Integrate the SDK by the following steps:
Integrate the SDK package
Create an SDK instance by using AMSCashierPayment
The process of creating an SDK instance includes the following steps:
- Create a config object: Required. The object must contain all of the following configuration parameters:
- setLocale: Optional. String type. It is used to pass in language information. Valid values are listed as follows. If other values are passed, English is used by default:
en_US
: Englishes_ES
: Spanishfr_FR
: Frenchnl_NL
: Dutchit_IT
: Italiande_DE
: Germanzh_CN
: Simplified Chinese
- setOption: Optional, used to set whether to adopt the default loading style and whether to use a sandbox environment. Supported values include the following:
"sandbox", "true"
: Sandbox environment."sandbox", "false"
: Production Environment."showLoading", "true"
: Use the default loading style."showLoading", "false"
: Do not use the default loading style."notRedirectAfterComplete", "true"
: Optional, Boolean type. The default value isfalse
, which means it will jump back to your page after the payment is completed. The same applies when the value is empty.true
value means there will be no jump after the payment is completed. You need to use the customer event code to control the card binding to complete the subsequent process. Please note that the payment result event code returned by the client is only used as a reference for the jump operation of the client page. For transaction status updates, please refer to the results returned by the server's notifyPayment or inquiryPayment API.-
"merchantAppointmentParam"
: Optional object used for setting custom features. It contains a value below:- storedCard: Optional object used for setting custom features of stored cards. It contains a value below:
- needCVV: Optional Boolean. The default value is
false
, which indicates that the user do not need to input CVV number during the payment process. The same applies when the value is empty.true
value means the user need to input CVV number during the payment process.
- needCVV: Optional Boolean. The default value is
- storedCard: Optional object used for setting custom features of stored cards. It contains a value below:
- setLocale: Optional. String type. It is used to pass in language information. Valid values are listed as follows. If other values are passed, English is used by default:
- Create an instance of the
onCheckoutListener
API for handling corresponding events in subsequent processes, including the following method:onEventCallback
: Required. A callback function that returns various types of data or values, including event codes, cardPaymentResultInfo parameter for card payment, and popRiskDecisionResultInfo parameter for risk control. See the References for further information.
- Set the instance of the
onCheckoutListener
API to the configuration instance for executing event callbacks. - Instantiate the
AMSCashierPayment
.
Initiate a createPaymentSession request
The merchant client monitors the click events of the payment button itself. When the buyer selects the payment method and clicks the payment button, the merchant client initiates createPaymentSession request to the APO server. Once the response to the createPaymentSession request is received, the paymentSessionData value in the response is used in Step 4.
For card token payment mode with bound cards, you need to pass in the paymentMethod.paymentMethodId field to the card token returned to you by APO after the buyer binds the card. The way to obtain the card token is as follows:
- Independent card binding: Obtain the card token through the card.cardToken field in the asset binding result notification sent to you by APO.
- Non-independent card binding: Obtain the card token through the paymentResultInfo.cardToken field in the payment result notification sent to you by APO or the response to actively query the payment result.
Note: When calling the createPaymentSession API, the value of the request parameter paymentRedirectUrl needs to use the URL Scheme corresponding to the page you provide after the payment is completed.
Create a payment element collection component using the createComponent
method in the instance object.
- Call the
createComponent()
method and pass in the following parameters:- activity: Required. Activity type object, used to contain contextual parameter information for the current page.
- sessionData: Required. String type. Pass in the complete data of the paymentSessionData field obtained from the response of the createPaymentSession request into the sessionData parameter.
-
Free resources of the SDK component by calling the
onDestroy()
method in the instance object. You need to unmount a component in the following cases:- When the user exits the checkout page, free the component resources created in the createPaymentSession .
- When the user initiates multiple payments, free the component resources created in the previous createPaymentSession .
The References offers callback data and code samples for integration steps. For further details, refer to the References.