Skip to content

techquest/isw-mobile-sdk-ios

Repository files navigation

Interswitch Payment SDK

This library aids in processing payment through the following channels

  • Card
  • Verve Wallet
  • QR Code
  • USSD

Usage

There are three steps you would have to complete to set up the SDK and perform transaction

  • Install the SDK as a dependency
  • Configure the SDK with Merchant Information
  • Initiate payment with customer details

Installation

  1. Go to releases, click on assets of the latest version and download the zip of IswMobileSdk.xcframework
  2. Unzip to find the IswMobileSdk.xcframework, and move it to your project folder
  3. Open your project in Xcode, and navigate to the General settings of your project
  4. Choose your app in TARGETS, then in General settings, under Framework, Libraries and Embeded Content, click the + sign to add library
  5. In the popup window, click Add Other -> Add Files, and navigate to the foler where you have the IswMobileSdk.xcframework folder and choose it
  6. Now build the project

Add the following import statment to the file where you want to use the library:

    import IswMobileSdk

Configuration

You would need to configure the SDK and there are two ways to configure the SDK.

  1. By providing your merchant details for the SDK You would also need to configure the SDK with your merchant credentials. Which could be done in your AppDelegate or your root ViewController.
    let merchantCode = "<your merchantCode>"
    let clientSecret = "<your clientSecret>"
    let clientId = "<your clientId>"
    let currencyCode = "566"
    let env: Environment = .sandbox

    // create merchant configuration
    let config = IswSdkConfig(
        clientId: clientId, 
        clientSecret: clientSecret,
        currencyCode: currencyCode, 
        merchantCode: merchantCode
    )

    // initialize sdk
    IswMobileSdk.intialize(config: config, env: env)
  1. By providing an access token string, that is generated by your server, to the SDK.
        // set transaction environment & currency code 
        let env: Environment = .sandbox
        let currencyCode = "566"
        
        // create config with currency code
        let config = IswSdkConfig(currencyCode: currencyCode)

        // initialize sdk
        IswMobileSdk.intialize(config: config, env: env)
        
        // then in the next step,
        // when triggering payment,
        // provide the string access token
        // Note: more explained in next step
        let info = IswPaymentInfo(...)
        
        // set access token in the payment info
        info.with(accessToken: sampleAccessToken)
        
        // ... then trigger txn to be processed

Once the SDK has been initialized, you can then perform transactions.

Performing Transactions

You can perform a transaction, once the SDK is configured, like so:

  1. First you would need to have you view controller implement the IswPaymentDelegate protocol
extension ViewController: IswPaymentDelegate {
    // user cancelled payment without completion
    func onUserDidCancel() {
        // handle cancellation
    }
    
    // user completed the payment
    func onUserDidCompletePayment(result: IswPaymentResult) {
        // handle payment result
    }
}
  1. Once you have setup the delegate, you can trigger payments
    @IBAction func onPayTapped(_ sender: Any) {
    
        let customerId = "<customer-id>",
            customerName = "<customer-name>",
            customerEmail = "<customer.email@domain.com>",
            customerMobile = "<customer-phone>",
            // generate a unique random
            // reference for each transaction
            reference = "<your-unique-ref>";
                        
        // amount in kobo e.g. "N500.00" -> 50000
        let amount = providedAmount; // e.g. 50000

        // create payment info
        let info = IswPaymentInfo(
            customerId: customerId,
            customerName: customerName,
            customerEmail: customerEmail, 
            customerMobile: customerMobile,
            reference: reference, 
            amount: amount
        )
        
        // Note: If you have split settlement accounts,
        // you can create payment info with the variant
        // constructor that takes split settlement accounts
        // list of accounts 'IswSettlementAccount' 
        let settlementAccounts = [
            IswSettlementAccount(alias: "pacct", amount: 0, percentage: 63.79, description: "primary account", isPrimary: true),
            IswSettlementAccount(alias: "sacct", amount: 0, percentage: 36.21, description: "secondary account", isPrimary: false)
        ]
        
        let info = IswPaymentInfo(
            customerId: customerId,
            customerName: customerName,
            customerEmail: customerEmail, 
            customerMobile: customerMobile,
            reference: reference, 
            amount: amount,
            settlementAccounts: settlementAccounts)
        )
    
        // Note: If access tokens are generated from your server,
        // set access token in the payment info
        info.with(accessToken: sampleAccessToken)
        
        // trigger payment
        // parameters
        // -- on: the UIViewController triggering payment
        // -- with: the payment information to be processed
        // -- call: the IswPaymentDelegate that receives the result
        IswMobileSdk.pay(on: self, with: info, call: self)
    }

Handling Result

To process the result received onUserDidCompletePayment callback, here are the fields' attributes of the IswPaymentResult

Field Type meaning
responseCode String txn response code
responseDescription String txn response code description
isSuccessful boolean flag indicates if txn is successful
transactionReference String reference for txn
amount int txn amount
channel PaymentChannel channel used to make payment: one of card, wallet, qr, or ussd

And that is it you can start processing payment in your iOS app.