# Sandbox

> Build and test in a second organization of yours, which only your own testers join.

Any organization can be used for testing. A sandbox is simply a second organization of yours that
you keep for it: same hosts, same routes, same events and signatures as your live one. You decide
who joins it.

What makes an organization live is your agreement with YOU(th): the codes and limits you agreed are
set on your live organization. A sandbox keeps the defaults every new organization starts with.

## What a sandbox has of its own

| Yours in the sandbox | Means                                                                                             |
| -------------------- | ------------------------------------------------------------------------------------------------- |
| Credentials          | Integrations, with keys that reach the sandbox only: see [Get API credentials](/docs/credentials) |
| Webhook endpoints    | Their own addresses and signing secrets, so test deliveries go to your test receiver              |
| Access codes         | Batches and codes of its own, for your testers                                                    |
| Members              | Only the people you gave a sandbox code to                                                        |

Going live changes your credentials, your signing secret and your receiver's address, and no code
of yours.

## Know where you are

An integration belongs to one organization. Ask which:

```bash
curl https://api.youth-platform.io/v1/organization \
  --header "Authorization: Bearer $YOUTH_ACCESS_TOKEN"
```

```json
{
  "organization": { "alias": "example-mobile-sandbox", "name": "Example Mobile (sandbox)" },
  "integration": {
    "id": "0193b1a0-52c4-7b1e-a2d3-4f5a6b7c8d9e",
    "name": "Billing backend (test)",
    "scopes": ["access_codes:read", "access_codes:write", "webhooks:write"]
  }
}
```

It is also the quickest check that your credentials work. Have your test systems refuse to start
when `organization.alias` is not your sandbox.

## A whole run

1. [Create a webhook endpoint](/docs/webhooks/endpoints) for your test receiver.
2. [Order a batch](/docs/access-codes/order) of a few codes and read them.
3. Give one code's `redeem_url` to a tester. They redeem it in the YOU(th) app as a customer would,
   with an account in your sandbox.
4. Check that your receiver got [`AccessCode.redeemed`](/docs/webhooks#accesscoderedeemed) and
   stored the time.
5. [End its access](/docs/access-codes/end-access) with `ends_at` left out, and check that your
   receiver got `Access.ended` and that the tester's app shows it.
6. Stop your receiver, have a second code redeemed, and
   [catch up](/docs/access-codes/reconcile#catch-up-after-an-outage) from the list.

## Go live

1. In your live organization, create an integration and a webhook endpoint.
2. Give your production backend the live client id, key id, private key and signing secret.
3. Check `GET /v1/organization`: `organization.alias` is your live one.
4. Order your first live batch.

Ask your YOU(th) contact for a sandbox when you start.
