# Testing

Test payments, notifications, retries and idempotency in Sandbox.

[Web version](https://www.longplayai.com/docs/guides/testing)

<a id="sandbox"></a>

## Build in Sandbox

- Build and test with a Sandbox Server Key. Sandbox Customers, purchases and usage are fully separate from Live.
- Create Customers from fixed test user IDs such as `test-user-1`; repeated runs return the same Customer.
- Before launch, follow the go-live checklist to create Live Keys and publish your configuration in Live.

- [Go-live checklist](https://www.longplayai.com/docs/guides/environments.md#go-live)

<a id="payments"></a>

## Test payments

Connect a Stripe test-mode account to Sandbox under Payment connections in Console, then use Stripe test cards on the payment page with any future expiry and any 3-digit CVC.

- [Set up Stripe first: API key, webhook and activation](https://www.longplayai.com/docs/guides/stripe.md)

**Common test cards**

| Card number | Result |
| --- | --- |
| `4242 4242 4242 4242` | Payment succeeds |
| `4000 0000 0000 0002` | Payment is declined |
| `4000 0025 0000 3155` | Requires 3D Secure authentication |

- After paying, call `readSubscriptionOperation` until the status is `complete`, then confirm access with `readHoldings`.
- Test refunds with `previewRefund` and `refund`, and confirm access is kept or revoked as chosen.

<a id="notifications"></a>

## Test notifications

- The receiver must be public HTTPS. During local development, expose your local server with an HTTPS tunnel and enter that address under App notifications in Console.
- Trigger a real event, such as reporting usage, and confirm `usage.consume` arrives and its signature verifies.
- Replay the same event from the delivery list in Console and confirm your service deduplicates it by event ID.

- [Notifications and webhooks](https://www.longplayai.com/docs/guides/notifications.md)

<a id="retries"></a>

## Test retries and idempotency

- Send the same write twice with the same `requestId` or `idempotencyKey` and confirm it returns the original result without running again; responses with a `replayed` field return `true`.
- Sending the same ID with different content should return `CONFLICT`.
- After a simulated timeout, recover by reading the original operation and retrying with the original ID; confirm no second charge or purchase appears.

- [Idempotency and retries](https://www.longplayai.com/docs/api.md#idempotency)
