Skip to content

tranzzo/ios-card-tokenizer

Repository files navigation

Tranzzo Tokenizer

CocoaPods Compatible Carthage compatible License Platform

Requirements

  • iOS 8+
  • Swift 5+

Installation

CocoaPods

To integrate TranzzoTokenizer into your Xcode project using CocoaPods, add it to your Podfile:

pod 'TranzzoTokenizer'

Then, run the following command:

$ pod install

Carthage

To integrate TranzzoTokenizer into your Xcode project using Carthage, add it to your Cartfile:

github "https://github.com/tranzzo/ios-card-tokenizer.git"

Then, run the following command:

$ carthage update

Then drag TranzzoTokenizer.framework into your Xcode project.

Features

Tokenization: Simple way to obtain a Tranzzo user card token, generated on our servers. For more information visit our documentation Validation: Use straightforward card utilities to validate, define and format your card input

Usage

Tokenization

  1. Import TranzzoTokenizer framework header

    import TranzzoTokenizer
  2. Initialize the tokenizer for an environment you are working with

    let tokenizer = TranzzoTokenizer(apiKey: apiKey, environment: environment)

    Make sure to replace appKey with your application key. If you are already using Tranzzo Widget then you can use key parameter value. Otherwise, you need to be signed up to Tranzzo Services and obtain you appKey from the Tranzzo dashboard.

    Choose your environment depending on your needs. If you need to test your workflow in a SandBox mode, you should use .stage

  3. Construct a card data with your user's card information

    let card = CardRequestData(
        cardNumber: "4242424242424242",
        cardExpMonth: 12,
        cardExpYear: 22,
        cardCvv: "123"
    )
  4. In case you want to receive a single token for your card, use this method

    tokenizer.tokenize(card: card) { (result: Result<TranzzoTokenSuccess, TranzzoError>) in
        switch result {
        case .success(let tokenData):
            // Process your token
        case .failure(let error):
            // Handle an error
        }
    }

    If you want to receive additional card data with your token, like expiration date and card mask, use the following:

    tokenizer.tokenizeEncrypt(card: card) { (result: Result<TranzzoTokenDataSuccess, TranzzoError>) in
        switch result {
        case .success(let encryptedData):
            // Process your encrypted token data
        case .failure(let error):
            // Handle an error
        }
    }

Read our decryption guide to learn more about encryptedData

Validation

Use TranzzoCardValidator to validate your user's card input, such as number, cvv and expiration date.

let validator = TranzzoCardValidator()
let numberIsValid = validator.isValid(cardNumber: cardNumber)

Specify CardProvider to validate it's cvv.

let cvvIsValid = validator.isValid(cvv: "123", for: .visa)

Get the provider of a card by it's full number

let provider = validator.getCardType(for: "4222222222222222") // .visa

or by it's prefix (length depends on specific provider)

let provider = validator.getPartialCardType(for: "5455") // .mastercard