> For the complete documentation index, see [llms.txt](https://docs.clickwall.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clickwall.net/postback.md).

# Postback

Experience a seamless journey towards setting up your own Postback as we walk you through each step, providing comprehensive guidance along the way.

{% hint style="info" %}
What The Postback?

When a user successfully completes an offer, we immediately trigger a call to the Postback URL you have provided in your placement. This call contains all the relevant information required to credit your users, serving as a real-time notification to your server.
{% endhint %}

Postback Parameter

<table data-header-hidden data-full-width="false"><thead><tr><th width="168">Header 1</th><th width="428.3333333333333">Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td>Parameter</td><td>DESCRIPTION</td><td>EXAMPLE</td></tr><tr><td>{user_id}</td><td>This is the unique identifier code of the user who completed action on your platform.</td><td>varchar (25)</td></tr><tr><td>{offer_name}</td><td>The Name of the offer completed.</td><td>varchar (255)<br></td></tr><tr><td>{amount}</td><td>The amount of your virtual currency to be credited to your user.</td><td>99999</td></tr><tr><td>{payout}</td><td>Amount in USD that you earned for this conversion.</td><td>100.5</td></tr><tr><td>{user_ip}</td><td>IP address of the user that completed the offer.</td><td>1.1.1.1</td></tr><tr><td>{txid}</td><td>Unique ID of the conversion generated by ClickWall.</td><td>sdf8sd7fs</td></tr><tr><td>{offer_id}</td><td>Display number in our system</td><td>varchar (50)</td></tr><tr><td>{status}</td><td>Transaction status (<mark style="color:$danger;">completed</mark> for rewards, <mark style="color:$danger;">rejected</mark> for reversals)</td><td>completed</td></tr><tr><td>{sig}</td><td>HMAC-SHA256 signature for security verification</td><td>4a3f2b...</td></tr></tbody></table>

### Example Postback URL <a href="#example-postback-url" id="example-postback-url"></a>

```url
https://example.com/postback/clickwall.php?user_id={user_id}&payout={payout}&amount={amount}&offer_name={offer_name}&user_ip={user_ip}&txid={txid}
```

We expect a response with a status code of **Ok** or **1** to indicate that the retransmission was received successfully.

### PHP Example <a href="#php-example" id="php-example"></a>

```php
<?php
                    /*!
                     * ClickWall LLC
                     * http://clickwall.net
                     * mail@dclickwall.net
                     * Demo: https://example.com/postback/clickwall.php?user_id={user_id}&amount={amount}&offer_name={offer_name}&user_ip={user_ip}
                     */

                    // Include the initialization file
                    include_once("../admin/core/init.inc.php");

                    // Get data from the request
                    $user_id = $_REQUEST['user_id'];
                    $amount = $_REQUEST['amount'];
                    $offerName = $_REQUEST['offer_name'];
                    $user_ip = $_REQUEST['user_ip'];

                    // Get the current timestamp
                    $timeCurrent = time();

                    // Initialize the functions object
                    $configs = new functions($dbo);

                    // Define the event type
                    $type = "ClickWall: Offername: $offerName . IP: $user_ip";

                    // Create an account object and retrieve user data
                    $account = new account($dbo, 1);
                    $userdata = $account->getuserdata($user_id);

                    // Calculate the new user balance
                    $newBalance = $userdata['points'] + $amount;

                    // Update user Points
                    $sql = "UPDATE users SET points = '$newBalance' WHERE login = '$user_id'";
                    $stmt = $dbo->prepare($sql);
                    $stmt->execute();

                    // Update user Tracker
                    $sql = "INSERT INTO tracker(username, points, type, date) values ('$user_id', '$amount', '$type', '$timeCurrent')";
                    $stmt = $dbo->prepare($sql);
                    $stmt->execute();

                    if ($stmt) {
                        echo "OK";
                    }
                    

                    ?>
```

#### 🔐 Postback Signature Verification (HMAC-SHA256)

To protect your callback endpoint against fraudulent requests, ClickWall signs all postback requests using **HMAC-SHA256** and your unique **Postback Secret Key**.

**How to verify the signature:**

1. Copy your **Postback Secret Key** from your App settings inside the ClickWall publisher dashboard.
2. Build the payload string using the exact parameter values received, in this **strict order**: `user_id={user_id}&oid={offer_id}&amount={amount}&tx_id={txid}`
3. Compute the HMAC-SHA256 hash using your secret key and compare it to the received `sig` parameter:

```php
$secret_key = "YOUR_POSTBACK_SECRET_KEY";
$received_sig = $_GET['sig'] ?? '';

// Build payload string in strict order:
$payload = "user_id=" . $_GET['user_id'] . 
           "&oid=" . $_GET['offer_id'] . 
           "&amount=" . $_GET['amount'] . 
           "&tx_id=" . $_GET['txid'];

$expected_sig = hash_hmac('sha256', $payload, $secret_key);

if (!hash_equals($expected_sig, $received_sig)) {
    http_response_code(403);
    die("Invalid Signature");
}

// Signature is valid -> Credit the user
echo "1";
```
