iOS
In this topic, you'll learn how to integrate the embedded payment experience SDK into an iOS client, and it will allow you to render checkout pages in a mobile application.
Before the integration, ensure that you have completed the following tasks:
- Install Xcode 12 or later.
- Use iOS 11 or later.
Integrate the SDK by following these steps:
Integrate the SDK package
Create an SDK instance by using the AMSCashierPayment
- Create an instance for the checkout page. The instance contains the following parameters:
- configuration: A required object belonging to the
AMSCashierPaymentConfigurationtype. The object must contain all configuration parameters.
- configuration: A required object belonging to the
- Create the
AMSCashierPaymentConfigurationclass, which must contain the following parameters:- locale: Optional. NSString 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 provide checkout pages in the corresponding language. 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
- options: Optional. NSDictionary type. It is 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": Configure the merchant to render the card binding button, while also calling thesubmit()method in the instance object to trigger the submission of the card binding process."notRedirectAfterComplete", "true": The default value isfalse, which means it will redirect back to your page after the payment is completed. The same applies when the value is empty.truevalue means there will be no redirect 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 redirect 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 the following value:- 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 buyer does not need to input the CVV number during the payment process. The same applies when the value is empty. Thetruevalue means the buyer needs to input the 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:
- locale: Optional. NSString 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 provide checkout pages in the corresponding language. Valid values are listed as follows. If other values are passed, English is used by default:
- Create the
AMSPaymentProtocolinstance for handling corresponding events in subsequent processes, including the following method:onEventCallback: A callback function that returns various types of data or values, including event codes, cardPaymentResultInfo parameter for card payment, and popRiskDecisionResultInfoparameter for risk control. See the References for further information.
- Create an instance of the
AMSLoggerProtocolprotocol, which is used to manage log output:logWithName: Optional. It is a callback method that is used to output logs by default.。
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.
Render card binding element collection components
- Use the
MountComponentmethod in the instance object:- Create a configuration object using the vaultingSessionDataparameter: Pass in the full data of the vaultingSessionData field obtained in Step 4 into the vaultingSessionData parameter of
mountComponent. - Call the
mountComponent()method in the instance object.
- Create a configuration object using the vaultingSessionDataparameter: Pass in the full data of the vaultingSessionData field obtained in Step 4 into the vaultingSessionData parameter of
- Call the
submit()method in the instance object:- Calling this method triggers the card-binding submission process, and the return value is a
Promisethat returns a specific event code. These event codes are also returned by events such asonErrororonEventCallback. - If you need to pass in pre-collected billing address information for AVS validation, you can configure the following parameters to be passed in via the
submit()method.- billingAddress: Optional Object. Billing address information is used to identify and locate the payer. It contains the following parameters:
- region: Required. String (2). ISO 3166 compliant 2-digit country code.
- zipCode: Optional. String (32). Zip code.
- address2: Optional. String (256). Address line 2, e.g., apartment, suite, unit, and building information.
- address1: Optional. String (256). Address line 1, e.g., street address, P.O. Box, and company name.
- city: Optional. String (32). Name of the city, region, suburb, town or village.
- state: Optional. String (8). The name of the state, country, or province.
- billingAddress: Optional Object. Billing address information is used to identify and locate the payer. It contains the following parameters:
- Calling this method triggers the card-binding submission process, and the return value is a
-
Free resources of the SDK component by calling the
unmount()method in the instance object. You need to unmount a component in the following cases:- When the user switches views to exit the checkout page, free the component resources created in the createPaymentSession API.
- When the user initiates multiple payments, free the component resources created in the previous createPaymentSession API.
- When the user completes the payment and sets notRedirectAfterComplete to
true, free the component resources after obtaining specific payment result codes.
The SDK provides the following error codes:
SDK_INTERNAL_ERROR: SDK internal error. Please contact APO technical support.SDK_CREATEPAYMENT_PARAMETER_ERROR:mountComponentmethod passed in parameter abnormally, please check if the parameter is correct and retry the request by replacing the vaultingRequestId.SDK_INIT_PARAMETER_ERROR:AMSVaultingmethod passed in parameter abnormally. Please check if the parameter is correct and retry the request by replacing the vaultingRequestId.SDK_CREATECOMPONENT_ERROR: Component initialization exception. Please contact APO technical support.SDK_ABNORMAL_RENDERING_DATA: Rendering data exception. Please retry the initialization process or contact technical support for troubleshooting.SDK_SUBMIT_NETWORK_ERROR: API call failed due to network reasons. It may occur insubmitmethod submission. Please try to submit it again.
The SDK provides the following status codes:
SDK_CALL_URL_ERROR: This event code represents one of the following event scenarios:- Failed to redirect to the merchant page.
- Failed to redirect to the 3D challenge page.
- The paymentRedirectUrl parameter was not provided or incorrectly provided when calling the createPaymentSession API.
In Web/WAP scenarios, redirect links usually do not encounter issues. It is recommended to validate the redirect link. In App scenarios, if this exception frequently occurs, please contact APO technical support to investigate redirect or app launch issues.
SDK_CALL_URL_SUCCESS: Redirection to the merchant page is successful. No further action is required.SDK_DUPLICATE_SUBMISSION_BEHAVIOR: The form is submitted repeatedly. The merchant can prompt the buyer not to click submit repeatedly.SDK_PAYMENT_AUTHORIZATION_SUCCESSFUL: Once the payment process is complete, if the feature to disable redirection after payment completion is configured, it is recommended to continue listening to the corresponding payment event codes to handle subsequent processes. Otherwise, you can ignore this event code, as the buyer will be redirected to your designated payment result page.SDK_PAYMENT_CHALLENGE: A 3D challenge has been triggered, and the card-issuing bank requires further interaction from the buyer before the payment can be authenticated. No additional handling is required, as the SDK will automatically redirect the buyer to the challenge page.
The SDK may return the following payment result event codes:
SDK_PAYMENT_SUCCESSFUL: The payment was successful. Suggest redirecting buyers to the payment result page.SDK_PAYMENT_FAIL: The payment failed. We suggest that you check the value of paymentResultCode in theonEventCallbackresult data for details. Guide users to retry the payment based on the provided information.SDK_PAYMENT_PROCESSING: The payment is being processed. Your server can check the payment status or waits for the payment result notification.SDK_PAYMENT_ERROR: The payment status is abnormal. Your server can check the payment status or wait for the payment result notification.SDK_PAYMENT_CANCEL: The buyer did not proceed with the payment and closed the payment window. You can use the valid paymentSessionData to call the SDK again. If it has expired, new paymentSessionData must be requested.SDK_FORM_VERIFICATION_FAILED: After the form submission, the verification failed. The SDK will display the form error codes on the element page.
The SDK may return the following payment status (paymentStatus):
SUCCESS: indicates that the payment is successful.FAIL: indicates that the payment failed.PROCESSING: indicates that the payment is being processed.CANCELLED: indicates that the payment is cancelled.PENDING: indicates that the payment is complete. Wait for the payment result notification.
The SDK may return the following result codes (result.resultCode):
| resultCode | Value | Message | Suggestions |
| SUCCESS | S | Success | - |
| ORDER_NOT_EXIST | F | The order does not exist. | Please place the order again. |
| PAYMENT_IN_PROCESS | U | The payment is being processed. | Wait for payment notifications or inquiry the payment results. |
| PROCESS_FAIL | F | A general business failure occurred. | Contact APO technical suppport to solve the problem. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Wait for payment notifications or inquiry the payment results. |
| INQUIRY_PAYMENT_SESSION_FAILED | F | Failed to retrieve paymentSessionData, which may have expired or is in an unknown state.
| The payment session is expired. Wait for payment notifications or inquiry the payment results. |
| PAGE_ELEMENT_ILLEGAL | U | The payment information is incorrect. | The payment is denied because the payment information is incorrect. |
The SDK may return the following card vaulting result codes (paymentResultcode):
| resultCode | Value | Message | Suggestions |
| SUCCESS | S | Success |
- |
| ACCESS_DENIED | F | Access is denied. | Please contact APO technical support. |
| CURRENCY_NOT_SUPPORT | F | The currency is not supported. | Please contact APO technical support. |
| 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. | The card is suspected of fraud. Please contact APO technical support in the following situations:
|
| 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. | Please try again with a different card.
|
| INVALID_EXPIRY_DATE_FORMAT | F | The format of expiryYear or expiryMonth is wrong. | Check the format of the expiration date. |
| ISSUER_REJECTS_TRANSACTION | F | The issuing bank rejects the transaction. | Please try again with a different card or contact the issuing bank. |
| INVALID_MERCHANT_STATUS | F | The merchant status is abnormal because restrictions exist. | Please contact APO technical support. |
| 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 APO technical support. |
| NO_PAY_OPTIONS | F | The currency is not supported for the transaction. | Check whether the payment method supports the currency, or whether the payment method and currency align with the terms specified in the contract. Please contact APO technical support. |
| ORDER_IS_CLOSED | F | The request you initiated has the same paymentRequestId as that of the existed transaction, which is closed. | The order is closed, please place a new order to try again. |
| PAYMENT_AMOUNT_EXCEED_LIMIT | F | The payment amount is greater than the maximum amount allowed by the contract or payment method. | Check whether the payment amount exceeds the limit or try again with a lower amount. Please contact APO technical support. |
| PAYMENT_COUNT_EXCEED_LIMIT | F | The maximum number of payments exceeds the limit that is specified by the payment method. | Please contact APO technical support. |
| 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. | Please contact APO technical support. |
| PROCESS_FAIL | F | A general business failure occurred. | The payment failed. Please contact APO technical support. |
| 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. | The card is suspected of risk control. If the buyer did not receive refunds in two weeks, please contact APO technical support. |
| SUSPECTED_CARD | F | The card is suspected of fraud. For example, the card is stolen or restricted. | Please try again with a different card or contact 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. | The card is suspected of risk control. Please contact APO technical support in the following situations:
|
| USER_AMOUNT_EXCEED_LIMIT | F | The payment amount exceeds the user payment limit. | Initiate the payment again using an amount less than or equal to the account's available balance or contact APO technical support. |
| USER_BALANCE_NOT_ENOUGH | F | The payment cannot be completed because the user balance in the corresponding payment method is not enough. | Please top up the account or select 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). | The user needs to complete the KYC verification. |
| USER_PAYMENT_VERIFICATION_FAILED | F | The user is restricted from payment on the payment method side. | Please contact APO technical support. |
| USER_STATUS_ABNORMAL | F | The user status is abnormal on the payment method side. | Please contact APO technical support. |
| PAYMENT_IN_PROCESS | U | The payment is being processed. | - |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Please contact APO technical support. |
| CARD_NOT_SUPPORTED | F | The card used for the transaction is not supported. | Please try again with a different card. |
| INVALID_EXPIRATION_DATE | F | The value of paymentMethod.paymentMethodMetaData.expiryYear or paymentMethod.paymentMethodMetaData.expiryDate is invalid. | Verify whether the card expiration date is been entered and if it is been entered correctly. |
| INVALID_CARD_NUMBER | F | The number of the card used for the transaction is invalid. | Please try again with a different card. If the problem is not resolved, contact APO technical support. |
The following sample codes demonstrate the key integration steps. The sample does not include the steps for calling createPaymentSession API. You need to handle the server-side API calling.