INITIAL GUIDE
Libraries
COLLECTING PAYMENTS
WEB
CHARGES

Kushki iOS

The Kushki library for iOS allows you to collect payments easily and safely in your iOS mobile application.

Install and configure

  1. If you haven’t already installed, here there is the latest version of CocoaPods.

  2. Include the library in your project, add this line to your Podfile:

pod 'Kushki', '~> 2.1.5'
  1. Run the following command:
Terminal
pod install
  1. To update to our last version:
Terminal
pod update Kushki

Usage

After you finished installing, create your Kushki, it will allow you to perform all the methods available in iOS.

let publicMerchantId = "public-merchant-id"
let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "USD",
                            environment: KushkiEnvironment.testing,false)

Required

Property Type Description Default Possible Values
publicMerchantId String Kushki ID created for your merchant
currency String Code of currency useds USD USD, COP, CLP, UF

Optional

Property Type Description Default Possible Values
environment Enum Value to define if you are in production or test environment KushkiEnvironment.production KushkiEnvironment.production , KushkiEnvironment.testing
regional Boolean Define if use a static IP to Kushki access false true,false

Reference

Find methods available in the chart. They allow you to make this operations:

  • Create Card token
  • Create a Subscription token
iOS Methods
Name Parameters Returns Description
requestToken() card, totalAmount, months Object Returns a token
requestSubscriptionToken() card Object Returns a subscription token

requestToken()

To request a token you can use this method

import UIKit
import Kushki
class ViewController: UIViewController {
    // ...
    private func requestToken(card: { //Example of what is expected in the card object
    name: "Juan Guerra",
    number: "4544980425511225",
    cvc: "345",
    expiryMonth: "12",
    expiryYear: "28"
}) {
        let publicMerchantId = "tu-id-público-de-comercio"
        let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "USD",
                            environment: KushkiEnvironment.testing,
                            false)//optional parameter regional
        kushki.requestToken(card: card, totalAmount: 19.99, months:3) { transaction in
            let message = transaction.isSuccessful() ?
                transaction.token :
                transaction.code + ": " + transaction.message
            DispatchQueue.main.async(execute: {
                let alert = UIAlertController(title: "Kushki Token",
                                              message: message,
                                              preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .default))
                self.present(alert, animated: true)
            })
        }
    }

Required

Property Type Description
card Object The card data collected in an card object
totalAmount Double The amount you are going to collect as a string

Optional

Property Type Description
months Integer Number of months. Only available in Chile for deferred transactions

requestSubscriptionToken()

To request a subscription token you can use this method

    private func requestSubscriptionToken(card: { //Example of what is expected in the card object
    name: "Juan Guerra",
    number: "4544980425511225",
    cvc: "345",
    expiryMonth: "12",
    expiryYear: "28"
}) {
        let publicMerchantId = "public-merchant-id"
        let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "USD",
                            environment: KushkiEnvironment.testing,
                            false)//optional parameter regional
        kushki.requestSubscriptionToken(card: card)
            {DispatchQueue.main.async(execute: {
                let alert = UIAlertController(title: "Kushki Token",
                                              message: message,
                                              preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .default))
                self.present(alert, animated: true)
            })
          }
    }

Required

Property Type Description
card Object The card data collected in an card object
totalAmount String The amount you are going to collect as a string

The DispatchQueue class with the async instance method to process the result of the requestToken or requestSubscriptionToken method. You will receive a Transaction object once the call to Kushki has completed; if it was successful, the token will be available in its token property.

Next Steps

Remember that to continue with the payment flow you must send to your servers the token received as shown in the example code as an alert.

To start the charge process, please go to our backend integrations: Kushki Libraries or Kushki API

Example Application

You can find an example application in GitHub iOS project repository.