# Quickstart: Your First Payment Plan on Your Own Account

This quickstart is for a merchant that integrates its own ChaChing account. It registers a webhook endpoint, creates a customer, previews and creates a payment plan with a down payment, collects the down payment on your Dejavoo terminal, reads a webhook delivery and lists the installments. Every request carries your account's secret key in the `cc-api-key` header and no `Chaching-Account` header. A platform that operates many locations follows the [platform quickstart](/developer-guide/quickstart-payment-plan) instead.

The requests go to the staging API, `https://stage-api.chaching.io`, and the amounts are cents: `100` is $1.00, an amount the iPOSpays UAT host approves on staging (see [Test cards and amounts](/developer-guide/integrating-staging#test-cards-and-amounts)).

## Before you start

- Your account's secret key (`sk_...`), created in the dashboard under **Settings, Developer settings** and stored in `CHACHING_SECRET_KEY`. See [Developer Settings](/settings/developersettings).
- Payment plans enabled for your account: an account created in the dashboard has them off until ChaChing enables them, and every `/payment-plans` request answers `403 PAYMENT_PLANS_NOT_ENABLED` until then. See [Payment Plans](/developer-guide/payment-plans).
- Your account's Dejavoo (iPOSpays) credentials saved and one Dejavoo terminal registered. Through the API, see [Processor Credentials](/developer-guide/processor-credentials) and [Register a Dejavoo Terminal](/developer-guide/payment-plans-terminal#register-a-dejavoo-terminal).
- A public HTTPS URL for webhooks; see [Receive webhooks on staging](/developer-guide/integrating-staging#receive-webhooks-on-staging).


```bash
export CHACHING_SECRET_KEY="sk_..."
```

## 1. Register a webhook endpoint

```bash
curl -X POST https://stage-api.chaching.io/webhook-endpoints \
  -H "cc-api-key: $CHACHING_SECRET_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": "93bfe8a6-e2cf-4d74-8898-71bf02740358",
  "object": "webhook_endpoint",
  "endpoint": "https://example.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": 1796068502,
  "updated": 1796068502,
  "secret": "<redacted len=49>"
}
```

Answers `201` with the endpoint. Its `secret` (`whsec_...`) signs every delivery and appears only in this answer and after a rotation, so save it before you continue; [Webhook Signatures](/developer-guide/webhook#webhook-signatures) shows how to check a delivery with it.

## 2. Find your terminal

```bash
curl https://stage-api.chaching.io/dejavoo/terminals \
  -H "cc-api-key: $CHACHING_SECRET_KEY"
```

```json
{
  "data": [
    {
      "id": "7309c7f2-68da-4f98-a866-86331068f93a",
      "object": "dejavoo_terminal",
      "tpn": "123456789013",
      "label": "UAT P1",
      "enabled": true,
      "register_id": null,
      "isv_id": null,
      "spin_auth_key_set": true,
      "credential_rotated_at": 1791760446,
      "last_probe_at": 1796066758,
      "last_probe_status": "Online",
      "build": null,
      "serial": "P1260428000529",
      "feed_enable_requested_at": 1791760425,
      "created": 1791760425
    }
  ]
}
```

Answers `200` with your account's terminals in `data`. Keep the `id` of an `enabled` terminal whose `last_probe_status` is `Online`: step 6 sends it.

```bash
export TERMINAL_ID="..."
```

## 3. Create the customer

```bash
curl -X POST https://stage-api.chaching.io/customers \
  -H "cc-api-key: $CHACHING_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Avery Quinn",
    "external_id": "client-5524"
  }'
```

```json
{
  "id": "cus_613663ea518955ea5d8f5358",
  "object": "customer",
  "name": "Avery Quinn",
  "email": null,
  "external_id": "client-5524",
  "phone": null,
  "description": null,
  "created": 1796068504,
  "currency": "usd",
  "address": {
    "line1": null,
    "line2": null,
    "city": null,
    "state": null,
    "postal_code": null,
    "country": null
  },
  "shipping": {
    "name": "Avery Quinn",
    "phone": "",
    "address": {
      "line1": null,
      "line2": null,
      "city": null,
      "state": null,
      "postal_code": null,
      "country": null
    }
  }
}
```

Answers `201` with the Customer object; keep its `id` (`cus_...`). On a Dejavoo account `email` is optional, and a customer without one receives no email from ChaChing. Your own id in `external_id` finds the customer again with `GET /customers?external_id=client-5524`.

## 4. Preview the schedule

```bash
curl -X POST https://stage-api.chaching.io/payment-plans/preview \
  -H "cc-api-key: $CHACHING_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "CUSTOMER_ID",
    "total_amount": 300,
    "down_payment_amount": 100,
    "installment_count": 2,
    "interval": "monthly",
    "start_date": 1798761600
  }'
```

```json
{
  "object": "payment_plan_preview",
  "mode": "terminal_deposit",
  "customer": "cus_613663ea518955ea5d8f5358",
  "total_amount": 300,
  "down_payment_amount": 100,
  "financed_amount": 200,
  "installment_amount": 100,
  "installment_count": 2,
  "interval": "monthly",
  "remainder_placement": "first",
  "start_date": 1798761600,
  "installments": [
    {
      "sequence": 1,
      "due_date": 1798761600,
      "amount": 100
    },
    {
      "sequence": 2,
      "due_date": 1801440000,
      "amount": 100
    }
  ]
}
```

Answers `200` with the schedule this body would create, and creates nothing. Put the customer id from step 3 in place of `CUSTOMER_ID`, and a day after today in `start_date` (`1798761600` is 1 January 2027, 00:00 UTC).

## 5. Create the plan

```bash
curl -X POST https://stage-api.chaching.io/payment-plans \
  -H "cc-api-key: $CHACHING_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: plan-client-5524-whitening-1" \
  -d '{
    "customer": "CUSTOMER_ID",
    "external_id": "whitening-5524",
    "description": "Teeth whitening",
    "total_amount": 300,
    "down_payment_amount": 100,
    "installment_count": 2,
    "interval": "monthly",
    "start_date": 1798761600
  }'
```

```json
{
  "id": "pp_15296da1317452bc4ef3642e",
  "object": "payment_plan",
  "external_id": "whitening-5524",
  "customer": "cus_613663ea518955ea5d8f5358",
  "customer_external_id": "client-5524",
  "description": "Teeth whitening",
  "status": "awaiting_deposit",
  "currency": "USD",
  "total_amount": 300,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 2,
  "interval": "monthly",
  "start_date": 1798761600,
  "remainder_placement": "first",
  "remaining_balance": 300,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 3,
  "next_due_date": 1795996800,
  "payment_method": null,
  "gateway": null,
  "reference": "REO0BJ5K",
  "deposit": {
    "reference": "REO0BJ5K",
    "kind": "down_payment",
    "amount": 100,
    "status": "pending",
    "transaction_reference": null,
    "collected_at": null,
    "attempt": null,
    "external": false
  },
  "created": 1796068504,
  "ended_at": null,
  "canceled_at": null
}
```

Without `payment_method`, the plan answers `201` in status `awaiting_deposit`, and `deposit.amount` is what the terminal collects. Keep the plan's `id`:

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

## 6. Collect the down payment on your terminal

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

```json
{
  "id": "pp_15296da1317452bc4ef3642e",
  "object": "payment_plan",
  "external_id": "whitening-5524",
  "customer": "cus_613663ea518955ea5d8f5358",
  "customer_external_id": "client-5524",
  "description": "Teeth whitening",
  "status": "awaiting_deposit",
  "currency": "USD",
  "total_amount": 300,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 2,
  "interval": "monthly",
  "start_date": 1798761600,
  "remainder_placement": "first",
  "remaining_balance": 300,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 3,
  "next_due_date": 1795996800,
  "payment_method": null,
  "gateway": null,
  "reference": "REO0BJ5K",
  "deposit": {
    "reference": "REO0BJ5K",
    "kind": "down_payment",
    "amount": 100,
    "status": "pending",
    "transaction_reference": null,
    "collected_at": null,
    "attempt": {
      "id": "ppda_cc7afc802452fc09d0ebef74",
      "object": "payment_plan_deposit_attempt",
      "terminal": "7309c7f2-68da-4f98-a866-86331068f93a",
      "reference_id": "REO0BJ5K01",
      "state": "in_flight",
      "started": 1796068589,
      "resolved": null,
      "decline_code": null,
      "decline_message": null,
      "surcharge_amount": 0,
      "amount_charged": 0
    },
    "external": false
  },
  "created": 1796068504,
  "ended_at": null,
  "canceled_at": null
}
```

Answers `202`, and `deposit.attempt.state` reads `in_flight`. The terminal shows the amount, with the credit card surcharge your account adds when the card is a credit card; your customer confirms it and presents the card. See [Credit Card Surcharges](/developer-guide/card-surcharges).

## 7. Wait for the terminal's answer

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

```json
{
  "id": "pp_15296da1317452bc4ef3642e",
  "object": "payment_plan",
  "external_id": "whitening-5524",
  "customer": "cus_613663ea518955ea5d8f5358",
  "customer_external_id": "client-5524",
  "description": "Teeth whitening",
  "status": "active",
  "currency": "USD",
  "total_amount": 300,
  "down_payment_amount": 100,
  "installment_amount": 100,
  "installment_count": 2,
  "interval": "monthly",
  "start_date": 1798761600,
  "remainder_placement": "first",
  "remaining_balance": 200,
  "amount_refunded": 0,
  "amount_due": 0,
  "amount_written_off": 0,
  "installments_paid": 0,
  "installments_remaining": 2,
  "next_due_date": 1798761600,
  "payment_method": "55f87086-2f58-4fec-a763-6d22a896ff34",
  "gateway": "dejavoo",
  "reference": "REO0BJ5K",
  "deposit": {
    "reference": "REO0BJ5K",
    "kind": "down_payment",
    "amount": 100,
    "status": "collected",
    "transaction_reference": "00000612345678901320261130145635",
    "collected_at": 1796068599,
    "attempt": {
      "id": "ppda_cc7afc802452fc09d0ebef74",
      "object": "payment_plan_deposit_attempt",
      "terminal": "7309c7f2-68da-4f98-a866-86331068f93a",
      "reference_id": "REO0BJ5K01",
      "state": "approved",
      "started": 1796068589,
      "resolved": 1796068599,
      "decline_code": null,
      "decline_message": null,
      "surcharge_amount": 3,
      "amount_charged": 103
    },
    "external": false
  },
  "created": 1796068504,
  "ended_at": null,
  "canceled_at": null
}
```

Repeat the request every 2 to 3 seconds while `deposit.attempt.state` is `in_flight`; an attempt stays there for 240 seconds at most. On `approved` the card is saved and the plan is `active`; `deposit.attempt.surcharge_amount` and `deposit.attempt.amount_charged` give the surcharge the terminal added and the total the card paid. [Deposit Attempt States](/developer-guide/payment-plans-terminal#deposit-attempt-states) explains the other states.

## 8. Read a webhook delivery

```bash
curl -G https://stage-api.chaching.io/webhook-deliveries \
  -H "cc-api-key: $CHACHING_SECRET_KEY" \
  --data-urlencode 'search={"event_type":"payment_plan.activated","endpoint":"https://example.com/chaching/webhooks"}'
```

```json
{
  "data": [
    {
      "id": "whd_c0dddba6123c601aa9c768db",
      "object": "webhook_delivery",
      "account": "acc_7b3d4564e53790c3dc62e215",
      "event": "evt_cd6bf5e4c2140018a16823cf",
      "event_type": "payment_plan.activated",
      "webhook_endpoint": "93bfe8a6-e2cf-4d74-8898-71bf02740358",
      "endpoint": "https://example.com/chaching/webhooks",
      "status": "success",
      "response_status_code": 200,
      "next_attempt": null,
      "created": 1796068605,
      "updated": 1796068605
    }
  ],
  "meta": {
    "page": 1,
    "take": 10,
    "items_total": 1,
    "pages_total": 1
  }
}
```

Answers `200` with a page of your account's deliveries of `payment_plan.activated`. Put the `id` (`whd_...`) of the first one in `DELIVERY_ID`:

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

```json
{
  "id": "whd_c0dddba6123c601aa9c768db",
  "object": "webhook_delivery",
  "account": "acc_7b3d4564e53790c3dc62e215",
  "event": "evt_cd6bf5e4c2140018a16823cf",
  "event_type": "payment_plan.activated",
  "webhook_endpoint": "93bfe8a6-e2cf-4d74-8898-71bf02740358",
  "endpoint": "https://example.com/chaching/webhooks",
  "status": "success",
  "response_status_code": 200,
  "next_attempt": null,
  "created": 1796068605,
  "updated": 1796068605,
  "payload": {
    "id": "evt_cd6bf5e4c2140018a16823cf",
    "account": {
      "id": "acc_7b3d4564e53790c3dc62e215",
      "external_id": null,
      "company": {
        "id": "com_53e6335346ee4dd4ba916246",
        "external_id": null
      }
    },
    "created": 1796068605,
    "createdAt": "2026-11-30T19:56:45.133Z",
    "data": {
      "id": "pp_15296da1317452bc4ef3642e",
      "object": "payment_plan",
      "status": "active",
      "created": 1796068504,
      "deposit": {
        "kind": "down_payment",
        "amount": 100,
        "status": "collected",
        "attempt": {
          "id": "ppda_cc7afc802452fc09d0ebef74",
          "state": "approved",
          "object": "payment_plan_deposit_attempt",
          "started": 1796068589,
          "resolved": 1796068599,
          "terminal": "7309c7f2-68da-4f98-a866-86331068f93a",
          "decline_code": null,
          "reference_id": "REO0BJ5K01",
          "amount_charged": 103,
          "decline_message": null,
          "surcharge_amount": 3
        },
        "external": false,
        "reference": "REO0BJ5K",
        "collected_at": 1796068599,
        "transaction_reference": "00000612345678901320261130145635"
      },
      "gateway": "dejavoo",
      "currency": "USD",
      "customer": "cus_613663ea518955ea5d8f5358",
      "ended_at": null,
      "interval": "monthly",
      "reference": "REO0BJ5K",
      "amount_due": 0,
      "start_date": 1798761600,
      "canceled_at": null,
      "description": "Teeth whitening",
      "external_id": "whitening-5524",
      "total_amount": 300,
      "next_due_date": 1798761600,
      "payment_method": "55f87086-2f58-4fec-a763-6d22a896ff34",
      "amount_refunded": 0,
      "installment_count": 2,
      "installments_paid": 0,
      "remaining_balance": 200,
      "amount_written_off": 0,
      "installment_amount": 100,
      "down_payment_amount": 100,
      "remainder_placement": "first",
      "customer_external_id": "client-5524",
      "installments_remaining": 2
    },
    "event": "payment_plan.activated"
  },
  "attempts": [
    {
      "attempt": 1,
      "created": 1796068605,
      "response_status_code": 200,
      "response_body": "{\"ok\":true}",
      "response_body_truncated": false,
      "error": null
    }
  ]
}
```

The delivery carries the payload your endpoint received and every attempt with the answer your endpoint gave. In the envelope, `account.id` is your account and `account.external_id` is `null`, because the account was created in the dashboard.

## 9. List the installments

```bash
curl https://stage-api.chaching.io/payment-plans/$PLAN_ID/installments \
  -H "cc-api-key: $CHACHING_SECRET_KEY"
```

```json
{
  "data": [
    {
      "id": "ppi_10a8ebab6943fdf6123c3d82",
      "object": "payment_plan_installment",
      "payment_plan": "pp_15296da1317452bc4ef3642e",
      "payment_plan_external_id": "whitening-5524",
      "customer": "cus_613663ea518955ea5d8f5358",
      "customer_external_id": "client-5524",
      "sequence": 0,
      "due_date": 1795996800,
      "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": 1796068599,
      "written_off_at": null,
      "first_failed_at": null,
      "failure_code": null,
      "failure_message": null,
      "card": {
        "brand": "mastercard",
        "last4": "2805"
      },
      "gateway_reference": {
        "transaction_id": "00000612345678901320261130145635",
        "rrn": "633419500878",
        "auth_code": "VTLMC1",
        "batch_number": "74",
        "tpn": "123456789013"
      },
      "invoice": "3d54954c-c273-4e41-b280-36659f76e12d",
      "hosted_invoice_url": "https://stage.chaching.io/checkout/3d54954c-c273-4e41-b280-36659f76e12d",
      "payments": [
        "ppp_bfdbe704fe242137a2c23048"
      ],
      "payment_plan_summary": {
        "installment_count": 2,
        "currency": "USD",
        "description": "Teeth whitening",
        "remaining_balance": 200,
        "installments_paid": 0,
        "installments_remaining": 2,
        "next_due_date": 1798761600,
        "status": "active"
      }
    },
    {
      "id": "ppi_534a278fcb743e0bea164e61",
      "object": "payment_plan_installment",
      "payment_plan": "pp_15296da1317452bc4ef3642e",
      "payment_plan_external_id": "whitening-5524",
      "customer": "cus_613663ea518955ea5d8f5358",
      "customer_external_id": "client-5524",
      "sequence": 1,
      "due_date": 1798761600,
      "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,
      "gateway_reference": null,
      "invoice": null,
      "hosted_invoice_url": null,
      "payments": [],
      "payment_plan_summary": {
        "installment_count": 2,
        "currency": "USD",
        "description": "Teeth whitening",
        "remaining_balance": 200,
        "installments_paid": 0,
        "installments_remaining": 2,
        "next_due_date": 1798761600,
        "status": "active"
      }
    },
    {
      "id": "ppi_5ff25d051b6a59042093b7df",
      "object": "payment_plan_installment",
      "payment_plan": "pp_15296da1317452bc4ef3642e",
      "payment_plan_external_id": "whitening-5524",
      "customer": "cus_613663ea518955ea5d8f5358",
      "customer_external_id": "client-5524",
      "sequence": 2,
      "due_date": 1801440000,
      "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,
      "gateway_reference": null,
      "invoice": null,
      "hosted_invoice_url": null,
      "payments": [],
      "payment_plan_summary": {
        "installment_count": 2,
        "currency": "USD",
        "description": "Teeth whitening",
        "remaining_balance": 200,
        "installments_paid": 0,
        "installments_remaining": 2,
        "next_due_date": 1798761600,
        "status": "active"
      }
    }
  ],
  "meta": {
    "page": 1,
    "take": 10,
    "items_total": 3,
    "pages_total": 1
  }
}
```

Answers `200` with every installment of this plan in one page. Installment `0` is the down payment, `paid` by the terminal deposit, with its surcharge in `surcharge_amount` and `amount_charged`; installments `1` and `2` are `scheduled`, and ChaChing charges each on its `due_date` to the card the terminal saved.

## Next

Continue with step 4 of the [single-account path](/developer-guide/overview#single-account-path).