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.
Parameter | Type | Required | Description |
---|---|---|---|
profileId | Alphanumeric | Yes | The unique consumer profile Id, which the app sends to SDK to identify the consumer. Note: The profileId is without special characters and spaces. |
client | Object | Yes | An object of clientinfo. |
platform | String | No | The platform from which the request is sent; for example, web, iOS, android, b2b, b2c. Note: SDK sets the platform internally. |
version | String | Yes | The version of the application programming interface (API) or application that sends the request. |
language | String | Yes | The 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. |
countryid | Integer | Yes | The CPD-specific country code, which is available only on request. |
mobile | Integer | Yes | The 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. |
String | No | The e-mail address of a customer. Note: Email can be mandatory or optional, based on the requirement of a merchant or a PSP. | |
orderno | String | Yes | The 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._-] |
amount | Integer | Yes | The 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. |
secretSalt | String | Yes | The salt string sent from the app to SDK. Note: CPD provides the secret salt to a merchant. |
hmac | String | No | It is deprecated from version 2.3.1 onwards and is applicable only for mRetail SDK. |
appVersion | String | The 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.
Parameter | Type | Description |
---|---|---|
id | Integer | The unique identification number of a card. |
typeid | Integer | The type of payment card. |
pspid | Integer | The unique PSP identification number of a card. |
name | String | The name of a card such as Visa or Mastercard. |
store | Boolean | The information if a card is stored. |
minlength | Integer | The minimum length of a card number. |
maxlength | Integer | The maximum length of a card number. |
cvclength | Integer | The length of a CVC code. |
state | String | The information if a card is disabled. |
token | String | The token data used for third-party payments such as Apple Pay. |
paymentNetwork | String | A string of the name of a payment network used for third-party payment such as Apple Pay. |
cardNumber | Integer | The card number used for authorizing transaction. |
expiryMonth | Number | The card expiry month used for authorizing a transaction. |
expiryYear | Number | The card expiry year used for authorizing a transaction. |
paymentMethods | Array | The available sub card payment methods. |
processorType | String | The type of processor used for a transaction. |
paymentType | String | The type of payment. |
cvvmandatory | Bool | Shows if the card verification value (CVV) is mandatory. |
Updated 3 months ago