Skip to content

Checkout

The main rule: checkout must not depend on Zirva. If we didn’t answer or answered with an error, place the order without the discount.

sequenceDiagram
  autonumber
  participant B as Buyer
  participant S as Your server
  participant A as Zirva
  B->>S: opens checkout
  S->>A: GET /v1/users/{user_ref}/rewards?status=available
  A-->>S: available rewards
  S->>A: POST /v1/rewards/{id}/reserve (order_id)
  A-->>S: 200 reserved
  S->>B: price with the discount
  alt payment succeeded
    S->>A: POST /v1/rewards/{id}/redeem (order_id, amounts)
    A-->>S: 200 redeemed
  else order cancelled
    S->>A: POST /v1/rewards/{id}/release (order_id)
    A-->>S: 200 available
  end
  1. Which discounts exist. GET /v1/users/{user_ref}/rewards?status=available returns rewards that can be applied now.
  2. Reserve. Before showing the discounted price, call reserve with the order ID. The reservation lasts 30 minutes (ttl_seconds from 60 to 86400 is allowed) and is released automatically. A retry with the same order_id returns the same reservation.
  3. Redeem. After payment, call redeem with the same order_id. Pass order_amount and discount_amount: without them the margin report computes the discount’s cost from its terms, not from the facts.
  4. Release. If the buyer left or the order was cancelled, call release. The reward returns to available.
POST /v1/rewards/rw_7731/redeem
Content-Type: application/json
{ "order_id": "ord_79010", "order_amount": 40.00, "discount_amount": 4.00 }
Response What it means What to do
200 the action is done, or was already done by this same order continue
409 reward_not_available the reward is not in the right status; the current one is in reward_status don’t apply the discount
409 reward_order_mismatch the reward is held or redeemed by another order don’t apply the discount
503 with Retry-After the user is being recalculated right now, nothing was written for reserve: no discount; for redeem and release: retry
timeout, 5xx unknown whether it was written see below

Set a timeout of at most 30 seconds on requests to us. If reserve did not answer in time or answered with an error:

  1. Place the order without the discount.
  2. Send release with the same order_id.
  3. After 60 seconds, send release again.
  4. Don’t retry reserve for this order.

Why two release calls: the reservation may have reached us after your timeout. Without a release, the reward would stay held by an order placed without the discount until the reservation ends, and the buyer’s next order would get 409. release of a reward that was never reserved answers 200 with no changes, so sending it is safe.

Retry with a growing pause until you get 200 or 409. Retrying is safe. The order is already paid with the discount: without a retry the reward would stay available and could be applied again.

  • redeemed is final. If the paid order is refunded later, the reward stays redeemed.
  • If the reward’s term ends during a reservation, it can still be redeemed by the same order until the reservation ends. A reservation never lasts more than 30 minutes past the end of the term.
  • In the order.paid event, send the amount after the discount: that is what scenarios count.