These are server to server card payments where you send encrypted card details directed to our server within the request body.
We support direct card collection requests. This means that as a merchant, you can create a payment form on your interface and then send the card details within the request body.
Card data is not sent in plain text but rather as an encrypted string.
To make direct card payments, you are required to provide an extra parameter in the request body, card_cipher
Generating data for the card_cipher parameter
Encryption
1. Create a JSON String With Card Details
A JSON string with data keys like those that follow should be created in that order. This includes the card details as shown below.
First Download the public key and store it in a text file named dusupay.public.key.pem. This will be used to encrypt the card details included in the JSON string created earlier.
>> Encryption Code Samples
constcrypto=require('crypto');constfs=require('fs');constdata= { full_name:"John Doe", card_no:"0123456789123456", exp_month:"06", exp_year:"22", cvv:"123" };functionencryptData(data) {constpayload=JSON.stringify(data);constpublicKeyFile="path-to-file/dusupay.public.key.pem";constpublicKey=fs.readFileSync(publicKeyFile).toString().replace(/\\n/g,'\n');constencryptedData=crypto.publicEncrypt( { key: publicKey, padding:crypto.constants.RSA_PKCS1_PADDING },Buffer.from(payload) );/*return the base64 encoded version of the encrypted string*/returnencryptedData.toString("base64");}
<?phppublicfunctionencryptData($jsonString) { $file ="path-to-file/dusupay.public.key.pem"; $keyContent =file_get_contents($file); $publicKey =openssl_get_publickey($keyContent); $ret =null;if (openssl_public_encrypt($jsonString, $result, $publicKey, OPENSSL_PKCS1_PADDING)) {/*get the base64 encoded version of the encrypted string*/ $ret =base64_encode(''. $result); }return $ret;}?>
Set card_cipher parameter
Now that we have encrypted the card details. The resultant string after encryption is what we need to set as the card_cipher and include it in the Post Collection Request when making a Card Collection Request
{..."card_cipher": "***"...}
By simply including the parameter, card_cipher in the collection request body, is enough for Dusupay to know that you want to make a direct card payment.
Since it's 3D by default, it will return the bank authentication URL where you will redirect the customer.
In the future when we support 2D cards, we will simply charge the card as expected and the payment_url response parameter will be empty