# End-to-end test walkthrough

One full pass: product, checkout, payment, refund, invoice, subscription.


This walkthrough runs the complete flow with `curl`. It works the same on macOS, Linux and Windows (CMD or PowerShell).

Set your key first:

```bash
export SB=sk_test_…            # macOS / Linux
set SB=sk_test_…               # Windows CMD
```

### 1. Create a product and a price

```bash
curl https://api.southbill.com/v1/products -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"name":"Test Plan","default_price":{"unit_amount":2500,"currency":"eur"}}'
```

### 2. Create a customer

```bash
curl https://api.southbill.com/v1/customers -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"email":"tester@example.com","name":"Test Buyer"}'
```

### 3. Create a checkout session and pay it

```bash
curl https://api.southbill.com/v1/checkout/sessions -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"amount":2500,"currency":"eur","customer_email":"tester@example.com",
       "success_url":"https://example.com/ok","cancel_url":"https://example.com/no"}'
```

Open the returned `url` in a browser and pay with `4242 4242 4242 4242`.

### 4. Check the payment

```bash
curl "https://api.southbill.com/v1/payments?limit=5" -H "Authorization: Bearer $SB"
```

### 5. Refund it

```bash
curl https://api.southbill.com/v1/refunds -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"payment_intent":"pi_…","amount":1000,"reason":"requested_by_customer"}'
```

### 6. Create an invoice with installments

```bash
curl https://api.southbill.com/v1/invoices -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"customer":"cus_…","currency":"eur","payment_mode":"partial",
       "items":[{"description":"Consulting","quantity":1,"unit_amount":120000}],
       "installments":[{"amount":60000,"due_date":"2026-10-01"},
                       {"amount":60000,"due_date":"2026-11-01"}]}'
```

Then `POST /v1/invoices/{id}/send`, inspect `GET /v1/invoices/{id}/installments`, and settle with `POST /v1/invoices/{id}/mark_paid`.

### 7. Create a subscription

```bash
curl https://api.southbill.com/v1/subscriptions -H "Authorization: Bearer $SB" \
  -H "Content-Type: application/json" \
  -d '{"customer":"cus_…","price":"price_…"}'
```

### 8. Read the event stream

```bash
curl "https://api.southbill.com/v1/events?limit=20" -H "Authorization: Bearer $SB"
```

Every object in these responses has `"livemode": false`. When the pass is green, swap `sk_test_` for `sk_live_` — nothing else changes.

