> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scrip.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Start with https://docs.scrip.dev/agents.md and https://docs.scrip.dev/which-endpoints-you-need.md. Your application only needs a few API calls as users earn and spend (`POST /v1/events`, balance/history reads, and redemptions); program setup happens in the dashboard or setup scripts.
> Use `https://api-sandbox.scrip.dev` with `sk_test_` keys for testing, and `https://api.scrip.dev` with `sk_live_` keys for production. Keep API keys on your server.
> Pass your own user ID as `external_id` on events and prefix it with `ext:` in participant URL paths (e.g., `GET /v1/participants/ext:user_123/balances`). By default (`on_unknown_participant: CREATE`), the first event for a new `external_id` creates and enrolls the participant automatically.
> Events process asynchronously: `POST /v1/events` returns `202 Accepted` when queued, and rules evaluate in the background. Pass an `idempotency_key` (such as an order ID) on every event, and wait for the `event.completed` webhook or poll `GET /v1/events/{event_id}` before reading updated balances.
> Connect the hosted MCP server at https://mcp.scrip.dev/mcp (OAuth, defaults to Sandbox) to inspect programs, validate and simulate rules, and trace events. Append `.md` to any docs URL for Markdown, or fetch https://docs.scrip.dev/openapi.json for full endpoint schemas.

# Pending rewards

> Show rewards as soon as they are earned, and make them spendable when a later event confirms them

A pending reward is value a participant has earned but cannot spend yet. It shows in the `held` part of their balance until one of your events confirms it, such as a card settlement, a delivery, an installation, or a loan closing.

Each rule decides when its own rewards become spendable, so one program can pay some rewards right away, hold others for a confirming event, and release others on a date. For rewards that wait only for a calendar date or duration, see [Vesting](https://docs.scrip.dev/guides/lots-and-expiration.md#vesting). For manual support adjustments, holds, and releases, see [Balance operations](https://docs.scrip.dev/guides/balance-operations.md).

## Choose when rewards become spendable

| Rewards become spendable | What the rule does | Where they wait |
| - | - | - |
| Right away | `CREDIT` | Nowhere. They go to `available`. |
| On a date known when they are earned, such as 30 days after a purchase | `CREDIT` with `matures_in` or `matures_at`. See [Vesting](https://docs.scrip.dev/guides/lots-and-expiration.md#vesting). | `deferred` |
| When a later event arrives, such as an installation | `CREDIT` into `HELD` with a `reference_id`, then [confirm](#confirm-pending-rewards) on the later event | `held` |
| Some time after a later event, such as 30 days after an installation or at the end of the statement period | `CREDIT` into `HELD`, then confirm [with a waiting period](#add-a-waiting-period) | `held`, then `deferred` |

> [!NOTE]
>
> Pending rewards need a [`LOT`-mode asset](https://docs.scrip.dev/guides/asset-configuration#inventory-mode), so that `reference_id` can link the pending reward to the event that confirms it.

## Add pending rewards

Send an event when the participant earns the reward. Include your own ID for whatever the reward is waiting on. This example uses an order ID:

```bash theme={null}
POST /v1/events
```

```json theme={null}
{
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "external_id": "user_123",
  "idempotency_key": "order-1001-placed",
  "event_timestamp": "2027-01-15T10:30:00Z",
  "event_type": "order_placed",
  "event_data": {
    "order_id": "order_1001",
    "amount": 8400
  }
}
```

A rule credits the points into `HELD` and labels them with the order ID:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order placed: pending points",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_placed\"",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.amount }}",
      "bucket": "HELD",
      "reference_id": "${{ event.order_id }}"
    }
  ]
}
```

The participant's `held` balance now includes 8,400 points that cannot be spent.

| Field | What to send |
| - | - |
| `bucket` | `HELD`. This is what makes the credit pending. |
| `reference_id` | Your ID for the order, booking, or application the reward waits on. Every later action finds the pending reward by it. 1-255 characters, alphanumeric plus `._:@-`, and it cannot start with `scrip:`. |
| `expires_in` or `expires_at` | Optional. A [deadline](#set-a-deadline) for a confirmation that never arrives. |

Use a `reference_id` that is unique to one order. Pending credits that share a reference for the same participant are confirmed and cancelled together.

On a `PREFUNDED` asset, which pays rewards out of the [program wallet](https://docs.scrip.dev/guides/programs.md#the-program-wallet), the value leaves the wallet when the pending reward is added. Cancelling the pending reward returns it.

## Confirm pending rewards

When the awaited event arrives, a second rule makes the rewards spendable. Two actions can do this. Use one of them for each reference. After a `RELEASE`, a `CREDIT` with the same `reference_id` finds no pending rewards to confirm and pays its full amount again.

| | `RELEASE` | `CREDIT` with the same `reference_id` |
| - | - | - |
| Amount | Not needed. The pending rewards become spendable as they are. | Required. Scrip replaces the pending rewards with this amount. |
| Use it when | The reward cannot change between the two events | The final amount can differ, or the rewards need new dates |
| Expiration | The rewards keep the pending credit's `expires_at` | The rewards take this credit's `expires_in` or `expires_at`. The pending credit's expiration does not carry over. |
| Waiting period | Not supported | Add `matures_in` or `matures_at` |
| If the confirming event arrives first | No pending rewards exist yet, so nothing is released. The pending credit then adds rewards that stay pending. | It credits the amount. Scrip then skips the pending credit for that reference. |

### Release them unchanged

`RELEASE` with the `reference_id` and no `amount` moves every pending reward for that reference to `available`:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order installed: release points",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_installed\"",
  "actions": [
    {
      "type": "RELEASE",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "reference_id": "${{ event.order_id }}"
    }
  ]
}
```

The confirming event only needs the same `order_id`. It does not need to repeat the amount.

### Confirm a final amount

A `CREDIT` with the same `reference_id` and no `bucket` confirms the pending rewards at the amount you send. This rule reads the amount from a `final_amount` field in the `order_installed` event:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order installed: confirm points",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_installed\"",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.final_amount }}",
      "reference_id": "${{ event.order_id }}"
    }
  ]
}
```

Scrip compares the amount with the pending rewards and settles the difference, so you do not calculate it:

| Confirmed amount | What happens |
| - | - |
| Same as pending | The pending rewards move to `available`. |
| More than pending | The pending rewards move to `available`, plus the difference. |
| Less than pending | The confirmed amount moves to `available`. The rest returns to where it came from. |

Leave `bucket` unset on this credit. With `"bucket": "HELD"` it adds more pending rewards instead of confirming them.

Give each event a stable `idempotency_key`, such as `order-1001-installed`. A confirming `CREDIT` sent twice under different keys pays twice.

### Settlement journal entry

When a confirming `CREDIT` finds pending rewards, it creates one `CREDIT` journal entry with that `reference_id` and up to three postings:

```text theme={null}
Journal Entry: CREDIT, reference_id auth_78945
├── participant/user_123 HELD        -8.00   (full pending amount)
├── participant/user_123 AVAILABLE   +6.50   (confirmed amount)
└── program/loyalty                  +1.50   (under-settlement returned to the program wallet)
```

The `HELD` posting removes all pending rewards for the reference, even when the confirmed amount is smaller. The destination posting (`AVAILABLE` or `DEFERRED`) adds the confirmed amount. The third posting appears only when the two amounts differ: on an under-settlement, the difference returns to the program wallet or `SYSTEM_ISSUANCE`; on an over-settlement (such as an added tip), the extra comes from there.

In a statement with `bucket=HELD`, the confirmation appears as a negative `CREDIT` row with the same `reference_id` as the pending credit.

Key settlement rules:

* **One reference per order or card transaction.** When incremental credits share a `reference_id`, the confirmation compares against their total. Once a reference settles, later `HELD` credits with that `reference_id` are skipped, while a second confirming `CREDIT` with a new `idempotency_key` credits its full amount.
* **Expired pending rewards are excluded.** Pending rewards that expired before confirmation are skipped.
* **Confirmed credits set their own dates.** A confirming `CREDIT` uses its own `expires_in` / `expires_at` and `matures_in` / `matures_at`; the pending credit's expiration does not carry over. A lot settled in full keeps its `id` and `created_at`. See [Lot-aware operations](https://docs.scrip.dev/guides/lots-and-expiration.md#lot-aware-operations).

## Cancel pending rewards

When an order or card authorization is cancelled before it is confirmed, `VOID_PENDING` removes the pending rewards. The value returns to where it came from: the program wallet on a `PREFUNDED` asset, or `SYSTEM_ISSUANCE` on an `UNLIMITED` one (see [Issuance policy](https://docs.scrip.dev/guides/asset-configuration.md#issuance-policy)).

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order cancelled: void points",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_cancelled\"",
  "actions": [
    {
      "type": "VOID_PENDING",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "reference_id": "${{ event.order_id }}"
    }
  ]
}
```

Add `amount` to cancel part of the pending rewards (for example, when one item on an order is returned or an issuer processor reverses part of an open authorization). `amount` is in reward units, not the order's currency: calculate it in your backend as the rewards for the earlier authorized amount minus the rewards for the remaining amount, and pass it on the event. For example, on a 2x card where a USD 100.00 authorization added 200 pending points and USD 40.00 is reversed (leaving USD 60.00, or 120 points), pass `amount: "80"`. Scrip voids the newest pending rewards first and leaves the rest in `HELD`. See [`VOID_PENDING`](https://docs.scrip.dev/guides/rule-actions#void_pending).

A void changes nothing once the rewards are confirmed. To take back confirmed rewards, see [Refunds and clawbacks](https://docs.scrip.dev/examples/refunds.md).

## Add a waiting period

Some rewards need the confirming event and then more time. Confirm them with a `CREDIT` and add one of two fields:

| The rewards become spendable | Field | Example |
| - | - | - |
| A set time after the confirming event | `matures_in` | 30 days after an installation |
| On a date your backend knows | `matures_at` | At the end of the statement period |

The confirmed rewards move from `held` to `deferred`. When the date arrives, Scrip moves them to `available`, usually within a few minutes, and sends a [`balance.matured`](https://docs.scrip.dev/api-reference/webhooks/event-payloads) webhook event. This is [vesting](https://docs.scrip.dev/guides/lots-and-expiration.md#vesting) that starts when the rewards are confirmed.

Put the waiting period on the confirming credit, not on the pending credit. Pending rewards created with a future `matures_in` or `matures_at` are skipped by a confirming `CREDIT` and stay in `HELD`, so the confirming `CREDIT` pays its full amount and counts the purchase twice until those pending rewards are voided or expire.

### Wait a set time after the event

This rule confirms an order's rewards when it is installed and makes them spendable 30 days later:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order installed: confirm points, spendable in 30 days",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_installed\"",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.final_amount }}",
      "reference_id": "${{ event.order_id }}",
      "matures_in": "30d"
    }
  ]
}
```

The 30 days count from when Scrip processes the event.

### Wait until a date from the event

When your backend knows the date, send it in the confirming event. This event confirms the order from [Add pending rewards](#add-pending-rewards) and carries the end of the statement period:

```bash theme={null}
POST /v1/events
```

```json theme={null}
{
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "external_id": "user_123",
  "idempotency_key": "order-1001-installed",
  "event_timestamp": "2027-02-10T15:00:00Z",
  "event_type": "order_installed",
  "event_data": {
    "order_id": "order_1001",
    "final_amount": 8400,
    "statement_period_end": "2027-02-28T23:59:59Z"
  }
}
```

The rule reads the date into `matures_at`:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order installed: confirm points, spendable at statement end",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_installed\"",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.final_amount }}",
      "reference_id": "${{ event.order_id }}",
      "matures_at": "${{ event.statement_period_end }}"
    }
  ]
}
```

The participant's balance after each step:

| After | `held` | `deferred` | `available` |
| - | - | - | - |
| The order is placed on January 15 | 8,400 | 0 | 0 |
| The order is installed on February 10 | 0 | 8,400 | 0 |
| The statement period ends on February 28 | 0 | 0 | 8,400 |

`matures_at` takes an RFC 3339 timestamp. If the date has already passed when Scrip processes the event, the rewards go straight to `available`.

### Leave out the pending credit

When rewards do not need to show before the installation, leave out the pending credit. One `CREDIT` with `matures_in` or `matures_at` on the installation event is enough.

## Set a deadline

Some orders are never confirmed or cancelled. Add `expires_in` or `expires_at` to the pending credit rule from [Add pending rewards](#add-pending-rewards) so those rewards do not stay pending forever:

```bash theme={null}
POST /v1/rules
```

```json theme={null}
{
  "name": "Order placed: pending points with deadline",
  "program_id": "8f14e45f-ceea-4e70-9df8-2a7d1b3c9f01",
  "condition": "event.type == \"order_placed\"",
  "actions": [
    {
      "type": "CREDIT",
      "asset_id": "a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02",
      "amount": "${{ event.amount }}",
      "bucket": "HELD",
      "reference_id": "${{ event.order_id }}",
      "expires_in": "180d"
    }
  ]
}
```

At the deadline, the pending rewards expire like any other [lot](https://docs.scrip.dev/guides/lots-and-expiration.md#expiration) and Scrip sends a `balance.expired` webhook event. Choose a deadline longer than the longest confirmation you expect.

The deadline also affects how you confirm:

| You confirm with | What happens to the deadline |
| - | - |
| `RELEASE` | It stays on the rewards as their expiration. Points released on day 170 of a 180-day deadline expire 10 days later. |
| `CREDIT` with the same `reference_id` | It is dropped. Set `expires_in` or `expires_at` on the confirming credit if the confirmed rewards should expire. |

## Show pending rewards to a participant

Each stage of a reward is a separate field in the [balances response](https://docs.scrip.dev/api-reference/participants/get-participant-balances.md), and each change sends a webhook event:

| Stage | Balance field | Webhook event when it starts |
| - | - | - |
| Pending | `held` | `balance.credited` with `bucket` `HELD` |
| Confirmed, in a waiting period | `deferred` | `balance.credited` with `bucket` `DEFERRED` |
| Spendable | `available` | `balance.released` after a `RELEASE`, `balance.credited` after a confirming `CREDIT`, or `balance.matured` after a waiting period |
| Cancelled | Removed from `held` | `balance.voided` |
| Expired before it was confirmed | Removed from `held` | `balance.expired` |

`held` also includes value set aside by a [hold](https://docs.scrip.dev/guides/balance-operations.md#hold) or a [pending redemption](https://docs.scrip.dev/guides/redemption-lifecycle.md). To list the pending rewards for one order, filter the participant's lots by its reference:

```bash theme={null}
GET /v1/participants/ext:user_123/balances/lots?asset_id=a3bb189e-8bf9-4c8b-9be0-6b5d2f4e7a02&status=HELD&reference_id=order_1001
```

## Card authorizations and settlements

Card programs use pending rewards when they want cardholders to see rewards as soon as they tap their card (at authorization) and reconcile to the final amount when the merchant settles (accounting for tips, partial captures, or currency conversion). Many card programs skip authorizations and credit only at settlement, as in [Cashback card](https://docs.scrip.dev/examples/cashback-card.md).

Forward your issuer processor's authorization, settlement, and cancellation webhooks as events using the authorization ID as `reference_id`:

* **Authorization:** Credit into `HELD` with `reference_id: "${{ event.authorization_id }}"` and an `expires_in` (such as `"30d"`) longer than merchants take to settle.
* **Settlement:** Confirm with a `CREDIT` using `reference_id: "${{ event.authorization_id }}"` and `amount: "${{ event.settlement_amount }}"` (optionally with `matures_at` for statement-cycle vesting). Use `RELEASE` instead only when the settled amount never differs from authorization.
* **Cancellation or partial reversal:** Void with `VOID_PENDING` using `reference_id: "${{ event.authorization_id }}"` (adding `amount` for a partial reversal).

If you instead hold a participant's existing `AVAILABLE` points with `HOLD` and a `reference_id`, finish it with `RELEASE`. Sending a confirming `CREDIT` against value held by `HOLD` fails with `error_code` `reference_provenance_conflict`.

## Out-of-order and repeated events

Upstream webhooks do not always arrive in order, and one authorization or order can be reversed or settled more than once. `reference_id` links a confirmation to its pending credit; it does not deduplicate retries. Build each event's `idempotency_key` from your upstream event ID.

| What happens | What Scrip does | What to do |
| - | - | - |
| Confirmation or settlement arrives before the pending event | The confirming `CREDIT` credits the full amount. Scrip skips the late pending credit with `SUCCESS` and reason `REFERENCE_ALREADY_SETTLED`. | No action needed when both events share `reference_id` and use `CREDIT` into `HELD` (not `HOLD`). |
| Cancellation arrives before the pending event | `VOID_PENDING` finds no pending rewards and changes nothing. The late pending credit then stays in `HELD`. | Guard the pending rule on open status (for example `event.transaction_status == "PENDING"`), or send `VOID_PENDING` again. |
| Refund arrives after confirmation | Pending rewards are already settled, so `VOID_PENDING` leaves confirmed rewards untouched. | Have the refund rule `DEBIT` the rewards (with `allow_negative` if they may already be spent). [Event reversal](https://docs.scrip.dev/guides/event-processing.md#reversing-an-event) cannot undo a settlement that consumed pending rewards (`ineligible_entries`). |
| Partial refund arrives before confirmation | `VOID_PENDING` with `amount` cancels that amount newest-first and leaves the rest in `HELD`. | Pass the reward difference in `amount`. See [Cancel pending rewards](#partial-authorization-reversals). |
| Merchant settles in two parts | The first settlement consumes all pending rewards; the second credits its full amount. | Give each settlement its own `idempotency_key`. |
| Confirmation arrives after the deadline | Expired pending rewards are forfeited to breakage; the confirming `CREDIT` credits its full amount. | Set `expires_in` longer than your longest expected confirmation window. |
| Same confirmation arrives twice with different idempotency keys | Both credits pay. | Derive `idempotency_key` from the upstream confirmation or settlement ID. |
| Rules run both `RELEASE` and a confirming `CREDIT` for one reference | If `RELEASE` runs first, the pending rewards become available and the `CREDIT` pays again. | Use only one confirmation action per reference. |
| An authorization that used `HOLD` arrives after its settlement | The participant's own points stay in `HELD`. | Send `RELEASE` for the reference. |

## Change pending rewards by hand

Rules add pending rewards. For a support case, you can release or cancel them yourself: send a [`RELEASE`](https://docs.scrip.dev/guides/balance-operations#release) or [`VOID_PENDING`](https://docs.scrip.dev/guides/balance-operations#void-pending-rewards) balance operation with the order's `reference_id`.

> [card] [Set expiration and vesting](https://docs.scrip.dev/guides/lots-and-expiration.md)
>
> Give rewards a date to become spendable or to expire.

> [card] [Manual balance operations](https://docs.scrip.dev/guides/balance-operations.md)
>
> Adjust, hold, release, forfeit, or void balances through the API.

> [card] [Test the rules](https://docs.scrip.dev/guides/testing.md)
>
> Run both events through a simulation before going live.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.