# Notification Process

## <mark style="color:blue;">Notifications</mark>

A notification will be sent every time the status of a cashout changes.&#x20;

For security reasons, we don't send the status of the cashout on the notification itself. Once you have received the notification, you will need to use the Cashout Status Endpoint to retrieve its new status.

The notifications will be sent to the `notification_url` specified in the request or to the default Withdrawals URL you have configured on the Merchant Panel by **POST** protocol in **x-www-form-urlencoded** format.

## <mark style="color:blue;">STG Testing</mark>

In the STG environment, you can force a notification to be sent to your `notification_url` from the [STG Merchant Panel](https://merchants-stg.directa24.com/login) by going to the `Transactions -> Withdrawals` page, opening the cashout transaction, and clicking on one of the options that will appear when clicking on the three dots button on the top right of the screen. Those options will change the status of the cashout therefore **sending the respective notification after a few minutes**.

<figure><img src="https://content.gitbook.com/content/9pqDQmo5HSlku7L1tVhp/blobs/1HDwgPXFJ5NLIsx4DhmB/image.png" alt=""><figcaption></figcaption></figure>

## <mark style="color:blue;">Notification response</mark>

```json
    date=2020-03-12%2020%3A26%3A11
    &bank_reference_id=
    &comments=
    &external_id=cashoutV35381
    &control=A4CFF64E78C4BD01F8BFCA4AFF04632EC4A33CC61BD6BBD156BA1289897892EB
    &cashout_id=60067
    &status_reason=
```

<table data-header-hidden><thead><tr><th width="170.33333333333331">Field</th><th width="189">Format</th><th>Description</th></tr></thead><tbody><tr><td>Field</td><td>Format</td><td>Description</td></tr><tr><td>date</td><td>Date. Format: YYYY-MM-DD HH:MM:SS (GMT)</td><td>Date the cashout changed its status</td></tr><tr><td>bank_reference_id</td><td>String </td><td><p>(max. 50 chars)</p><p>Reference ID of the bank if any</p></td></tr><tr><td>comments</td><td>String</td><td><p> (max. 200 chars)</p><p>Comments of the cashout if any</p></td></tr><tr><td>external_id</td><td>String</td><td><p> (max. 100 chars)</p><p>ID of the cashout you sent while creating the request</p></td></tr><tr><td>control</td><td>String</td><td>Control signature of the notification</td></tr><tr><td>cashout_id</td><td>Number</td><td>ID of the cashout on our end</td></tr><tr><td>status_reason</td><td>String</td><td>Reason of the status if any</td></tr></tbody></table>

The control string for the notifications is made up of some random characters at the beginning and the end of the request and the `external_id` received in the middle.

{% hint style="info" %}
The control string should be generated using your secret key (API Signature) and should be in uppercase&#x20;

Make sure to hash the message in UTF-8 format to prevent errors.
{% endhint %}

Example:

{% tabs %}
{% tab title="Java" %}

```java
public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
      String external_id = "cashoutID1234";
      String message = "Be4" + external_id + "Bo7";
      String apiSignature = "your_deposits_api_signature";

      Mac hasher = Mac.getInstance("HmacSHA256");
      hasher.init(new SecretKeySpec(apiSignature.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
      byte[] result = hasher.doFinal(message.getBytes(StandardCharsets.UTF_8));

      System.out.println(StringUtils.upperCase(DatatypeConverter.printHexBinary(result)));
}
```

{% endtab %}

{% tab title="PHP" %}

```php
$external_id = 'cashoutID1234';
$message = 'Be4' . $external_id . 'Bo7';
$api_signature = 'cashout_api_signature';

$hash = strtoupper(hash_hmac('sha256', pack('A*', $message), pack('A*', $api_signature)));


```

{% endtab %}

{% tab title="C#" %}

```csharp
string external_id = "cashoutID1234";
 string message = "Be4" + external_id + "Bo7";
 string apiSignature = "your_cashouts_api_signature";
 
 byte[] keyByte = new System.Text.Encoding.UTF8.GetBytes(apiSignature);
 byte[] messageBytes = new System.Text.Encoding.UTF8.GetBytes(message);
 byte[] hashmessage = new HMACSHA256(keyByte).ComputeHash(messageBytes);

 string control = BitConverter.ToString(hashmessage).Replace("-", "").ToUpper();
 
```

{% endtab %}
{% endtabs %}

## <mark style="color:blue;">Retry logic and Resend Notifications</mark>

{% tabs %}
{% tab title="Retry logic" %}
Every time a cashout changes its status, we will send you a notification so you can check its status back.

In case that for some reason your server was unable to receive the notification and you returned an HTTP code different than 2XX, we will retry the notification up to 5 more times or until you respond with HTTP 2XX, whatever comes first.

{% hint style="success" %}
In case of errors while handling the notification, make sure you will answer with an HTTP code distinct than 2XX, that way we will retry the notification.
{% endhint %}
{% endtab %}

{% tab title="Resend Notifications" %}
In case your system was unable to receive the notification in any of the 5 attempts, it can be manually re-sent.

If you need to trigger the check status by receiving our notification, once the issue preventing you from receiving our notifications is fixed, you can go to the Merchant Panel, locate the cashout (Transactions -> Withdrawals), and click on the three dots button under the "Status History" section and then "Resend notification"  to force a new notification to be sent.

{% hint style="success" %}
It can take up to 2 minute for the notification to be resent.
{% endhint %}

<figure><img src="https://content.gitbook.com/content/9pqDQmo5HSlku7L1tVhp/blobs/eL3EFe3WfFDUTLMcNrzv/image.png" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}
