> For the complete index of the 402pay docs, see [llms.txt](https://developer.402pay.co/llms.txt).

# Test your integration

Test your integration with small real payments, signed test events and requests that fail on purpose.

402pay has no test mode, test keys or test cards: every payment is real. Test with small payments you make yourself, signed test events and replays of real deliveries.

> A crypto test costs little: the money lands in your own wallet, so you're out only the network's fee and any fee 402pay charges.

## What to test

| What | How |
| --- | --- |
| Creating payments | Create a small real payment from your server and open its `url`. |
| Each outcome | Pay in full, short, over or not at all (below). |
| Your webhook handler | [Send a test event](https://developer.402pay.co/api/webhooks/test.md) of any type, then resend real deliveries. |
| Retries | Create the same payment twice with the same `reference`: you get one payment. |
| Errors | Send requests that fail on purpose (below). |

## Test payments

- Use a [restricted key](https://developer.402pay.co/authentication.md) for your test environment, with only the access it needs, and revoke it when you're done.
- Amounts start at the equivalent of $1.00, so keep tests small.
- Pay with a stablecoin on a network with low fees. A card test is a real card payment: the customer verifies their identity with the card provider, and it arrives as crypto.
- [Cancel](https://developer.402pay.co/api/payments/cancel.md) any payment you create and don't pay.

## Cause each outcome

Every outcome is something real you do to a payment. Watch for its event.

| Outcome | How | Event |
| --- | --- | --- |
| Succeeded | Pay the full amount. | `payment.succeeded` |
| Underpaid | Send less than checkout asks for, by more than your 0.5% tolerance. | `payment.underpaid` |
| Overpaid | Send more than checkout asks for. | `payment.overpaid` |
| Expired | Set `expires_at` 15 minutes out and don't pay. | `payment.expired` |
| Canceled | Cancel it with `POST /payments/{id}/cancel`. | `payment.failed` |

An underpaid payment is the one to rehearse: see [underpayments](https://developer.402pay.co/guides/underpayments.md) for requesting the rest or accepting what arrived.

## Test webhooks

A test event is signed like a real one and changes nothing in your business. Its payload has `test: true` and a subject ID containing `_test_`, and it goes out once, without retries.

Send a test event, cURL:

```bash
curl -X POST "https://api.402pay.co/api/v1/webhooks/whk_GFAKLrE8wkBwF4WL/test" \
  -H "Authorization: Bearer $PAY402_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "event_type": "payment.succeeded"
  }'
```

Send a test event, Node.js:

```js
const response = await fetch("https://api.402pay.co/api/v1/webhooks/whk_GFAKLrE8wkBwF4WL/test", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAY402_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    event_type: "payment.succeeded"
  }),
});
const { data } = await response.json();
```

Send a test event, Python:

```python
import os

import requests

response = requests.post(
    "https://api.402pay.co/api/v1/webhooks/whk_GFAKLrE8wkBwF4WL/test",
    headers={
        "Authorization": f"Bearer {os.environ['PAY402_SECRET_KEY']}",
    },
    json={
        "event_type": "payment.succeeded"
    },
)
data = response.json()["data"]
```

- Endpoints must be public `https://` addresses. To reach your machine, use an HTTPS tunnel, or [replay deliveries locally](https://developer.402pay.co/guides/frameworks.md#test-locally).
- [Resend](https://developer.402pay.co/api/webhooks/resend.md) a real delivery to check that your handler skips one it has already processed.
- [`GET /webhook-deliveries`](https://developer.402pay.co/api/webhooks/deliveries.md) shows each request and your server's response.
- Test events and resends are limited to 10 a minute for each business.

## Test errors

These requests fail on purpose, so you can check how your code handles each one.

| Send | Get |
| --- | --- |
| A request with no key | `401` `unauthenticated` |
| `amount` as a JSON number, such as `49` | `400` `invalid_request` |
| A used `reference` with a different amount | `409` `reference_in_use` |
| An ID that isn't yours | `404` `not_found` |

Every code is on the [errors](https://developer.402pay.co/api/errors.md) page.

## Next steps

- [Going live](https://developer.402pay.co/going-live.md): Everything to check before you accept real payments, and after.
- [Webhooks](https://developer.402pay.co/guides/webhooks.md): Signed events for every change, retried for about 28 hours.
- [Underpayments and overpayments](https://developer.402pay.co/guides/underpayments.md): What happens when a customer sends too little, too much, too late or on the wrong network.
- [Errors](https://developer.402pay.co/api/errors.md): Status codes, the error envelope, and the codes to branch on.
