Package com. thanx. sdk. cardEncryption
This package provides methods to encrypt credit cards so you can then send the encrypted PAN to the Thanx API 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 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.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();
}
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.