Skip to content

End-to-end example

Let’s walk the whole path with one buyer of a game key shop: from the scenario setup to a redeemed discount. Requests and responses have the real shape; responses are trimmed to the fields that matter. The Authorization header and event signatures are left out: the quickstart shows how to set them.

timeline
  title Buyer 4f9a
  3 November : First purchase : progress 1 of 3
  12 November : Second purchase : progress 2 of 3
  20 November : Third purchase : scenario completed, reward pending
  4 December : Delay is over : webhook reward.available, coupon
  6 December : Order with the discount : reserve, then redeem

We do this together with you before you connect. These settings are not in the API: you see their result in the user’s status.

What How it is set up
Event dictionary type order.paid: link key order_id, fields amount, currency, items; refunds order.refunded and order.chargeback point to it by order_id
Scenario collector “Collector” one step: 3 key purchases from 10 AZN (order.paid, metric count), window of any 60 days, once per buyer
Reward template 10% off keys (applies_to: keys), at most 5 AZN; becomes available 14 days after completion, valid for 30 days
Webhook URL https://shop.example.com/aapp/webhooks in test mode

The 14-day delay lets the purchase pass the refund period: if the buyer returns a key earlier, the reward is cancelled before it becomes available.

  1. The buyer signed up. Register them with us. This is optional: the first event would create the user. But this way you can show them the program right away.

    POST /v1/users
    Content-Type: application/json
    { "user_ref": "4f9a" }
    // 201 Created
    { "user_ref": "4f9a", "group": "participant", "attributes": {}, "created_at": "2026-11-01T08:00:00Z" }

    group: participant means the buyer takes part in the program. If they were in the control group, it would be control, and the site would not show them progress.

  2. See what is available to them.

    GET /v1/users/4f9a/status
    Accept-Language: en
    {
    "user_ref": "4f9a",
    "group": "participant",
    "badges": [],
    "scenarios": [{
    "key": "collector",
    "name": "Collector",
    "description": "3 key purchases from 10 AZN within any 60 days",
    "status": "not_started",
    "steps": [{ "name": "Key purchase from 10 AZN", "event": "order.paid", "metric": "count", "current": 0, "target": 3 }]
    }],
    "rewards": []
    }
  3. 3 November: the first purchase. The shop’s server sends the event right after payment.

    POST /v1/events
    {
    "event_id": "evt_90114",
    "type": "order.paid",
    "user_ref": "4f9a",
    "order_id": "ord_78123",
    "occurred_at": "2026-11-03T18:02:11Z",
    "amount": 25.00,
    "currency": "AZN",
    "items": [{ "sku": "game-123", "category": "rpg", "price": 25.00, "qty": 1 }]
    }

    The response is 202 with status: accepted: the event is accepted and will be counted in the background. A couple of seconds later we check:

    GET /v1/events/evt_90114
    {
    "event_id": "evt_90114",
    "status": "processed",
    "scenarios": [{ "scenario_key": "collector", "counted": true }],
    "changes": [
    { "kind": "progress", "scenario_key": "collector", "step": 0, "current": 1, "target": 3 }
    ]
    }
  4. 12 November: the second purchase. Event evt_90207 with order ord_78150, same as before. Progress is now current: 2.

  5. 20 November: the third purchase completes the scenario.

    GET /v1/events/evt_90301
    {
    "event_id": "evt_90301",
    "status": "processed",
    "changes": [
    { "kind": "progress", "scenario_key": "collector", "step": 0, "current": 3, "target": 3 },
    { "kind": "scenario_completed", "scenario_key": "collector", "completion_id": "cmp_5521", "completed_at": "2026-11-20T11:58:40Z" },
    { "kind": "reward_created", "scenario_key": "collector", "completion_id": "cmp_5521", "reward_id": "rw_7731", "reward_status": "pending" }
    ]
    }

    At the same time the scenario.completed webhook arrives. Reward rw_7731 is created but still pending: it waits 14 days. It already shows in the status, with its dates:

    {
    "reward_id": "rw_7731",
    "status": "pending",
    "name": "Collector discount",
    "percent": 10,
    "max_amount": 5.00,
    "currency": "AZN",
    "applies_to": "keys",
    "available_at": "2026-12-04T11:58:40Z",
    "expires_at": "2027-01-03T11:58:40Z"
    }

    The site can tell the buyer: “Your 10% discount becomes available on 4 December”.

  6. 4 December: the reward becomes available. We send a webhook:

    {
    "type": "reward.available",
    "timestamp": "2026-12-04T11:58:40Z",
    "data": { "reward_id": "rw_7731", "user_ref": "4f9a", "version": 2 }
    }

    The shop’s server verifies the signature, answers 204 and, in its own queue, fetches the terms with GET /v1/rewards/rw_7731. With them it creates a coupon in its own system: 10% off keys, at most 5 AZN, until 3 January. Exactly one coupon for rw_7731, even if the webhook arrives again.

  7. 6 December: the buyer checks out a 40 AZN order. On the payment page the site applies the coupon and reserves the reward for the order:

    POST /v1/rewards/rw_7731/reserve
    { "order_id": "ord_79010" }
    // 200
    { "reward_id": "rw_7731", "status": "reserved", "reservation": { "order_id": "ord_79010", "reserved_at": "2026-12-06T09:00:00Z", "expires_at": "2026-12-06T09:30:00Z" } }

    A 409 reward_not_available would mean the discount cannot be applied. If we had not answered in time, the site would place the order without the discount: the Checkout guide explains these cases.

  8. Payment succeeded. Redeem the reward and send the purchase event.

    POST /v1/rewards/rw_7731/redeem
    { "order_id": "ord_79010", "order_amount": 40.00, "discount_amount": 4.00 }
    // 200
    { "reward_id": "rw_7731", "status": "redeemed", "redemption": { "order_id": "ord_79010", "redeemed_at": "2026-12-06T09:03:12Z", "order_amount": 40.00, "discount_amount": 4.00 } }

    And, as usual, order.paid with order_id: ord_79010 and amount: 36.00, the amount after the discount. “Collector” is a one-time scenario, so this purchase no longer moves it, but it can move other scenarios.

Suppose a chargeback arrived for order ord_78150 on 25 November, while the reward was still waiting:

{ "event_id": "evt_90871", "type": "order.chargeback", "user_ref": "4f9a", "order_id": "ord_78150", "occurred_at": "2026-11-25T10:00:00Z" }

The engine excludes the second purchase, progress goes back to 2 of 3, completion cmp_5521 is cancelled and reward rw_7731 moves to cancelled. The reward.cancelled webhook arrives, and if the coupon was already created, disable it. If the buyer makes another purchase within the window, the scenario completes again, with a new reward.