Thanx SDK iOS
Installation
The instructions below detail how to install the library via Cocoapods.
Additionally, you can download the binary .framework
file and manually link it to your project.
Cocoapods
- The Thanx SDK is hosted in a private Cocoapods Spec repo so you first need to add it.
>> pod repo add thanx-ios-specs https://github.com/thanx/thanx-ios-spec.git
- Add the source at the top of your
Podfile
and theThanxSDK
pod within your target.
# Podfile
source 'https://github.com/thanx/thanx-ios-spec.git'
target 'SDKSampleApp' do
use_frameworks!
pod 'ThanxSDK'
end
Generate a new Github token with the user that has been invited to the Thanx repositories.
Set the environmental variable
GITHUB_TOKEN
with the newly generated token and then runbundle exec pod install
.
>> GITHUB_TOKEN=1234567890 bundle exec pod install
Usage
In order to use the SDK, you must first import the module at the top of any files that you intend to utilize it.
# MyClass.swift
import ThanxSDK
Card Encryption
The SDK provides methods to encrypt credit cards so you can then send them via the Thanx API to create and enroll a card into the loyalty platform.
Important! Do not send plain credit card numbers to the Thanx API.
For following methods to work, you must first get the encryption details via the Thanx API GET signature endpoint. This endpoint provides the necessary public key for the encryption as well as the additional uid
for Visa cards.
Visa
To encrypt Visa cards, you will need the public key and the uid
from the signature endpoint. Once you have have that information, use these steps to generate the encrypted pan.
# VisaEncryption.swift
let publicKey: String = "" # from the signature details
let uid: String = "" # from the signature details
let cardNumber: String = "" # from your application user form.
let encryptedPan = Thanx.CardEncryption(
type: .visa,
publicKey: publicKey,
userId: uid
).encrypt(
number: cardNumber
)
Mastercard
For Mastercard encryption, you only need the public key from the signature endpoint.
# MastercardEncryption.swift
let publicKey: String = "" # from the signature details
let cardNumber: String = "" # from your application user form
let encryptedPan = Thanx.CardEncryption(
type: .mastercard,
publicKey: publicKey
).encrypt(
number: cardNumber
)
Amex
For Amex encryption, you only need the public key from the signature endpoint.
# AmexEncryption.swift
let publicKey: String = "" # from the signature details
let cardNumber: String = "" # from your application user form
let encryptedPan = Thanx.CardEncryption(
type: .amex,
publicKey: publicKey
).encrypt(
number: cardNumber
)
Note: Credit card numbers passed to the encrypt
method must first be sanitized of all non-numeric characters – this means no spaces!
Once you have the encryptedPan
, you can send it to the create card endpoint as the encrypted_pan
parameter.