Android
In this topic, you'll learn how to integrate the embedded card payment SDK with an Android client. This will allow you to render the card payment page in a mobile application.
Before the integration, ensure that you have completed the following tasks:
- Install the latest version of Android Studio.
- Use target API level 19 or later.
- Use Gradle 4.1 or later.
- Configure a physical machine or emulator to run your application.
Integrate the embedded card payment SDK by following these steps:
Integrate the SDK package
To integrate the SDK package, please refer to Integrate the SDK Package for Android.
Create an SDK instance using AMSCashierPayment :
- Initialize the checkout instance with the following parameters:
- configuration: Required. An object of typeAMSCashierPaymentConfiguration. The object must contain all of the following configuration parameters:
- Create an
AMSCashierPaymentConfigurationobject. The object must contain all of the following configuration parameters:- locale: Optional. String type. It is used by the merchant client to identify the browser language and pass in the language information. The SDK uses the information to render the cashier page in the corresponding language. Valid values are listed as follows. If other values are passed, English is used by default:
"en", "US":English"es", "ES":Spanish"fr", "FR":French"nl", "NL":Dutch"it", "IT":Italian"de", "DE":German"zh", "CN":Simplified Chinese
- setOption: Optional. Used to specify whether to use the sandbox environment. Valid values are:
"sandbox", "true":Sandbox environment."sandbox", "false":Production Environment."showSubmitButton", "true":Configure the SDK component to render the card binding button."showSubmitButton", "false":Configures the merchant to render the card binding button, requiring invocation of the submit() function in the instance object to trigger the card binding submission process."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.truevalue 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.
- storedCard:Optional object used for setting custom features of stored cards. It contains a value below:
- locale: Optional. String type. It is used by the merchant client to identify the browser language and pass in the language information. The SDK uses the information to render the cashier page in the corresponding language. Valid values are listed as follows. If other values are passed, English is used by default:
- Create an instance of the OnCheckoutListener API to handle corresponding events that occur in the subsequent process. It contains the following function:
OnEventCallback: Required. The card vaulting event callback function that returns eventCode and eventResult.
- Set the instance of the onCheckoutListener API to the configuration instance for executing event callbacks.
- Instantiate
AMSCashierPayment。
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.
Render payment element collection components
- Use the
mountComponentmethod in the instance object and pass the following parameters:- activity: Required. Activity type object, used to contain contextual parameter information for the current page.
- appearance is AMSPaymentAppearance type.
"showSubmitButton", "true":Configure the SDK component to render the payment button."showSubmitButton", "false":Configure the merchant to render the payment button, while also calling thesubmit()method in the instance object to trigger the submission of the payment process.
- sessionData:Required. String type. Pass the complete data of the createPaymentSession field obtained from the response of session creation request into the paymentSessionData parameter of
sessionData. - parentViewGroup:Required, FrameLayout type, used to bind the view to the merchant's page layout. The layout parameter needs to be set to
wrap_content. The SDK will automatically adjust the view width and height according to the size of the internal content of the view.
- Call the
submit()method in the instance object:- Calling this function to initiate the payment transaction process and returns specific event codes. These event codes will also be returned via the
onEventCallback. - If you need to pass in pre-collected billing address information for AVS verification, you can configure the following parameters to be passed in through the
submitmethod.- billingAddress: Optional, Object type. Billing address information is used to identify the payer's identity and location. It contains the following parameters:
- region: Required. String (2). ISO 3166 compliant 2-digit country code.
- state: Optional. String (8). The name of the state, country, or province.
- city: Optional. String (32). Name of the city, region, suburb, town or village.
- address1: Optional. String (256). Address line 1, e.g., street address, P.O. Box, and company name.
- address2: Optional. String (256). Address line 2, e.g., apartment, suite, unit, and building information.
- zipCode: Optional. String (32). Zip code.
- billingAddress: Optional, Object type. Billing address information is used to identify the payer's identity and location. It contains the following parameters:
- Calling this function to initiate the payment transaction process and returns specific event codes. These event codes will also be returned via the
-
Free resources of the SDK component by calling the
unmount()method in the instance object. You need to unmount the component in the following cases:- When the buyer switches views and exits the payment page, free the component resources created in createPaymentSession.
- When the buyer initiates multiple payment transactions, free the component resources previously created in createPaymentSession.
- When the buyer completes a payment and notRedirectAfterComplete is
true,which allows the buyer to receive a definitive payment result event code, free the component resources.
The SDK may return the following error codes:
SDK_INTERNAL_ERROR: SDK internal error. Please contact Antom technical support.SDK_CREATEPAYMENT_PARAMETER_ERROR:mountComponentmethod passed in parameter abnormally, and please check if the parameter is correct and retry the request by replacing the paymentRequestId.SDK_INIT_PARAMETER_ERROR:AMSCashierPaymentmethod passed in parameter abnormally. Please check if the parameter is correct and Instantiate the SDK again.SDK_CREATECOMPONENT_ERROR: Component initialization exception. Please contact Antom technical support.SDK_SUBMIT_NETWORK_ERROR: Interface call failed due to network reasons. It may occur insubmitmethod submission. Please try to submit it again.
The SDK may return the following status codes:
SDK_CALL_URL_ERROR:This event code represents one of the following scenarios:
-
- Failure to redirect to the merchant page.
- Failure to redirect to the 3D challenge page.
- The paymentRedirectUrl parameter is not provided and correctly passed when calling createPaymentSession API.
In Web/WAP scenarios, redirection links typically do not cause issues, but it is recommended to verify the redirect link. In the App scenario, if this anomaly occurs frequently, please contact Antom technical support to troubleshoot redirection or app launch issues.
SDK_CALL_URL_SUCCESS: The merchant page was successful. No further action is required.SDK_DUPLICATE_SUBMISSION_BEHAVIOR: The form is submitted repeatedly. The merchant can prompt the user with a toast so that they don't have to click submit repeatedly.SDK_PAYMENT_AUTHORIZATION_SUCCESSFUL: The payment process is completed. If the feature of not redirecting after payment completion is configured, it is recommended to continue monitoring the relevant payment event code to manage the subsequent steps. Otherwise, you can ignore this event code, as it will automatically redirect to your payment result page.SDK_PAYMENT_CHALLENGE: Triggered for 3D challenge. The issuing bank requires further interaction from the buyer before payment can be verified. No action is needed; the SDK will redirect to the challenge page.
The SDK may return the following result codes (result.resultCode):
SDK_PAYMENT_SUCCESSFUL: The payment Successful. Please redirect to the payment result page.SDK_PAYMENT_FAIL: The payment failed. Suggest checking the paymentResultCode error code message and re-initiating the payment.SDK_PAYMENT_PROCESSING: The payment is being processed. Suggest your server query the payment status or wait for the payment result notification.SDK_PAYMENT_ERROR: The payment status is abnormal. Suggest your server query the payment status or wait for the payment result notification.SDK_PAYMENT_CANCEL: The buyer did not click payment and closed the payment window. Can be used to re-invoke the SDK with paymentSessionData within its validity period. If expired, you need to request paymentSessionData again.SDK_FORM_VERIFICATION_FAILED: Form submission failed validation. The SDK will display form error codes on the element collection page.
The SDK may return the following payment status (paymentStatus):
SUCCESS: Payment Successful.FAIL: Payment failed.PROCESSING: The payment is processing.CANCELLED: The payment has been canceled.PENDING: The payment has been completed, please wait for the final payment result notification.
The SDK may return the following result codes (result.resultCode):
| Code | Value | Message | Further actions |
| SUCCESS | S | Success | -No further action is required. |
| ORDER_NOT_EXIST | F | The order does not exist. | Suggest placing a new order. |
| PAYMENT_IN_PROCESS | U | The payment is being processed. | Wait for the payment notification or actively query the result. |
| PROCESS_FAIL | F | A general business failure occurred. | Usually, this issue requires manual confirmation. It is recommended to contact Alipay technical support to resolve the problem. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Wait for the payment notification or actively check the result. |
| INQUIRY_PAYMENT_SESSION_FAILED | F | Failed to retrieve paymentSessionData, which may have expired or is in an unknown state.
| The session has expired. Wait for the payment notification or actively check the result. |
| PAGE_ELEMENT_ILLEGAL | U | The payment information is incorrect. | The payment was rejected, and there was an error in filling out the payment details. |
The SDK may return the following result codes(paymentResultCode):
| Code | Value | Message | Further actions |
| SUCCESS | S | Success |
No further action is required. |
| ACCESS_DENIED | F | Access is denied. | Insufficient permissions. Contact Antom technical support to understand the specific reasons. |
| CURRENCY_NOT_SUPPORT | F | The currency is not supported. | Currency not supported. Contact Antom technical support to understand the specific reasons. |
| FRAUD_REJECT | F | The transaction cannot be further processed because of risk control. If the user has already paid for the transaction, the transaction will be refunded. | Fraudulent rejection. In the following situations, please contact technical support:
|
| INVALID_CARD | F | The card is invalid. Maybe the credit card number cannot be identified, the card has no corresponding issuing bank, or the card number is in the wrong format. | Invalid card. It is recommended to try again with a different card.
|
| INVALID_EXPIRY_DATE_FORMAT | F | The format of expiryYear or expiryMonth is wrong. | The card's expiration date is incorrect. It is recommended to check the format of the card's expiration date entry. |
| ISSUER_REJECTS_TRANSACTION | F | The issuing bank rejects the transaction. | The issuing bank has denied the request. It is recommended to try again with a different card or contact the issuing bank. |
| INVALID_MERCHANT_STATUS | F | The merchant status is abnormal because restrictions exist. | The merchant's status is abnormal. Please contact technical support to understand the specific reasons. |
| MERCHANT_KYB_NOT_QUALIFIED | F | The payment failed because of the merchant's KYB status. The merchant is either not KYB compliant, or the KYB status is not qualified for this transaction. | Please contact technical support to understand the specific reasons. |
| NO_PAY_OPTIONS | F | The currency is not supported for the transaction. | The currency is not supported. Check if the payment method supports this currency or if the payment method and currency are consistent with what was agreed in the contract. If there are any issues, contact technical support to understand the specific reasons. |
| ORDER_IS_CLOSED | F | The request you initiated has the same paymentRequestId as that of the existed transaction, which is closed. | The order has been closed. Initiate a new request and try again. |
| PAYMENT_AMOUNT_EXCEED_LIMIT | F | The payment amount is greater than the maximum amount allowed by the contract or payment method. | Exceeded the limit amount. Check if the payment amount is above the limit or try with a lower amount and retry. Contact technical support to understand the specific payment limit. |
| PAYMENT_COUNT_EXCEED_LIMIT | F | The maximum number of payments exceeds the limit that is specified by the payment method. | Exceeded the usage limit. Contact technical support to understand the specific payment limit. |
| PAYMENT_NOT_QUALIFIED | F | The merchant is not qualified to pay because the merchant is not registered, does not have a contract for Auto Debit payment, or is forbidden to make a payment. | The merchant does not have permission. Contact technical support to understand the specific reasons. |
| PROCESS_FAIL | F | A general business failure occurred. | Payment failed. This issue usually requires manual verification. It is recommended to contact technical support to resolve the problem. |
| RISK_REJECT | F | The transaction cannot be further processed because of risk control. If the user has already paid for the transaction, the transaction will be refunded. | Risk control rejection. If the buyer does not receive a refund within two weeks, please contact technical support. |
| SUSPECTED_CARD | F | The card is suspected of fraud. For example, the card is stolen or restricted. | Risk control rejection. Suggest trying again with a different card or contacting the issuing bank. |
| SUSPECTED_RISK | F | The transaction cannot be further processed because of suspected security issues. You can retry the transaction after one working day. If the transaction is not secure and the user has already paid, the transaction will be refunded. | Fraudulent rejection. In the following situations, please contact technical support:
|
| USER_AMOUNT_EXCEED_LIMIT | F | The payment amount exceeds the user payment limit. | The amount exceeds the limit. Please initiate the payment again with an amount less than or equal to the available balance in your account, or contact technical support. |
| USER_BALANCE_NOT_ENOUGH | F | The payment cannot be completed because the user balance in the corresponding payment method is not enough. | User's balance is insufficient. Please recharge or choose another payment method. |
| USER_KYC_NOT_QUALIFIED | F | The payment failed because of the user's KYC status. The user is either not KYC compliant, or the KYC status is not qualified for this transaction (for example, limitations on the payment amount or product information). | User needs to complete KYC certification. |
| USER_PAYMENT_VERIFICATION_FAILED | F | The user is restricted from payment on the payment method side. | User has not completed verification. Please contact technical support to understand the specific reasons. |
| USER_STATUS_ABNORMAL | F | The user status is abnormal on the payment method side. | User status is abnormal. Please contact technical support to understand the specific reasons. |
| PAYMENT_IN_PROCESS | U | The payment is being processed. | Payment processing. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Unknown error. Please contact technical support to understand the specific reasons. |
| CARD_NOT_SUPPORTED | F | The card used for the transaction is not supported. | The card is not supported. Please try using a different card. |
| INVALID_EXPIRATION_DATE | F | The value of paymentMethod.paymentMethodMetaData.expiryYear or paymentMethod.paymentMethodMetaData.expiryDate is invalid. | The card's expiration date is incorrect. Please check if the card's expiration date is filled in correctly. |
| INVALID_CARD_NUMBER | F | The number of the card used for the transaction is invalid. | The card number is incorrect. Please try again with a different card. If the issue persists after retrying, contact technical support to understand the specific reasons. |
The following sample code demonstrates the key steps in the integration process. The code does not include examples of calling the createPaymentSession API. You need to handle the server API calls on your own.