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

# Test and recover agent purchases

> Check that your Spend integration handles approvals, retries, and interrupted checkouts.

Run these tests in test mode, with the test card and checkout Ionic provides
when it enables Spend for you. You also need a business owner who can complete
the [card and approval steps](https://docs.ionicfi.com/guides/spend-card-access.md).

Don't write keys, claim responses, card details, or security codes to logs,
recordings, screenshots, or model prompts. Record IDs and outcomes for each
test instead.

## Complete one approved purchase

1. Create a setup session and complete it as the business owner. Retrieve it
   until `status` is `completed` and `card_id` is set.
2. Give the agent access to the card. Confirm `GET /v1/spend/cards` returns it
   for the agent's key and business.
3. Create a spend intent with a stored idempotency key. Complete every
   approval, then retrieve the spend intent and check its status.
4. Take the job's lock and claim with a separate stored key. Record that
   checkout may start before you enter any card fields.
5. Submit once. Record the seller's order ID and outcome. `claimed` alone
   doesn't mean the purchase succeeded.

## Test refusals and recovery

| Test | Expected result |
| - | - |
| No card access | The agent can't see or claim the card. Saving a card doesn't give the agent access. |
| Declined or expired approval | The job stops. It doesn't claim or create a new request. |
| Limit set to **Block** | `limit_exceeded` and a saved `blocked` spend intent. The job stops. |
| Limit set to **Ask for approval** | The job waits for the extra approval, then retrieves the spend intent before claiming. |
| Access revoked before claim | The claim is refused, and the job stops. |
| Same webhook event twice | Only one job runs. |
| Lost create response | Retrying with the same key and body returns the same spend intent. |
| Lost claim response | Retrying with the same claim key before `expires_at` returns the same card details and expiry, with no second submission. After `expires_at`, the retry is refused. |
| Two workers at once | Only one submits, even after the first worker's lock expires. |
| Crash after submission | The outcome is marked uncertain until someone checks the seller's order history. |

## Handle claim errors

For each claim error, follow
[Recover without creating another purchase](https://docs.ionicfi.com/guides/spend-platform-integration.md#recover-without-creating-another-purchase).
If the claim window closes before checkout, stop the job and confirm nothing was
submitted before you request a new approval. See also
[requests and errors](https://docs.ionicfi.com/guides/spend-platform-integration.md#requests-and-errors).


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