Introduction
When you call the direct card charge endpoint yourself, encrypt the card details before you send the request.
Please Note
You do not need to encrypt the payload yourself if you use a backend SDK. Pass your encryption key when you set up the library, and it encrypts the payload before sending the request.
To encrypt your payload manually, you will need an encryption key from the Settings > API section of your dashboard. This uses the 3DES algorithm to encrypt the payload.
Below is an example of an encryption function in different languages. In each case, the function takes the payload as a hash, converts it to JSON, encrypts and encodes it in base64:
Javascript
function encrypt(encryptionKey, payload) {
const text = JSON.stringify(payload);
const forge = require("node-forge");
const cipher = forge.cipher.createCipher(
"3DES-ECB",
forge.util.createBuffer(encryptionKey)
);
cipher.start({iv: ""});
cipher.update(forge.util.createBuffer(text, "utf-8"));
cipher.finish();
const encrypted = cipher.output;
return forge.util.encode64(encrypted.getBytes());
}