INITIAL GUIDE
Libraries
WEB

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.2.1'
  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, PEN

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

Examples

Find the methods available in our iOS library along with examples.

One-Time Payment Examples

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",
    months: 2
}) {
        let publicMerchantId = "public-merchant-id"
        let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "USD",
                            environment: KushkiEnvironment.testing,
                            false)//optional parameter regional
        kushki.requestToken(card: card, totalAmount: 19.99) { 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

getCardInfo()

Returns an object with the information related to the credit card bin (first six digits). For Chilean merchants, the response is helpfull to decide wheter to continue with the request of a card token (when cardType is CREDIT), or with the request of a card async token (when cardType is DEBIT):

Request

private func requestCardInfo(cardNumber: "4242424242424242") {
        let publicMerchantId = "public-merchant-id"
        let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "USD",
                            environment: KushkiEnvironment.testing)
        kushki.getCardInfo(cardNumber: cardNumber){ cardInfo in
            let message = "\nBank: "+cardInfo.bank + "\nBrand: " + cardInfo.brand + "\nCard type: " + cardInfo.cardType
            DispatchQueue.main.sync(execute: {
                let alert = UIAlertController(title: "Get Card Info response",
                                              message: message,
                                        preferredStyle: UIAlertController.Style.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .default))
                self.present(alert, animated: true)
            })
            self.ResponseView.text = "Get card info response: \n\n" + message
        }
    }

Required

Property Type Description
cardNumber String The credit card number to get the info

Subscriptions Examples

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

Payouts Examples

requestCashOutToken()

To request a Cash Out token, you can use this method

private func requestKushkiToken(name : String, lastName: String, identification: String, documentType: String, totalAmount: String, email: String) {
        let publicMerchantId = "publicMerchantId"
        let kushki = Kushki(publicMerchantId: publicMerchantId,
                            currency: "COP",
                            environment: KushkiEnvironment.testing)
        kushki.requestCashOutToken(name: name, lastName: lastName, identification: identification, documentType: documentType, totalAmount: Double(totalAmount) ?? 0.0, email: email) { transaction in
            let message = transaction.isSuccessful() ?
                transaction.token : transaction.code + ": " + transaction.message
            //                transaction.code + ": " + transaction.message
            DispatchQueue.main.async(execute: {
                let alert = UIAlertController(title: "Kushki Token request",
                                              message: message,
                                              preferredStyle: UIAlertController.Style.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: .default))
                self.present(alert, animated: true)
            })
            self.ResponseView.text = "Token response: \n\n" + message
        }
    }

Required

Property Type Description Possible Values
name String Name of the client
lastName String Last name of the client
documentType String Type of document that the client is using to pay. CC, NIT, CE, TI, PP
identification String Document number that the client is using to pay
totalAmount Number The amount you are going to collect as a number
currency String Code of currency used COP

Optional

Property Type Description
email String Email address of the client
description String A description of the payment

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 finish the payment process, please go to out API Reference


Reference

Find the methods available in our iOS library. You can perform the following operations:

One-time Payment:

  • Create a Card token
  • Get Bin Info
  • Create a Card Async Token
  • Create a Transfer In token
  • Create a Cash In token

Subscriptions:

  • Create a Card Subscription token
  • Get an Async Card Subscription
  • Get a list of banks available for subscriptions with wire transfer debit
  • Create a transfer subscription token
  • Start and answer a challenge to validate the account data in transfer subscriptions

Payouts:

  • Create a Cash Out token

One-time Payment

Name Parameters Returns Description
requestToken() card, totalAmount, months Object Returns a card token
getCardInfo() cardNumber Object Returns an object with the information related to the credit card bin
requestCardAsyncToken() totalAmount, returnUrl, email, description Object Returns a card async token
requestTransferToken() amount, callbackUrl, documentType, documentNumber, email, description, userType Object Returns a transfer in token
requestCashToken() totalAmount, currency, identification, documentType, name, lastName, email, description Object Returns a cash in token that can later be used to initialize a cash in transaction

Subscriptions

Name Parameters Returns Description
requestSubscriptionToken() card Object Returns a subscription token
requestSubscriptionCardAsyncToken currency, email, cardNumber, callbackUrl Object Returns an async card subscription token
getBankList() Object Returns a list of banks available for transfer subscriptions
requestTransferSubscriptionToken() documentNumber, bankCode, name, lastName, accountNumber, documentType, accountType, email, currency Object Returns a token along with a secureId, and secureService. The token can later be used to create a transfer subscription. Before that, you will need to confirm the account data by starting and asnwering a challenge with the secure validation method
requestSecureValidation() On first call: secureService, secureServiceId, cityCode, stateCode, phone, expeditionDocumentDate. On second call: secureService, secureServiceId, questionnaireCode, answers (JSON Object) Object On first call, returns a questionnaire for the challenge. On second call, returns a code and a message with the results of the account verification

Payouts

Name Parameters Returns Description
requestCashOutToken() totalAmount, currency, identification, documentType, name, lastName, email, description Object Returns a cash out token that can later be used to initialize a cash out transaction

Example Application

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