Local Integration with iOS

Overview

This document serves as a complete reference guide for individuals seeking to utilize the Pine Labs iOS PoSlib SDK. Its primary focus is to assist in the acceptance of payments, processing of transactions, and the seamless return of payment results to the invoking payment terminal application.

The Billing System can be integrated into the iOS platform in a single way namely Off-Device Integration.

In Off-Device integration approaches, the Merchant Billing application should use the PoSLib to communicate with the PineLabs Payment Application via PoSBridge.

The following sections provide detailed insights into Off-Device Integration processes.

Off-Device Integration

In this approach, the Merchant Billing application, running on iOS devices such as tablets or mobile phones, communicates with the Pine Labs Payment application by integrating the iOS PoSlib. The iOS PoSlib facilitates communication with the pinelabs Payment application via PoSBridge.

The Merchant Billing application needs to integrate PoSlib to communicate with the PoSBridge application through PoSLib APIs. The message exchange between PoSLib and PoSBridge can occur over IP.

Screenshot

The Billing System communicates with PoSBridge application via PoSLib APIs. Message exchange between PoSLib and PoSBridge can happen over IP. The Billing System running on the PineLabs Payment Terminal has the capability to perform transactions via app-to-app communication.

The following sequence diagram describes the transaction flow:

Screenshot

Merchant Billing Application shall be integrated with PoSLib to perform transactions with Payment application

  1. Merchant Billing Application calls scan & connect IP via PoSLib APIs.
  2. PoSLib will send device discovery request to connect with PoSBridge.
  3. PoSBridge will respond with the device connected status.
  4. Merchant Billing Application will fetch transaction details.
  5. Merchant Billing Application sends the transaction request to PoSLib by calling doTransaction API.
  6. PoSLib will process the doTransaction and forward the transaction request to PoSBridge.
  7. PoSBridge will process the doTransaction request and forward the transaction request to PineLabs Payment Application.
  8. PineLabs Payment Application will process the transaction request and sends the payment request to payment controller for authorization.
  9. Payment controller sends the payment authorization response to PineLabs payment Application.
  10. PineLabs Payment Application will process the payment authorization response and sends the doTransaction response to PoSBridge.
  11. PoSBridge will process the doTransaction response and forward the doTransaction response to PoSLib.
  12. PoSLib will process the doTransaction response and forward the doTransaction response to Merchant Billing Application.

Supported Features

The following features (APIs) are supported by iOS PoSLib:

Supported APIs Functionality / Description
PosLibServicesImpl Create an instance of PosLibServicesImpl and initialize it with the PoSlib. This will be the first step towards calling the API.
scanOnlinePOSDevice This API will be used to discover/scan for PoS devices in same network (Wi-Fi)
setConfiguration This API will be used set the required configuration to PoSLib
getConfiguration This API will be used get the configuration settings from PoSLib
comTest This API will be used to check for TCPIP connection with PoSBridge
doTransaction This API will be used to perform transaction with Payment Application

PoSLib framework Integration

This section describes the pre-requisites and steps to integrate POSLib framework with the Merchant Billing Application.

Pre-requisites
  • Ensure you have latest version PoSLib.
  • Ensure you have latest version of XCode (14.x) installed in your system.

Steps to integrate PoSLib

Step 1: Add generated PosLib.xcframework into the Billing Application for debug and release inside Archives -> Binaries -> extracted file -> PosLib.xcframework.

Step 2: Import iOS PoSLib Framework into frameworks folder which is generated in Archives -> Binaries -> PosLib-Bitcode-Debug -> PosLib.xcframework.
Add PosLib.xcframework from framework folder as an embedded content in Billing application project settings (as shown below).

Step 3: Add Local Network Usage Description, Bonjour Services, Bluetooth Always Usage Description and Supported external accessory protocols to info.plist of the Billing Application.

API Integration

Below section describes the APIs exposed by PoSLib, details of the API and integration sample code snippets.

Note: The sample code snippets provided in this document are currently supported only in Swift. These code snippets might have to be customized if you want to test them on Objective-C.

PosLibServicesImpl

This API shall be used to Initialize the PoSlib. This shall be the first API to be called.

Signature var posLibServices: PosLibServicesImpl()
Description Once we integrate the PoSLib framework. This is the first step we perform to initialize the PosLibSercies which is done in Splash View Controller
Parameters None
Returns Creates the object of PosLibServicesImpl class
Call-backs None
Error Condition None

Code snippet for posLibInitialize:

Initialize PoSLib using the following code:

              

Swift


override func viewDidLoad() { super.viewDidLoad() // Create an instance of PosLibServicesImpl posLibServices = PosLibServicesImpl() // Set the text of the "lblVersion" label to display the application version self.lblVersion.text = "Version: \(posLibServices!.getPosLibVersion())" }

scanOnlinePOSDevice

This API will discover/Scan the PinLabs payment terminals on the same network where PoSBridge is running on it and list them.

Signature func scanOnlinePOSDevice(ransactionListener: self)
Description This API will be used to auto discover/scan for PoS device in same network (Wi-Fi)
Parameters
  • transactionListener
Returns message received
Call-backs state update Handler - state
Error Condition
  • Response timeout
  • Device disconnected
  • COM error
  • Network down

Code snippet for scanOnlinePOSDevice:

            

Swift


@IBAction func scanTCPIPDevices(_ sender: UIButton) { if (networkIP != nil) { // Initiate the scanning process for online POS devices posLibServices!.scanOnlinePOSDevice(transactionListener: self) } else { //Invalid Conditions } }

ConfigData Details

This class will have the details of the device which will be used during discovery/scan over IP.

Code snippet for ConfigData Details

            

Swift


@objc public class ConfigData: NSObject { var cashierID: String = "" var cashierName: String = "" var connectionFallback: Bool = false var connectionPriority: String = "" var connectionTimeout: Int = 0 var connectionRetries: Int = 0 var tcpIP: String = "" var tcpPort: Int var btDeviceName: String = "" var btDeviceSSID: String = "" var networkIpTest: Bool = false; }

setConfiguration

This API will set PoS Library configurations related to connectivity, priority settings, and logging options.

Signature setConfiguration(configData: ConfigData)
Description Set the required configuration to PosLib
Parameters configData - Configuration Data
Returns 0 - Success < 0 - Failure
Call-backs None
Error Condition
  • Invalid IP
  • Invalid port
  • Comm error
  • IP or Port not configured
  • POSLib not initialized

Code snippet for setConfiguration:

            

Swift


func saveConfigurations() { let configData = ConfigData(cashierID: self.settingsItem.cashierID, cashierName: self.settingsItem.cashierName, connectionFallback: self.settingsItem.poslibLogsRequired, connectionPriority: self.settingsItem.connectionPriority, connectionTimeout: self.settingsItem.connectionTimeout, connectionRetries: self.settingsItem.connectionRetries, tcpIP: self.settingsItem.tcpIP, tcpPort: "\(self.settingsItem.tcpPort)", btDeviceName: self.settingsItem.btDeviceName, btDeviceSSID: self.settingsItem.btDeviceSSID) posLibServices!.setConfiguration(configData: configData) }

getConfiguration

This API should be used to retrieve PoS Library configurations related to connectivity, priority settings, and logging options.

Signature getConfiguration() -> ConfigData
Description Gets the configuration settings from PosLib
Parameters None
Returns 0 - Success < 0 - Failure
Call-backs None
Error Condition
  • Invalid IP
  • Invalid port
  • Comm error
  • IP or Port not configured
  • PosLib not initialized

Code snippet for getConfiguration:

            

Swift


@IBAction func testTCPIPConnection(_ sender: UIButton) { if (UserDefaults.standard.bool(forKey: "networkStatus") { let configData = posLibServices!.getConfiguration() } else { //showing alert to enable network to getConfig details and other conditions as well } }

comTest

This API will verify connectivity between the merchant billing system and the iOS payment terminal in IP connectivity mode.

Signature comTest(tcpIp ip: String, tcpPort port: String, transactionListener txnListener: TransactionListener)
Description This API will be used to check for TCPIP connection
Parameters
  • IP - Payment terminal IP
  • Port - POSBridge port
  • transactionListener - TransactionListener
Returns 0 - Success < 0 - Failure
Call-backs None

Code snippet for comTest:

            

Swift


@IBAction func testTCPIPConnection(_ sender: UIButton) { if (networkIP != nil || (UserDefaults.standard.bool(forKey: "networkStatus”))) { posLibServices?.comTest(tcpIp: configData.getTcpIP(), tcpPort: "\(configData.getTcpPort())", transactionListener: self) } else { // Checking Other conditions } }

doTransaction

This API will be used to perform transaction with iOS Payment Application.

Signature func doTransaction(paymentRequest message: String, transactionType txnType: Int, transactionListener txnListener: TransactionListener)
Description This API shall be used for transaction processing with Payment Application
Parameters

paymentRequest - Request message body from billing application.

transactionType = 6 // payment transaction type

Returns None
Call-backs OnSuccess(String paymentResponse)
- paymentResponse data for all the supported transaction types

OnFailure(String errorMsg, int errorCode)
- Error Message
- Error Code
Error Condition • Response timeout
• Parsing error
• Network down
• Comm disconnected

Code snippet for doTransaction:

            

Swift


@IBAction func processTransactionAction(_ sender: UIButton) { var msgType: Int // take required message type for txn to proceed let txnTypeValue = Constant.transactionValuesList[self.selectedTransaction] let csvString = PosHelper.shared.getCSVStringForTxn((txnTypeValue)!, Constant.TXN_NUM, self.amountTextField.text!) let requestBody = PosHelper.shared.getPaymentPacket(csvString) if (requestBody != "") { posLibServices!.doTransaction(paymentRequest: requestBody, transactionType: msgType, transactionListener: self) } else { /*ERROR CONDITIONS*/ } } Note : Please refer Transaction type in API's section for more information click here