Direct Card Payment

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.

{
    "full_name": "John Doe",
    "card_no": "0123456789123456",
    "exp_month": "06",
    "exp_year": "22",
    "cvv": "123",
    "pin": "1234",
    "billing_address": "Second Street",
    "billing_city": "San Francisco",
    "billing_zip": "94105",
    "billing_state": "CA",
    "billing_country": "US"
}

>>Getting a list of billing countries

To get a list of the available billing countries to use when composing the JSON card details string above, use the API description that follows

// sandbox
GET https://sandbox.dusupay.com/v1/avs-countries

Request

Header

Value

Required

secret-key

SEC-*** Your Merchant secret key

YES

2. Encrypt the JSON String

To encrypt the JSON string correctly, we have organized a few code samples to illustrate how it could be done as shown below.

>> Downloading Public Key

// sandbox
GET https://sandbox.dusupay.com/v1/download-public-key

Request Header

Header

Value

Required

secret-key

SEC-*** Your Merchant secret key

YES

Download our public key for encryption.

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

const crypto = require('crypto');
const fs = require('fs');

const data = {
        full_name: "John Doe",
        card_no: "0123456789123456",
        exp_month: "06",
        exp_year: "22",
        cvv: "123"
    };

function encryptData(data) {
    const payload = JSON.stringify(data);
    const publicKeyFile = "path-to-file/dusupay.public.key.pem";
    const publicKey = fs.readFileSync(publicKeyFile).toString().replace(/\\n/g, '\n');

    const encryptedData = crypto.publicEncrypt(
        {
            key: publicKey,
            padding: crypto.constants.RSA_PKCS1_PADDING
        },
        Buffer.from(payload)
    );

    /*return the base64 encoded version of the encrypted string*/
    return encryptedData.toString("base64");
}

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

Last updated