Integration for APM
9. Integration for APM
You can easily integrate SDK with an Android device for an APM. However, the integration workflow depends on an APM used for a transaction. This section provides an example for PayPal.
9.1 Application Configurations
Before you start integrating the SDK for APM transactions, you need to make the following configurations in your mobile application. To integrate the SDK with an Android device for an APM, complete the following steps:
- Add the following line to build.gradle file of your app:
implementation "com.cellpointmobile.mpoint:mPoint:2.5.0@aar"
- Copy PPFraud.jar file into libs folder of your application.
Note: Include this jar only if you opt for fraud detection feature.
- Add the following line to build.gradle file of your application:
compile 'com.android.support:customtabs:28.0.0'
- Add the following intent filters to the activity to implement mPoint initialization and authorization. This is achieved using deep linking.
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!—the following host and scheme is required to return call back from Paypal--> <data android:host="[MERCHANT URL].<CLIENT_HOST_DOMAIN_PREFIX>.PayPalReturn" android:scheme="cellpoint" /> </intent-filter>
9.2 Instantiate SDK
See Instantiate SDK for details.
9.3 Initialize Payment for APM
When you initialize a payment for APM, a call is sent to the SDK to authorize the payment. The following code sample shows the authorize call that you need to send to the SDK:
var addressInfo = [mPointAddressInfo]
var authToken = [AUTH_TOKEN]
mPoint.authorize(mPointAuthorizeInfo(cardInfo)
.setActivity(activity)
.setAddressInfo(addressInfo)
.setClientInfo(clientInfo)
.setAuthToken(authToken))
Note: The setAuthToken parameter can be optional or required, depending on merchant requirement.
9.4 Presentment Currency
This is a subscription-based feature. You can show the price of your product or services on your website or app-in presentment currencies. However, you cannot make settlement in that currency. Velocity enables you to make the settlement in the configured currency.
When making payments, customers select a currency in which they want to make payment. On the payment page, Velocity converts this currency into the settlement currency and facilitates the payment in the configured settlement currency
This feature is enabled for APM and wallet. It utilizes the FX flow in Velocity. In the initialize payment response, in the card node, if FX and presentment flags are true,
call the FX API to fetch available currencies. To call the FX API, refer to the following code sample
var cardInfo : mPointCardInfo
if(cardInfo.isDcc && cardInfo.isPresentmentCurrency){
// Fetch settlement currencies from initialize response and send it in Fx Service api request
val settlementCurrencies = cardInfo.settlementCurrencies
if(settlementCurrencies != null && settlementCurrencies.size > 0){
Call Fx API for Presentment Currency to fetch available currencies
val amount : Long
val currency : Int
val saleAmount: mPointAmountInfo = mPointAmountInfo().setCurrency(currency).setPrice(amount)
val offerCriteria: mPointExchangeOfferCriteria =
mPointExchangeOfferCriteria().setOrderNumber(orderID)
.setCardType(cardInfo.type)
.setCountry(CountryConfig.COUNTRY_CODES.getValues().get(countryCode)).country)
.setSaleAmount(saleAmount)
.setTransactionId(mPoint.txnInfo.id)
.setClientId(clientId)
.setClientInfo(clientInfo)
.setSettlementCurrencies(settlementCurrencies)
_mPoint.delegate = context _mPoint.getForeignExchangeOffer(offerCriteria)
}
After receiving the FX API response, create mPointForeignExchangeInfo
object. Display the available currency and exchange amount to the customer. Refer to Dynamic Currency Conversion for details. Refer to the following code sample:
override fun displayForeignExchangeOffers(offer: mPointExchangeOffer?, mpoint: mPoint?) {
var fxInfo : mPointForeignExchangeInfo = mPointForeignExchangeInfo()
.setId(offer?.foreignExchangeOfferId!!)
.setExchangeAmount(offer.paymentCurrencyOffers[0].exchangeAmount.price)
.setExchangeCurrencyId(offer.paymentCurrencyOffers[0].exchangeCurrency.isoNumericCode)
.setSaleCurrencyId(offer.paymentCurrencyOffers[0].saleCurrency.isoNumericCode)
.setSaleAmount(offer.paymentCurrencyOffers[0].saleAmount.price)
.setConversionRate(offer.paymentCurrencyOffers[0].offeredExchangeRate)
.setHmac(offer.paymentCurrencyOffers[0].validationHmac)
fxInfo.isDccOpted = true
fxInfo?.serviceTypeId = mPointForeignExchangeInfo.SERVICE_TYPE_ID.PCC_OPT_IN
}
Note: Consider the following items:
- The mPointForeignExchangeInfo object might be required for the subsequent API calls.
- When creating mPointForeignexchangeinfo object, set isDccOpted as true for presentment currencies.
- Set the value service type ID for the mPointForeignexchangeinfo object, as PCC_OPT_IN as mentioned in the previous code sample. The process is similar to FX opt-in.
9.5 Authorize Payment
After you invoke the authorize the authorization of PayPal transaction. Override the following method in that activity and authorize mPoint.
var txnTypeId = [mPointTxnInfo.TXN_TYPES.MPOINT_SHOPPING_ONLINE.id]
var addressInfo = [mPointAddressInfo]
var authToken = [AUTH_TOKEN]
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
var params : List<String> = intent.data.pathSegments
if (params.get(0).equals("return")) {
// complete PayPal checkout
mPoint.authorizeWallet(cardInfo, clientInfo, txnTypeId, authToken, addressInfo)
} else {
// cancel PayPal checkout
}
}
Note: Consider the following items:
• The authToken
parameter is required only if it is present in the initialize request.
• It is important that the activity must include in the manifest android:launchMode
="singleTask" //singleTop to activate onNewIntent
.
9.6 Payment Confirmation
Implement the displayPaymentConfirmation
call back method to receive the transaction status as shown in the following code sample:
override fun displayPaymentConfirmation(txn: mPointTxnInfo?, code: Int, mpoint: mPoint) {
Log.d(TAG, "displayPaymentConfirmation")
}
9.7 Initialize Payment for APM
When you initialize a payment for APM, a call is sent to the SDK to authorize the payment. Refer to the following code sample to make the authorize call, which you need to send to the SDK with the mPointForeignExchangeInfo
object in authorize API request for presentment currency:
mPoint.authorize(mPointAuthorizeInfo(cardInfo)
.setActivity(context)
.setAddressInfo(addressInfo)
.setClientInfo(clientInfo)
.setAuthToken(authToken)
.setForeignExchangeOffer(fxInfo))
9.8 Authorize Payment
After you invoke the authorize the authorization of PayPal transaction. Override the following method in that activity and authorize mPoint.
_mPoint.authorizeWallet(mPointAuthorizeWalletInfo()
.setWallet(cardInfo)
.setClientInfo(clientInfo)
.setTxnTypeId(mPointTxnInfo.TXN_TYPES.MPOINT_SHOPPING_ONLINE.id)
.setAuthToken(authToken)
.setAddressInfo(addressInfo)
.setForeignExchangeOffer(fxInfo))
9.9 Payment Confirmation
Implement the displayPaymentConfirmation
call back method to receive the transaction status as shown in the following code sample:
Implement the displayPaymentConfirmation call back method to receive the transaction status as shown in the following code sample:
9.10 Handle Error
When using the split payment option, after getting callback in displayPaymentConfirmation you need to call getTxnStatus method to retrieve status of the transactions. When calling the getTxnStatus pass session ID (available in mPoint class) to retrieve all transactions from the current session. To call getTxnStatus, use the following code sample:
if(isSplitPaymentApplicable){
if(mpoint!!.sessionId != null && mpoint.sessionId.isNotEmpty()){
mPoint.delegate = this
mPoint.getTxnStatus(-1, "", mpoint.sessionId, clientInfo)
}
}
To get transaction statuses response implement following delegate method:
override fun handleTxnStatus(arrListTxnStatusInfo: ArrayList<mPointTxnStatusInfo>?, paymentStatus: Int, arrListLinkedTransactions: ArrayList<mPointLinkedTransactions>?, mPoint: mPoint?) {
runOnUiThread {
var pendingAmount: Long = 0
if(null != arrListTxnStatusInfo && arrListTxnStatusInfo.size > 0){
for (txnStatusInfo : mPointTxnStatusInfo in arrListTxnStatusInfo){
// Retrieve Pending Amount
pendingAmount = txnStatusInfo.pendingAmount
}
}
when (paymentStatus) {
com.cellpointmobile.sdk.mPoint.PAYMENT_STATUS.MPOINT_PAYMENT_STATUS_PENDING.id ->
// Poll getTxnStatus()
getTxnStatus(mPoint!!.sessionId)
com.cellpointmobile.sdk.mPoint.PAYMENT_STATUS.MPOINT_PAYMENT_STATUS_COMPLETE.id -> {
if(pendingAmount == 0L)
// Split Payment Successful
else
// Retry Payment with Pending Amount
}
com.cellpointmobile.sdk.mPoint.PAYMENT_STATUS.MPOINT_PAYMENT_STATUS_FAILED.id -> {
// Retry Payment with Pending Amount
}
}
}
}
The merchant front end reads the response received to know the payment status. Read the paymentStatus parameter to know the status of the payment. If a transaction status has payment status as:
- Pending: call the getTxnStatus API again until you get the payment status either as Successful or Failed.
- Complete: the payment is successful.
- Failed: retry the payment.
To retry the payment, initialize the payment with the pending amount. This action helps a customer complete the payment using any option.
Send the pending amount you received from back end in the initialize request. After you initialize, a customer can complete the payment using any available payment option or can split the payment. This process repeats until the transaction is successful, fails, or maximum retries are attempted.
Note: If a customer decides not to retry a failed payment, call the Post-Status API as shown in the following code sample to notify that the session is complete:
mPoint.postStatus(mPoint.sessionId)
Refer to Handle Error for details.
9.11 Handle status
Refer to Handle Status for details.
Updated 7 months ago