1. SDKs
  2. Android

Our SDK docs are programmatically generated, so to guarantee you’re viewing the most up-to-date version of our docs, you can visit this site. The docs (below) are regularly updated and have been replicated here for your convenience.

Installation

The Thanx Android SDK is distributed via a public github packages maven repository. Github requires authentication even for public packages, so you must generate a token with the read:packages scope and configure the repo with credentials in your build.gradle file. See github’s documentation for more details

One way to store these credentials is in a gradle.properties file.

# gradle.properties
ghr.user=<your_github_username>
ghr.key=<your_github_token>

Next, you need to include the SDK in your app level Gradle dependencies.

build.gradle
dependencies {
  implementation 'com.thanx.sdk:thanx-sdk-android:1.0.0
}

Since the SDK is written in Kotlin, any Android projects written in Java must include the Kotlin Standard Library as a dependency.

build.gradle
dependencies {
  implementation 'com.thanx.sdk:thanx-sdk-android:1.0.0'
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10"
}

Card Encryption

This package (com.thanx.sdk.cardEncryption) provides methods to encrypt credit cards so you can then send the encrypted PAN to the POST /cards API endpoint to create and enroll a card into the loyalty platform.

Important! Do not send plaintext credit card numbers to the Thanx API.

For the following methods to work, you must first get the encryption details via the GET /card_signature endpoint. This endpoint provides the necessary public key for the encryption as well as the additional uid for Visa cards.

Credit card numbers passed to the encrypt method must first be sanitized of all non-numeric characters – this means no spaces!

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.java
String publicKey = "" // from the signature details
String uid = "" // from the signature details
String cardNumber = "" // from your application user form

try {
  CardEncryption thanxCardEncryption = new CardEncryption(
    CardEncryption.CardType.VISA,
    publicKey,
    uid
  );

  thanxCardEncryption.encrypt(cardNumber);
} catch (CardEncryption.EncryptionError encryptionError) {
  encryptionError.getMessage();
}

Mastercard

For Mastercard encryption, you only need the public key from the signature endpoint.

MastercardEncryption.java
String publicKey = "" // from the signature details
String cardNumber = "" // from your application user form

try {
  CardEncryption thanxCardEncryption = new CardEncryption(
    CardEncryption.CardType.MASTERCARD,
    publicKey,
    null
  );

  thanxCardEncryption.encrypt(cardNumber);
} catch (CardEncryption.EncryptionError encryptionError) {
  encryptionError.getMessage();
}

Amex

For Amex encryption, you only need the public key from the signature endpoint.

AmexEncryption.java
String publicKey = "" // from the signature details
String cardNumber = "" // from your application user form

try {
  CardEncryption thanxCardEncryption = new CardEncryption(
    CardEncryption.CardType.AMEX,
    publicKey,
    null
  );

  thanxCardEncryption.encrypt(cardNumber);
} catch (CardEncryption.EncryptionError encryptionError) {
  encryptionError.getMessage();
}

Submission

Once you have the encryptedPan, you can send it to the POST /cards as the encrypted_pan parameter.