SDK Integration for Wallets

10. SDK Integration for Wallets

The integration workflow of an Android device with SDK for a wallet transaction depends on the wallet used for a transaction. This section provides an example of Google Pay wallet integration.

Before you start integrating a wallet, go through the list of prerequisites.

To integrate the SDK for a wallet payment, check for the following:

10.1 SDK Integration Checklist

Before you start the SDK integration process, ensure you have the following details:

10.2 Application Configurations

Make the following configurations in your mobile application before you start integrating the SDK for wallet transactions.

10.2.1 Organize the Setup

To organize the setup, complete the following steps:

  1. Add dependencies in build.gradle file.
implementation 'com.google.android.gms:play-services-wallet:18.0.0'
implementation 'com.android.support:appcompat-v7:24.1.1'
  1. Update AndroidManifest.xml to enable Google Pay API.
<application
    ...
    ...
    <!-- Enables the Google Pay API -->
    <meta-data
        android:name="com.google.android.gms.wallet.api.enabled"
        android:value="true" />

10.2.2 Create Request Object

The mPoint SDK provides mPoint class to create request object based on the client configuration details. The request object is required to initiate the payment process.

this._mpoint = mPoint(URL ("[CPD provided URL]"), 
        this, 
        "username",[USERNAME] 
        "password", [PASSWORD] 
        clientid, [CLIENT ID] 
        accountid, [ACCOUNT ID] 
        null, 
        context, 
        null,
        RecordMap<String, String> (),
arrayOf(ClientInfo.IDENTIFIERS.DEVICEID)
 this._mpoint.mode = mPoint.OUTPUT_MODE.NONE)

10.3 Instantiate Payment

See Instantiate SDK for details.

10.4 Initialize Payment

To initialize a wallet payment, use the following code sample:

var mobile: Long = [MOBILE NUMBER];
var email: String = "[EMAIL ID]";
var countryId = CountryConfig.USA;   //[AMOUNT] for USA
var currencyId = [CURRENCY_ID]
var operatorId = countryId * 100;
var amount = [AMOUNT];
amount= amount*100;
var orderID : String = "[ORDER ID NUMBER]";
var mPointOrderInfo = [ORDER_INFO_AID_DATA]
var txnType: String = mPointTxnInfo.TXN_TYPES. MPOINT_SHOPPING_ONLINE; // Example of Search and Book Flow

mPointClientInfo  clientInfo = mPointClientInfo(appid, appversion, mPoint.LANGUAGES.da) 
.setCountryId(countryId) 
.setMobile(mobile) 
.setEmail(email) 
.setDeviceId(deviceid) 
.setCustomerRef(customerRefId) 
.setProfileId(profileId)

mPointInitializePaymentInfo paymentInfo = mPointInitializePaymentInfo()
                        paymentInfo.amount = amount
                        paymentInfo.country = CountryConfig.COUNTRIES.getValues().get(countryId)
                        paymentInfo.operator = operatorId
                        paymentInfo.mobile = mobile
                        paymentInfo.email = email
                        paymentInfo.language = mPoint.LANGUAGES.us
                        paymentInfo.setOrderno(orderID)
                       paymentInfo.clientinfo = clientInfo
                        paymentInfo.setCurrencyid(currencyId)
 paymentInfo.txnType = txnType
       paymentInfo.setHmac(hmac) OR
                        paymentInfo.secretSalt = salt


   paymentInfo.order = mPointOrderInfo
   paymentInfo.authToken = authToken
   paymentInfo.sessionId = sessionId 
     
mpoint.initialize(paymentInfo);

Note: Consider the following items:

  • The mPointOrderInfo is required only for order data.
  • The authToken can be made optional, depending on a merchant’s requirement.
  • The sessionId is required only for payment retries.

10.5 Presentment Currency

See Presentment Currency for details.

10.6 Initialize Payment

Call the following method to initialize the payment when a customer selects a third-party wallet for payment such as Google Pay.

var addressInfo = [mPointAddressInfo]   
var authToken = [AUTH_TOKEN] 
 

mPoint.authorize(mPointAuthorizeInfo(cardInfo)  
.setActivity(activity)  
.setAddressInfo(addressInfo)  
.setClientInfo(clientInfo)  
.setAuthToken(authToken))

Note: The authToken parameter can be optional or required, depending on the merchant requirement.

10.7 Authorize Payment

After the authorize method is called, customers can see their Google Pay accounts and cards stored in the wallet. When they select a card for payment, you get response in the following method:

override fun displayPaymentConfirmation(txn: mPointTxnInfo?, code: Int, mpoint: mPoint?)

10.8 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.

10.9 Handle status

The status codes are returned by the SDK in a call back to the handleStatus method. This method enables the application to handle the status appropriately by implementing the method as shown in the following code sample:

The handleStatus method shows an error in the CPD server.

override fun handleStatus(statusInfo: mPointStatusInfo, client: Client, mpoint: mPoint) {}