Callback

purchaseProductIdEvery time when the user makes withdrawal, Enabl3 will send callback request to the Application backend with details.

There are two types of withdrawals:

  • with withdrawal options, e.g. subscriptions (predefined amount)

  • custom withdrawal (custom amount)

You need to create POST endpoint on your backend side, which will be requested by Enabl3.

Request body example:

{ 
  "userId": "14813ccc-83b6-11ee-b962-0242ac120002", 
  "optionId": "97cf7320-25f0-485d-a2c9-2ae60c05574e",
  "purchaseProductId": "product123", 
  "amount": 100.00, 
  "tokenAmount": 500.00,
  "tokenRate": 5.0,
  "transactionId": "709a45bd-2b9a-452d-9ae2-a9aa479c29e6",
  "createdAt" : "2024-05-30T12:14:40.988257"
}

Body

Callback request will be signed and contains X-REQUEST-SIGNATURE header.

The example of how to get signature of request body using secret:

For Java

public String getSignature(String requestBody, String secret) {
    String md5Hex = DigestUtils.md5Hex(requestBody);
    try {
        Mac shaHMAC = Mac.getInstance("HmacSHA512");
        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA512");
        shaHMAC.init(secretKey);
        return Base64.getEncoder().encodeToString(shaHMAC.doFinal(md5Hex.getBytes()));
    } catch (GeneralSecurityException ex) {
        log.error(ex.getMessage(), ex);
        throw new RuntimeException("Request signing error", ex);
    }
}

For Node JS

const crypto = require('crypto');

function getSignature(requestBody, secret) {
  const md5Hex = crypto.createHash('md5').update(requestBody).digest('hex');
  const hmac = crypto.createHmac('sha512', secret);
  const signature = hmac.update(md5Hex).digest('base64');
 
  return signature;
}

const requestBody = 'your_request_body';
const secret = 'your_secret_key';
const signature = getSignature(requestBody, secret);

console.log(signature);

Last updated