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

# In-game reward grants

> How to integrate the Almedia SDK — synced from the source repository.

The backend can instruct the game to grant in-game rewards. Subscribe, credit the player, celebrate:

```csharp theme={"theme":{"light":"github-light","dark":"night-owl"}}
Almedia.OnInGameRewardGrantRequested += grant =>
{
    foreach (var reward in grant.Rewards)
        Wallet.Credit(reward.Code, reward.Amount);
};
```

There is nothing extra to start. Grants travel with notifications, so `FetchNotifications()` fetches them and `StopNotificationPolling()` suspends them.

## One event per grant

A grant is an atomic bundle. "250 gems and 3 spins for finishing the chapter" arrives as a single event with one id and two entries in `Rewards`. Show one celebration for it. Three separate grants arriving together raise three events.

`Amount` is a `double` and may carry fractions, so do not truncate it to an integer. `Code` is the reward code agreed with Almedia, for example `"gems"`. Treat a code you do not recognize as a no-op rather than an error.

## Delivery is at-least-once

The same grant can arrive more than once. The server-to-server reward postback remains the authoritative record of what was granted; reconcile against it if your economy needs certainty.

Each grant has a unique `Id`, and a redelivery carries the same one. Deduplicate on it when a repeat credit matters:

```csharp theme={"theme":{"light":"github-light","dark":"night-owl"}}
private readonly HashSet<string> _credited = new HashSet<string>();

Almedia.OnInGameRewardGrantRequested += grant =>
{
    if (!_credited.Add(grant.Id)) return;   // redelivered, already credited
    foreach (var reward in grant.Rewards)
        Wallet.Credit(reward.Code, reward.Amount);
};
```

A short memory of recent ids is enough.

## Testing without a backend

`AlmediaEditorMock.EmitInGameRewardGrant` delivers a grant to your handler. Call it twice with one id to reproduce a redelivery and prove your dedup holds:

```csharp theme={"theme":{"light":"github-light","dark":"night-owl"}}
var rewards = new[]
{
    new AlmediaInGameReward(250, "gems"),
    new AlmediaInGameReward(3, "spins")
};
AlmediaEditorMock.EmitInGameRewardGrant("grant-1", rewards);
AlmediaEditorMock.EmitInGameRewardGrant("grant-1", rewards);   // must credit once
```

See [Driving non-happy paths](https://docs.almedia.dev/technical/integration-guide/editor-and-play-mode.md#driving-non-happy-paths) for the mock's rules.

***


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