How to Use iOS SDK

Initiating Xendit object

Before using the SDK, you need to set your public API key into the Xendit object

Xendit.publishableKey = "YOUR_PUBLIC_API_KEY" 

Create Credit Card Token

To create token, you first need to create Card object, the information should be collected from your card form interface in your own application. To instantiate Card object you need:

  1. Credit card number
  2. Credit card expiry month (MM)
  3. Credit card expiry year (YYYY)
  4. Credit card verification number (3 numbers in the back)
let cardData = CardData()
cardData.cardNumber = "4000000000000002"
cardData.cardExpMonth = "12"
cardData.cardExpYear = "2017"
cardData.cardCvn = "123"
cardData.isMultipleUse = true

After creating the object, you need to call createToken. In case you are creating a single use token, you will also get _authentication ID _as the success response.

Xendit.createToken(fromViewController: self, cardData: cardData) { (token, error) in
  if (error != nil){
    // Handle error. Error is of type XenditError
   // Handle successful tokenization. Token is of type XenditCCToken

Create Authentication (3DS)

For multiple use token, you need to separately call createAuthentication method using the token ID that you get from createToken method. During the authentication process, we will display a webview in front of your application for user to securely do the OTP (one time password) or any other means of authentication depending on the issuing bank.

let tokenID = "sample-token-id"
let amount = 75000

Xendit.createAuthentication(fromViewController: self, tokenId: tokenID!, amount: amount) { (authentication, error) in
  DispatchQueue.main.async {

  if (error != nil){
     // Handle error. Error is of type XenditError

  // Handle successful authentication


iOS SDK Limitation

  • Swift version: Swift 5.1
  • iOS minimum version: 8

Last Updated on 2023-06-02