# Quickstart: Your First Payment Plan (Platform)

This quickstart creates a practice location, saves its Dejavoo credentials, registers a terminal, creates a patient as a customer, creates a payment plan with a down payment and collects that down payment on the terminal. It uses a **platform API key** (`psk_...`) and the `Chaching-Account` header, which is how a platform such as a practice-management integration works.

This quickstart uses a platform key. If you integrate your own account, follow the [single-account quickstart](/developer-guide/quickstart-single-account).

Every request goes to staging, `https://stage-api.chaching.io`. Amounts are in cents and are small on purpose: on staging the iPOSpays UAT host approves `100` ($1.00). See [Integrating against staging](/developer-guide/integrating-staging#test-cards-and-amounts).

## Before you start

- A staging platform key, created by your administrator in the platform console and stored in `CHACHING_PLATFORM_KEY`. See [Get access](/developer-guide/integrating-staging#get-access). Create it with **Full access** (`*`), or with the scopes `read`, `operate`, `accounts`, `processor_credentials` and `webhooks`: this quickstart uses all five, and a key's scopes cannot be changed later (see [Key scopes](/developer-guide/platforms#key-scopes)).
- Your iPOSpays UAT e-commerce credentials: TPN, API key, secret key and e-commerce token.
- A Dejavoo terminal set up for SPIn Cloud, with its TPN and its 10-character SPIn Auth Key.
- A public HTTPS URL that receives webhooks. See [Receive webhooks on staging](/developer-guide/integrating-staging#receive-webhooks-on-staging).


```bash
export CHACHING_PLATFORM_KEY="psk_..."
```

## 1. Register a webhook endpoint

Register one endpoint for your platform before you create accounts: it receives the events of every account of your platform, including accounts created later.

```bash
curl -X POST https://stage-api.chaching.io/platform/webhook-endpoints \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "https://example.com/chaching/webhooks",
    "enabled_events": ["payment_plan.created", "payment_plan.activated", "payment_plan.installment_paid", "payment_plan.installment_failed", "payment_plan.payment_succeeded", "payment_plan.completed", "payment_plan.canceled"]
  }'
```

```json
{
  "id": "4a19c6f9-c4c8-4b79-b9a1-379260670c3d",
  "object": "webhook_endpoint",
  "endpoint": "https://doctor-cycling-likewise-brother.trycloudflare.com/chaching/webhooks",
  "enabled_events": [
    "payment_plan.created",
    "payment_plan.activated",
    "payment_plan.installment_paid",
    "payment_plan.installment_failed",
    "payment_plan.completed",
    "payment_plan.canceled",
    "payment_plan.payment_succeeded"
  ],
  "status": "active",
  "signature_key": "endpoint_secret",
  "created": 1794269584,
  "updated": 1794269584,
  "secret": "<redacted len=49>"
}
```

Returns the webhook endpoint with its signing secret in `secret`. The secret is shown only in this response and in a rotation: store it now. Verify every delivery with it; see [Webhooks](/developer-guide/webhook).

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `400` | `WEBHOOK_EVENT_TYPE_UNKNOWN` | An event type is not in the catalog. | Use the names of [Webhooks](/developer-guide/webhook). |
| `400` | no code | `endpoint` is not a public `http` or `https` URL. | Use a public URL; see [Receive webhooks on staging](/developer-guide/integrating-staging#receive-webhooks-on-staging). |
| `409` | `WEBHOOK_ENDPOINTS_LIMIT_REACHED` | Your platform already has 16 endpoints. | Delete one first. |


## 2. Create an account for the location

```bash
curl -X POST https://stage-api.chaching.io/platform/accounts \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: create-account-office-1042-location-7" \
  -d '{
    "external_id": "location-7",
    "name": "Rosen Family Dental - Main Street",
    "company": {
      "external_id": "office-1042",
      "name": "Rosen Family Dental"
    },
    "time_zone": "America/New_York"
  }'
```

```json
{
  "object": "account",
  "id": "acc_52f3ca849c5021b4504c63e5",
  "external_id": "location-7",
  "name": "Rosen Family Dental - Main Street",
  "company": {
    "id": "com_b08861ac3b5790f5f6882ed3",
    "external_id": "office-1042",
    "name": "Rosen Family Dental"
  },
  "time_zone": "America/New_York",
  "status": "active",
  "deactivated_at": null,
  "created": 1795657223
}
```

Returns the Account object with status `201`. Store its `id` (`acc_...`): every later request for this location sends it in `Chaching-Account`. Sending the same `external_id` again returns the same account with status `200`, unchanged, so a lost id is recovered by repeating this request.

```bash
export CHACHING_ACCOUNT_ID="acc_..."
```

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `400` | `ACCOUNT_TIME_ZONE_INVALID` | `time_zone` is not an accepted IANA zone. | Use a US zone such as `America/New_York`. |
| `422` | `IDEMPOTENCY_KEY_REUSED` | The key was used with a different body. | Use a new key. |
| `500` | no code | The outcome is unknown: the account may or may not exist. Repeat the request with the same external_id values (company and account) and a new Idempotency-Key: it returns the existing account or creates it. A billing-engine record created during a failed attempt can remain behind. | Repeat with the same `external_id` values and a NEW `Idempotency-Key`: the create is idempotent on those ids (`200` with the existing account, or `201`). |


## 3. Save the location's Dejavoo credentials

```bash
curl -X PUT https://stage-api.chaching.io/dejavoo/credentials \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "tpn": "123456789012",
    "api_key": "YOUR_IPOSPAYS_API_KEY",
    "secret_key": "YOUR_IPOSPAYS_SECRET_KEY",
    "ecom_token": "YOUR_IPOSPAYS_ECOM_TOKEN"
  }'
```

```json
{
  "object": "dejavoo_credentials",
  "active": true,
  "tpn_set": true,
  "api_key_set": true,
  "secret_key_set": true,
  "secret_key_last4": "t0He",
  "ecom_token_set": true,
  "feed_signing_key_set": false,
  "google_pay_merchant_id_set": false,
  "updated_at": 1795657225
}
```

Returns which credential fields are set; it never returns a value. ChaChing checks the API key and secret key with iPOSpays before saving anything. The first save sets the account's payment gateway to Dejavoo.

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `422` | `DEJAVOO_CREDENTIALS_REJECTED` | iPOSpays refused the API key and secret key. | Check them; on staging they are UAT credentials. |
| `503` | `DEJAVOO_VERIFICATION_UNAVAILABLE` | iPOSpays did not answer. | Nothing was saved; retry. |
| `429` | `PROCESSOR_CREDENTIALS_RATE_LIMITED` | More than 10 saves in a minute for this location. | Wait a minute. |


To receive this location's FEED notifications, add `feed_signing_key` to this request and give Dejavoo the location's FEED webhook URL; see [The Dejavoo FEED Webhook URL](/developer-guide/processor-credentials#the-dejavoo-feed-webhook-url).

## 4. Register the terminal

```bash
curl -X POST https://stage-api.chaching.io/dejavoo/terminals \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "tpn": "123456789013",
    "label": "Front desk",
    "spin_auth_key": "SPINAUTH10"
  }'
```

```json
{
  "id": "f9fb0123-89b1-4e5e-ac98-98b7eb1a94bb",
  "object": "dejavoo_terminal",
  "tpn": "123456789013",
  "label": "Front desk",
  "enabled": true,
  "register_id": null,
  "isv_id": null,
  "spin_auth_key_set": true,
  "credential_rotated_at": null,
  "last_probe_at": 1795657234,
  "last_probe_status": "Online",
  "build": null,
  "serial": null,
  "feed_enable_requested_at": null,
  "created": 1795657234
}
```

Returns the terminal with status `201`. Store its `id`: you name it when you collect a deposit. The SPIn Auth Key is never returned.

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `409` | `DEJAVOO_NOT_CONFIGURED` | Step 3 was not done. | Save the credentials first. |
| `409` | `TERMINAL_TPN_EXISTS` | The TPN is already registered on this account. | List the terminals with `GET /dejavoo/terminals`. |
| `422` | `SPIN_CREDENTIALS_REJECTED` | SPIn refused the TPN and Auth Key pair. | Check both values. |
| `503` | `SPIN_UNREACHABLE` | SPIn did not answer. | Nothing was saved; retry. |


## 5. Create the customer

```bash
curl -X POST https://stage-api.chaching.io/customers \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jenny Rosen",
    "email": "jenny.rosen@example.com",
    "external_id": "patient-55821"
  }'
```

```json
{
  "id": "cus_e858445ae329019c9e385ea5",
  "object": "customer",
  "name": "Jenny Rosen",
  "email": "jenny.rosen@example.com",
  "external_id": "patient-55821",
  "phone": null,
  "description": null,
  "created": 1795657235,
  "currency": "usd",
  "address": {
    "line1": null,
    "line2": null,
    "city": null,
    "state": null,
    "postal_code": null,
    "country": null
  },
  "shipping": {
    "name": "Jenny Rosen",
    "phone": "",
    "address": {
      "line1": null,
      "line2": null,
      "city": null,
      "state": null,
      "postal_code": null,
      "country": null
    }
  }
}
```

Returns the Customer object with status `201`. `external_id` is your own id for the patient; find the customer later with `GET /customers?external_id=patient-55821`.

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `409` | `PAYMENT_GATEWAY_NOT_CONFIGURED` | The account has no credentials yet. | Do step 3 first. |
| `409` | `CUSTOMER_EXTERNAL_ID_EXISTS` | An active customer already has this `external_id`. | Use the customer the message names. |
| `400` | no code | `name` is missing, or `email` is not an email. | Fix the body. |


## 6. Preview the schedule

```bash
curl -X POST https://stage-api.chaching.io/payment-plans/preview \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "CUSTOMER_ID",
    "total_amount": 1200,
    "down_payment_amount": 100,
    "installment_count": 11,
    "interval": "monthly",
    "start_date": 1811808000
  }'
```

```json
{
  "object": "payment_plan_preview",
  "mode": "terminal_deposit",
  "customer": "cus_e858445ae329019c9e385ea5",
  "total_amount": 1200,
  "down_payment_amount": 100,
  "financed_amount": 1100,
  "installment_amount": 100,
  "installment_count": 11,
  "interval": "monthly",
  "remainder_placement": "first",
  "start_date": 1811808000,
  "installments": [
    {
      "sequence": 1,
      "due_date": 1811808000,
      "amount": 100
    },
    {
      "sequence": 2,
      "due_date": 1814400000,
      "amount": 100
    },
    {
      "sequence": 3,
      "due_date": 1817078400,
      "amount": 100
    },
    {
      "sequence": 4,
      "due_date": 1819756800,
      "amount": 100
    },
    {
      "sequence": 5,
      "due_date": 1822348800,
      "amount": 100
    },
    {
      "sequence": 6,
      "due_date": 1825027200,
      "amount": 100
    },
    {
      "sequence": 7,
      "due_date": 1827619200,
      "amount": 100
    },
    {
      "sequence": 8,
      "due_date": 1830297600,
      "amount": 100
    },
    {
      "sequence": 9,
      "due_date": 1832976000,
      "amount": 100
    },
    {
      "sequence": 10,
      "due_date": 1835481600,
      "amount": 100
    },
    {
      "sequence": 11,
      "due_date": 1838160000,
      "amount": 100
    }
  ]
}
```

Returns the schedule the plan would have, with nothing created. Replace `CUSTOMER_ID` with the id from step 5, and `start_date` (here 1 June 2027, 00:00 UTC) with any date later than today, in UTC and in the account's time zone; the example date works as is until then. See `start_date` in [Create a Plan](/developer-guide/payment-plans#create-a-plan) for the full rule.

## 7. Create the plan

Leave out `payment_method`: the plan waits for its down payment on the terminal.

```bash
curl -X POST https://stage-api.chaching.io/payment-plans \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: plan-patient-55821-treatment-1" \
  -d '{
    "customer": "CUSTOMER_ID",
    "external_id": "treatment-1",
    "description": "Orthodontic treatment",
    "total_amount": 1200,
    "down_payment_amount": 100,
    "installment_count": 11,
    "interval": "monthly",
    "start_date": 1811808000
  }'
```

```json
{
  "id": "pp_849639436a2cee4e5818694f",
  "object": "payment_plan",
  "external_id": "treatment-1",
  "customer": "cus_e858445ae329019c9e385ea5",
  "customer_external_id": "patient-55821",
  "description": "Orthodontic treatment",
  "status": "awaiting_deposit",
  "currency": "USD",
  "total_amount": 1200,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 11,
  "interval": "monthly",
  "start_date": 1811808000,
  "remainder_placement": "first",
  "remaining_balance": 1200,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 12,
  "next_due_date": 1795564800,
  "payment_method": null,
  "gateway": null,
  "reference": "G80DISXZ",
  "deposit": {
    "reference": "G80DISXZ",
    "kind": "down_payment",
    "amount": 100,
    "status": "pending",
    "transaction_reference": null,
    "collected_at": null,
    "attempt": null,
    "external": false
  },
  "created": 1795657236,
  "ended_at": null,
  "canceled_at": null
}
```

Returns the Payment Plan object with status `201` in status `awaiting_deposit`. Its `deposit` object names the `amount` the terminal collects. Nothing is charged until the deposit is collected. `next_due_date` is the due date of the earliest installment still `scheduled` or `failed`; while the plan waits for its deposit that installment is the deposit itself, so `next_due_date` reads earlier than `start_date`. When the customer pays the deposit outside ChaChing instead, record it with `POST /payment-plans/{id}/payments` and `external: true`; see [Record a Deposit Collected Outside Chaching](/developer-guide/payment-plans#record-a-deposit-collected-outside-chaching). Store the plan's `id`:

```bash
export PLAN_ID="pp_..."
```

| Status | Error code | When | What to do |
|  --- | --- | --- | --- |
| `400` | `PAYMENT_PLAN_START_DATE_INVALID` | `start_date` is not after today. | The message names the earliest valid date. |
| `409` | `PAYMENT_PLAN_EXTERNAL_ID_EXISTS` | A plan of this account already has this `external_id`. | Read that plan. |
| `409` | `PAYMENT_PLAN_CUSTOMER_DELINQUENT` | The customer has an invoice unpaid for one day or more, or is in the late-payment warning. | Collect the balance first. |


## 8. Collect the down payment on the terminal

```bash
curl -X POST https://stage-api.chaching.io/payment-plans/$PLAN_ID/deposit/terminal \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "terminal_id": "TERMINAL_ID"
  }'
```

```json
{
  "id": "pp_849639436a2cee4e5818694f",
  "object": "payment_plan",
  "external_id": "treatment-1",
  "customer": "cus_e858445ae329019c9e385ea5",
  "customer_external_id": "patient-55821",
  "description": "Orthodontic treatment",
  "status": "awaiting_deposit",
  "currency": "USD",
  "total_amount": 1200,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 11,
  "interval": "monthly",
  "start_date": 1811808000,
  "remainder_placement": "first",
  "remaining_balance": 1200,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 12,
  "next_due_date": 1795564800,
  "payment_method": null,
  "gateway": null,
  "reference": "G80DISXZ",
  "deposit": {
    "reference": "G80DISXZ",
    "kind": "down_payment",
    "amount": 100,
    "status": "pending",
    "transaction_reference": null,
    "collected_at": null,
    "attempt": {
      "id": "ppda_c8708021cc8a715f7b8781c2",
      "object": "payment_plan_deposit_attempt",
      "terminal": "f9fb0123-89b1-4e5e-ac98-98b7eb1a94bb",
      "reference_id": "G80DISXZ01",
      "state": "in_flight",
      "started": 1795657239,
      "resolved": null,
      "decline_code": null,
      "decline_message": null,
      "surcharge_amount": 0,
      "amount_charged": 0
    },
    "external": false
  },
  "created": 1795657236,
  "ended_at": null,
  "canceled_at": null
}
```

Replace `TERMINAL_ID` with the terminal `id` from step 4. Returns the plan with status `202`; `deposit.attempt.state` is `in_flight` and the terminal shows the amount. The patient presents the card.

### No terminal at hand

If the practice collected the deposit at its front desk, or you are testing with no terminal, record it instead with `POST /payment-plans/{id}/payments` and `"external": true`. Nothing is charged.

```bash
curl -X POST https://stage-api.chaching.io/payment-plans/$PLAN_ID/payments \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 100,
    "external": true
  }'
```

```json
{
  "id": "ppp_YRy082lETL7vBxFOKy4izlXt",
  "object": "payment_plan_payment",
  "payment_plan": "pp_849639436a2cee4e5818694f",
  "payment_plan_external_id": "treatment-1",
  "customer": "cus_e858445ae329019c9e385ea5",
  "customer_external_id": "patient-55821",
  "status": "applied",
  "origin": "payment",
  "failure_code": null,
  "failure_message": null,
  "amount": 100,
  "surcharge_amount": 0,
  "amount_charged": 100,
  "amount_refunded": 0,
  "amount_unapplied": 0,
  "amount_unapplied_refunded": 0,
  "surcharge_status": "final",
  "external": true,
  "payment_method": null,
  "card": null,
  "invoice": "dfdd0419-550a-40d1-8653-4d0f40721450",
  "hosted_invoice_url": "https://stage.chaching.io/checkout/dfdd0419-550a-40d1-8653-4d0f40721450",
  "payoff": false,
  "created": 1796068875,
  "payment_plan_status": "active",
  "remaining_balance": 1100,
  "installments_remaining": 11,
  "allocations": [
    {
      "installment": "ppi_c90ab094c3596146af20089e",
      "sequence": 0,
      "kind": "installment",
      "amount": 100,
      "surcharge_amount": 0,
      "amount_charged": 100,
      "surcharge_status": "final",
      "invoice": "dfdd0419-550a-40d1-8653-4d0f40721450",
      "hosted_invoice_url": "https://stage.chaching.io/checkout/dfdd0419-550a-40d1-8653-4d0f40721450",
      "gateway_reference": null
    }
  ],
  "refunds": [],
  "payment_plan_summary": {
    "installment_count": 11,
    "currency": "USD",
    "description": "Orthodontic treatment",
    "remaining_balance": 1100,
    "installments_paid": 0,
    "installments_remaining": 11,
    "next_due_date": 1811808000,
    "status": "active"
  },
  "terminal": null
}
```

The request answers `201` with the Payment object: `external` is `true`, `card` and `payment_method` are `null`, and `allocations` shows the deposit paid as installment `0`. The plan becomes `active`. On a platform account the `hosted_invoice_url` values do not open (see [Platforms](/developer-guide/platforms#what-does-not-apply-to-a-platform-account)): do not send them to the patient. Without a `payment_method` the plan has no card on file: its `payment_method` stays `null` and nothing is charged automatically on the due dates; see [The Card on File](/developer-guide/payment-plans#the-card-on-file) and [Record a Deposit Collected Outside Chaching](/developer-guide/payment-plans#record-a-deposit-collected-outside-chaching) for how each remaining installment is collected. Step 9 waits for a terminal answer, so skip it and continue at step 10.

## 9. Wait for the answer

```bash
curl https://stage-api.chaching.io/payment-plans/$PLAN_ID \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID"
```

```json
{
  "id": "pp_849639436a2cee4e5818694f",
  "object": "payment_plan",
  "external_id": "treatment-1",
  "customer": "cus_e858445ae329019c9e385ea5",
  "customer_external_id": "patient-55821",
  "description": "Orthodontic treatment",
  "status": "active",
  "currency": "USD",
  "total_amount": 1200,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 11,
  "interval": "monthly",
  "start_date": 1811808000,
  "remainder_placement": "first",
  "remaining_balance": 1100,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 11,
  "next_due_date": 1811808000,
  "payment_method": "6c48dee7-fc1b-4e07-8ecc-0864fe7e1e46",
  "gateway": "dejavoo",
  "reference": "G80DISXZ",
  "deposit": {
    "reference": "G80DISXZ",
    "kind": "down_payment",
    "amount": 100,
    "status": "collected",
    "transaction_reference": "00000411812636285020261125204047",
    "collected_at": 1795657252,
    "attempt": {
      "id": "ppda_c8708021cc8a715f7b8781c2",
      "object": "payment_plan_deposit_attempt",
      "terminal": "f9fb0123-89b1-4e5e-ac98-98b7eb1a94bb",
      "reference_id": "G80DISXZ01",
      "state": "approved",
      "started": 1795657239,
      "resolved": 1795657252,
      "decline_code": null,
      "decline_message": null,
      "surcharge_amount": 3,
      "amount_charged": 103
    },
    "external": false
  },
  "created": 1795657236,
  "ended_at": null,
  "canceled_at": null
}
```

Poll every 2 to 3 seconds until `deposit.attempt.state` is no longer `in_flight`; it leaves that state at most 240 seconds after it started. `approved` saves the card and the plan becomes `active`. Every other state is described in [Deposit Attempt States](/developer-guide/payment-plans-terminal#deposit-attempt-states).

## 10. Read the delivery of an event

```bash
curl -G https://stage-api.chaching.io/webhook-deliveries \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  --data-urlencode 'search={"event_type":"payment_plan.created"}'
```

```json
{
  "data": [
    {
      "id": "whd_f49e584e879fea1d93599349",
      "object": "webhook_delivery",
      "account": "acc_52f3ca849c5021b4504c63e5",
      "event": "evt_fbf6a18e5d0d43754c5341aa",
      "event_type": "payment_plan.created",
      "webhook_endpoint": "4a19c6f9-c4c8-4b79-b9a1-379260670c3d",
      "endpoint": "https://doctor-cycling-likewise-brother.trycloudflare.com/chaching/webhooks",
      "status": "success",
      "response_status_code": 200,
      "next_attempt": null,
      "created": 1795657236,
      "updated": 1795657236
    }
  ],
  "meta": {
    "page": 1,
    "take": 10,
    "items_total": 1,
    "pages_total": 1
  }
}
```

Returns one page of the account's deliveries of that event type. Store the `id` of the first one (`whd_...`) in `DELIVERY_ID` and read it:

```bash
curl https://stage-api.chaching.io/webhook-deliveries/$DELIVERY_ID \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID"
```

```json
{
  "id": "whd_f49e584e879fea1d93599349",
  "object": "webhook_delivery",
  "account": "acc_52f3ca849c5021b4504c63e5",
  "event": "evt_fbf6a18e5d0d43754c5341aa",
  "event_type": "payment_plan.created",
  "webhook_endpoint": "4a19c6f9-c4c8-4b79-b9a1-379260670c3d",
  "endpoint": "https://doctor-cycling-likewise-brother.trycloudflare.com/chaching/webhooks",
  "status": "success",
  "response_status_code": 200,
  "next_attempt": null,
  "created": 1795657236,
  "updated": 1795657236,
  "payload": {
    "id": "evt_fbf6a18e5d0d43754c5341aa",
    "account": {
      "id": "acc_52f3ca849c5021b4504c63e5",
      "external_id": "location-7",
      "company": {
        "id": "com_b08861ac3b5790f5f6882ed3",
        "external_id": "office-1042"
      }
    },
    "created": 1795657236,
    "createdAt": "2026-11-26T01:40:36.128Z",
    "data": {
      "id": "pp_849639436a2cee4e5818694f",
      "object": "payment_plan",
      "status": "awaiting_deposit",
      "created": 1795657236,
      "deposit": {
        "kind": "down_payment",
        "amount": 100,
        "status": "pending",
        "attempt": null,
        "external": false,
        "reference": "G80DISXZ",
        "collected_at": null,
        "transaction_reference": null
      },
      "gateway": null,
      "currency": "USD",
      "customer": "cus_e858445ae329019c9e385ea5",
      "ended_at": null,
      "interval": "monthly",
      "reference": "G80DISXZ",
      "amount_due": 0,
      "amount_written_off": 0,
      "start_date": 1811808000,
      "canceled_at": null,
      "description": "Orthodontic treatment",
      "external_id": "treatment-1",
      "total_amount": 1200,
      "next_due_date": 1795564800,
      "payment_method": null,
      "amount_refunded": 0,
      "installment_count": 11,
      "installments_paid": 0,
      "remaining_balance": 1200,
      "installment_amount": 100,
      "down_payment_amount": 100,
      "remainder_placement": "first",
      "customer_external_id": "patient-55821",
      "installments_remaining": 12
    },
    "event": "payment_plan.created"
  },
  "attempts": [
    {
      "attempt": 1,
      "created": 1795657236,
      "response_status_code": 200,
      "response_body": "{\"ok\":true}",
      "response_body_truncated": false,
      "error": null
    }
  ]
}
```

Returns the delivery with the payload sent and every attempt. Your endpoint received the same payload; its envelope `account.external_id` is `location-7` and `account.company.external_id` is `office-1042`.

## 11. List the installments

Abridged: the answer lists all 12 installments; two are shown. On a platform account `hosted_invoice_url` does not open (see [Platforms](/developer-guide/platforms#what-does-not-apply-to-a-platform-account)): do not send it to the patient.

```bash
curl -G https://stage-api.chaching.io/payment-plans/$PLAN_ID/installments \
  -H "cc-api-key: $CHACHING_PLATFORM_KEY" \
  -H "Chaching-Account: $CHACHING_ACCOUNT_ID" \
  -d take=50
```

```json
{
  "data": [
    {
      "id": "ppi_b5e46aec2b3b5238cc648cca",
      "object": "payment_plan_installment",
      "payment_plan": "pp_849639436a2cee4e5818694f",
      "payment_plan_external_id": "treatment-1",
      "customer": "cus_e858445ae329019c9e385ea5",
      "customer_external_id": "patient-55821",
      "sequence": 0,
      "due_date": 1795564800,
      "amount": 100,
      "amount_paid": 100,
      "amount_refunded": 0,
      "amount_due": 0,
      "amount_written_off": 0,
      "surcharge_amount": 3,
      "amount_charged": 103,
      "surcharge_status": "final",
      "status": "paid",
      "attempt_count": 1,
      "next_payment_attempt": null,
      "paid_at": 1795657252,
      "written_off_at": null,
      "first_failed_at": null,
      "failure_code": null,
      "failure_message": null,
      "card": {
        "brand": "mastercard",
        "last4": "2805"
      },
      "invoice": "62e2f332-b588-46d3-bc9a-4b416e3efb46",
      "hosted_invoice_url": "https://stage.chaching.io/checkout/62e2f332-b588-46d3-bc9a-4b416e3efb46",
      "payments": [
        "ppp_b9d87d012cd18603ed3e3ab8"
      ],
      "payment_plan_summary": {
        "installment_count": 11,
        "currency": "USD",
        "description": "Orthodontic treatment",
        "remaining_balance": 1100,
        "installments_paid": 0,
        "installments_remaining": 11,
        "next_due_date": 1811808000,
        "status": "active"
      }
    },
    {
      "id": "ppi_aac5e5f672c45c33aba759d2",
      "object": "payment_plan_installment",
      "payment_plan": "pp_849639436a2cee4e5818694f",
      "payment_plan_external_id": "treatment-1",
      "customer": "cus_e858445ae329019c9e385ea5",
      "customer_external_id": "patient-55821",
      "sequence": 1,
      "due_date": 1811808000,
      "amount": 100,
      "amount_paid": 0,
      "amount_refunded": 0,
      "amount_due": 0,
      "amount_written_off": 0,
      "surcharge_amount": 0,
      "amount_charged": 0,
      "surcharge_status": "final",
      "status": "scheduled",
      "attempt_count": 0,
      "next_payment_attempt": null,
      "paid_at": null,
      "written_off_at": null,
      "first_failed_at": null,
      "failure_code": null,
      "failure_message": null,
      "card": null,
      "invoice": null,
      "hosted_invoice_url": null,
      "payments": [],
      "payment_plan_summary": {
        "installment_count": 11,
        "currency": "USD",
        "description": "Orthodontic treatment",
        "remaining_balance": 1100,
        "installments_paid": 0,
        "installments_remaining": 11,
        "next_due_date": 1811808000,
        "status": "active"
      }
    }
  ],
  "meta": {
    "page": 1,
    "take": 50,
    "items_total": 12,
    "pages_total": 1
  }
}
```

Returns one page of installments; installment `0` is the down payment. ChaChing charges the next installment on its `due_date` to the card the terminal saved. A plan whose deposit you recorded with `external: true` has no card: nothing is charged automatically.

To integrate your own account with its secret key and no `Chaching-Account` header, follow the [single-account quickstart](/developer-guide/quickstart-single-account).