# Callback

Every time when the user makes withdrawal, Enable3 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 Enable3.

#### **Request body example:**

```json
{ 
  "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**

<table><thead><tr><th width="188">Name</th><th width="107">Type</th><th width="125">Mandatory</th><th>Description</th></tr></thead><tbody><tr><td>userId</td><td>String</td><td>Yes</td><td>Unique user ID on the Application side</td></tr><tr><td>optionId</td><td>String</td><td>No</td><td>This filed will be empty in case of custom withdrawal</td></tr><tr><td>purchaseProductId</td><td>String</td><td>No</td><td>You can assign here your own value in Admin panel</td></tr><tr><td>amount</td><td> Number</td><td>Yes</td><td> Amount in USDC</td></tr><tr><td>tokenAmount</td><td>Number</td><td>Yes</td><td>Amount in tokens</td></tr><tr><td>tokenRate</td><td>Number</td><td>Yes</td><td>Token rate</td></tr><tr><td>transactionId</td><td>String</td><td>Yes</td><td>Unique tx id from the Enable3 side. You can find this TX in the admin panel.</td></tr><tr><td>createdAt</td><td>String</td><td>Yes</td><td><p>The date time when user requested withdrawal.</p><p>Date format: </p><p><code>yyyy-MM-dd'T'HH:mm:ss.SSSSSS</code></p></td></tr></tbody></table>

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**

```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

```javascript
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);
```
