Initialize Payment

Velocity iOS Software Development Kit Integration Guide

Initialize Request

Initialize the payment transaction by invoking the initialize method as shown in the following code sample:

// Initialize payment

// Create ClientInfo object using builder pattern  
 let clientInfo = CPMClientInfo.make(builder: { builder in 
builder?._appId =  [CLIENT APP ID] 
builder?._profileId = [CUSTOMER PROFILE ID] 
builder?._appVersion =  [APP VERSION] 
builder?._language = [LANGUAGE] 
builder?._countryId =  CPMCountry(rawValue: UInt([COUNTRY CUSTOMER’s MOBILE NUMBER IS REGISTERED IN])!)!
builder?._mobile =  [CUSTOMER’S MOBILE NUMBER]              
builder?._email = [CUSTOMER’S EMAIL] 
builder?._customerRef = [CUSTOMER REFERENCE] 
      })
// Call initialize on mPoint SDK

 let info = mPointInitializeInfo.make { (builder:mPointInitializeBuilder?) in
            builder?._orderno = self.mPointMgr.orderNo
            let initAmount = Utility.generateInitializeAmount()
            if (initAmount == 0) {
                Utility.displayErrorAlert(message:"Error in generating amount for initialize", viewController: self)
                return
            }
            builder?._amount = initAmount [txn amount]
            builder?._info = clientInfo
            builder?._countryid = CPMCountry(rawValue: UInt(client.countryId)!)!
            builder?._transactionId = Int(String(format:"970%i",arc4random() % 999 ))!
            client.amount = "\(initAmount)"
            if !client.saltString.isEmpty {
            builder?._secretSalt = client.saltString
     }
            builder?._currencyId = client.currencyId
            // auth token should be sent in initialize request
            if !client.authToken.isEmpty {
                builder?._authtoken = client.authToken
            }

\\orderInfo is AID data\\
            builder?._orderInfo = Utility.generateOrderInfo()
            // Set session Id     
            if self.mPointMgr.sessionId > 0 {
                builder?._sessionId = self.mPointMgr.sessionId
            }
            builder?._typeid = .MPOINT_SHOPPING_ONLINE

            // Add holding fee if it is present. Holding fee is required for offline payments.
            if (AdditionalData.holdingFee != nil && AdditionalData.holdingFee?.isEmpty == false) {
                builder?._fee = Utility.generateHoldingFeeAmount(countryId: countryId)
            }
            if (!client.sessionToken.isEmpty) {
                builder?._additionalData = ["session_token": client.sessionToken]
            }
    }
        Self.mPointMgr.initialize(initializeInfo: info)

Request Parameters

The descriptions of the initialize payment parameters are listed in the table below.

ParameterTypeRequiredDescription
profileIdAlphanumericYesThe unique consumer profile Id, which the app sends to SDK to identify the consumer.

Note: The profileId is without special characters and spaces.
clientObjectYesAn object of clientinfo.
platformStringNoThe platform from which the request is sent; for example, web, iOS, android, b2b, b2c.

Note: SDK sets the platform internally.
versionStringYesThe version of the application programming interface (API) or application that sends the request.
languageStringYesThe language that Velocity uses as default when translating the payment pages. Velocity uses a default language set by a merchant if this parameter is omitted.

Note: Velocity language codes are based upon the ISO- 639-1 standard. Refer to http://en.wikipedia.org/wiki/ List_of_ISO_639-1_codes for details.
countryidIntegerYesThe CPD-specific country code, which is available only on request.
mobileIntegerYesThe MSISDN of a customer without International Dialling Code.

Note: Mobile number can be mandatory or optional, based on the requirement of a merchant or a PSP.
emailStringNoThe e-mail address of a customer.

Note: Email can be mandatory or optional, based on the requirement of a merchant or a PSP.
ordernoStringYesThe alphanumeric order ID that a merchant generates for a purchase.

Note: Some Payment Providers have strict guidelines for the order-no. The recommended pattern is "[a-zA-Z0-9._-]
amountIntegerYesThe total amount that a customer is charged for a payment transaction in a country’s smallest denomination. For example, the smallest currency of USD is a penny.
secretSaltStringYesThe salt string sent from the app to SDK.

Note: CPD provides the secret salt to a merchant.
hmacStringNoIt is deprecated from version 2.3.1 onwards and is applicable only for mRetail SDK.
appVersionStringThe version of an application

Callback

Implement the displayAvailablePayments callback method to display the available payment options as shown in the following code sample. In the displayAvailablePayments, the following sub-objects are available:

  • Card
  • Stored card
  • APM
  • Third-party wallet
  • Aggregators
  • Offline payment
  • Vouchers
  • SplitPayment
func display(_ availablePayments: mPointAvailablePayments!, mPoint mpoint: mPointManager
!) {
for card in availablePayments._cards.values {
if let c = card as? mPointCardInfo, !isAPM(card: c), !isWallet(card: c), (c._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED ||
c._state == mPointCardStates.MPOINT_CARD_STATE_DISABLED_BY_MERCHANT || c._state == mPointCardStates.MPOINT_CARD_DISABLE_SHOW) {
                mpointMgr.cards.append(c)
   }

}
// Read wallet cards
if let walletCardsArray = availablePayments._walletCards as? [mPointCardInfo], walletCardsArray.count > 0 {
            for walletCard in walletCardsArray {
                if (walletCard._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED || walletCard._state == mPointCardStates.MPOINT_CARD_STATE_DISABLED_BY_MERCHANT || walletCard._state == mPointCardStates.MPOINT_CARD_DISABLE_SHOW) {
                    mpointMgr.wallets.append(walletCard)
                }
            }
        }

// Read APMs
        if let apmsArray = availablePayments._apms as? [mPointCardInfo], apmsArray.count > 0 {
            for apm in apmsArray {
                if(apm._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED || apm._state == mPointCardStates.MPOINT_CARD_STATE_DISABLED_BY_MERCHANT || apm._state == mPointCardStates.MPOINT_CARD_DISABLE_SHOW) {
                    mpointMgr.apms.append(apm)
                }
            }
      }
// Read aggregators
        if let aggregators = availablePayments._aggregators as? [mPointCardInfo], aggregators.count > 0 {
            for aggregator in aggregators {
                if aggregator._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED {
                    mpointMgr.aggregators.append(aggregator)
                }
            }
             // Read payment center cards
            let offlineCards = availablePayments._offlineCards
            for offlineCard in offlineCards {
                if offlineCard._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED {
                    mpointMgr.offlineCards.append(offlineCard)
                }
            }
        // Read vouchers
            let vouchers = availablePayments._vouchers
            for voucher in vouchers {
                if voucher._state == mPointCardStates.MPOINT_CARD_STATE_ENABLED {
                    mpointMgr.vouchers.append(voucher)
                }
            }
       // Read split payment combinations
       let splitPayment = availablePayments._splitPayment ?? mPointSplitPayment()
let combinationsArray = splitPayment.configurations._applicableCombinations
for combination in combinationsArray {
mpointMgr.splitCombinations.append(combination)
}
}

Callback Parameters

The descriptions of the parameters are listed in the table below.

ParameterTypeDescription
idIntegerThe unique identification number of a card.
typeidIntegerThe type of payment card.
pspidIntegerThe unique PSP identification number of a card.
nameStringThe name of a card such as Visa or Mastercard.
storeBooleanThe information if a card is stored.
minlengthIntegerThe minimum length of a card number.
maxlengthIntegerThe maximum length of a card number.
cvclengthIntegerThe length of a CVC code.
stateStringThe information if a card is disabled.
tokenStringThe token data used for third-party payments such as Apple Pay.
paymentNetworkStringA string of the name of a payment network used for third-party payment such as Apple Pay.
cardNumberIntegerThe card number used for authorizing transaction.
expiryMonthNumberThe card expiry month used for authorizing a transaction.
expiryYearNumberThe card expiry year used for authorizing a transaction.
paymentMethodsArrayThe available sub card payment methods.
processorTypeStringThe type of processor used for a transaction.
paymentTypeStringThe type of payment.
cvvmandatoryBoolShows if the card verification value (CVV) is mandatory.