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

# Sell prepaid credits

> Let agents buy credits first and use them later. Add credits only after the payment completes, and only one time for each payment.

Let agents buy credits first and use them later. The agent pays for a top-up. Your service adds credits to the account.

## The rule

Add credits only after the payment completes. Add credits only one time for each payment. InFlow blocks duplicate payments, but your service must block duplicate credits.

## Make a top-up endpoint

1. Set a fixed price for each top-up package. See [Write a price](https://ifdocdemo.lumivescence.com/sellers/protect-an-endpoint.md#write-a-price) for x402 and [Choose the currency](https://ifdocdemo.lumivescence.com/sellers/protect-an-endpoint.md#choose-the-currency) for MPP.
2. Protect the endpoint with MPP, x402, or both. See [Get paid by agents](https://ifdocdemo.lumivescence.com/sellers/protect-an-endpoint.md).
3. Find the account from your usual authentication. With [Onboard](https://ifdocdemo.lumivescence.com/sellers/enable-enrollment.md), the enrollment credential of the agent identifies the account.
4. Make a top-up ID for each request. Keep it with the transaction ID of the payment.

## Add the credits

The two protocols run your handler at different times.

| Protocol | Order | Where to add the credits |
| - | - | - |
| MPP | The SDK accepts the payment. Then your handler runs. | In your handler. |
| x402 | The middleware checks the payment and runs your handler. Then it settles the payment. | After settlement. Not in your handler. |

For x402, add the credits when you know that the payment settled. A `TRANSACTION_UPDATED` [webhook](https://ifdocdemo.lumivescence.com/sellers/webhooks.md) with the status `SETTLED` tells you. The SDKs have no shared callback for after settlement.

## If adding credits fails

Do not ask for a second payment. Try again to add the credits for the same top-up ID. Use the transaction ID to find the payment. If your server did not see the result, get the payment status from a [webhook](https://ifdocdemo.lumivescence.com/sellers/webhooks.md).

## Let the buyer choose the amount

Fixed packages are the simplest. With MPP, you can also set the price from the request. With x402, use fixed packages.

## Next step

> [card] [Webhooks](https://ifdocdemo.lumivescence.com/sellers/webhooks.md)
>
> Get a signed event when a transaction changes.


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