Skip to content

Commit c7a8e6f

Browse files
authored
Merge pull request #43 from 398ja/codex/document-request-parameters-and-methods
Add webhook and client reference docs
2 parents 79d16d1 + cf89fa7 commit c7a8e6f

5 files changed

Lines changed: 88 additions & 1 deletion

File tree

docs/reference/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Reference
2+
3+
- [REST API](rest-api.md)
4+
- [Configuration](configuration.md)
5+
- [Webhook Handler](webhook.md)
6+
- [Java Client](client.md)

docs/reference/client.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Java Client
2+
3+
The `cashu-gateway-client` module offers REST clients for interacting with the service.
4+
5+
## Common Methods
6+
7+
Available on all client classes.
8+
9+
| Method | Inputs | Response |
10+
|--------|--------|----------|
11+
| `get(Long id)` | Numeric identifier | Returns the entity with the given id or `null`. |
12+
| `getByEntityId(String entityId)` | External id (`paymentId` or `quoteId`) | Returns the matching entity or `null`. |
13+
| `create(T entity)` | Entity instance | Persists the entity and returns the created object. |
14+
| `delete(Long id)` | Numeric identifier | Deletes the entity, response is empty. |
15+
16+
## PaymentClient
17+
18+
| Method | Inputs | Response | Description |
19+
|--------|--------|----------|-------------|
20+
| `getByQuoteId(String quoteId)` | Quote id | `GatewayPayment` linked to the quote. |
21+
| `updatePayment(GatewayPayment payment)` | Updated payment | `GatewayPayment` after update. |
22+
23+
## QuoteClient
24+
25+
| Method | Inputs | Response | Description |
26+
|--------|--------|----------|-------------|
27+
| `getByInvoiceId(String invoiceId)` | Lightning invoice id | Matching `GatewayQuote`. |

docs/reference/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ This document lists configuration properties and environment variables available
5959

6060
| Property | Default | Description |
6161
| --- | --- | --- |
62-
| `A1b2C3d4.wid` | `phoenixd` | Webhook identifier expected by validator. |
62+
| `A1b2C3d4.wid` | `phoenixd` | Webhook identifier expected by validator. |

docs/reference/rest-api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# REST API
2+
3+
The REST service exposes endpoints for managing quotes and payments. Base URL defaults to `http://localhost:8080`.
4+
5+
## Quote Endpoints
6+
7+
- `GET /quote` – list quotes
8+
- `POST /quote` – create a quote
9+
- `GET /quote/{id}` – fetch a quote by numeric id
10+
- `GET /quote/search/findByQuoteId?quoteId=...` – fetch by external quote id
11+
- `GET /quote/search/findByInvoiceId?invoiceId=...` – fetch by Lightning invoice id
12+
13+
## Payment Endpoints
14+
15+
- `GET /payment` – list payments
16+
- `POST /payment` – create a payment
17+
- `GET /payment/{id}` – fetch a payment by numeric id
18+
- `GET /payment/search/findByPaymentId?paymentId=...`
19+
- `GET /payment/search/findByQuoteId?quoteId=...`

docs/reference/webhook.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Webhook Handler
2+
3+
`cashu-gateway-webhook` exposes a servlet at `/webhook` for processing payment notifications.
4+
5+
## Request Parameters
6+
7+
| Name | Required | Description |
8+
|------|----------|-------------|
9+
| `wid` | Yes | Identifies the webhook source (`phoenixd` or `dummy`). If absent in the request, the system property `wid` is used. |
10+
| `type` | Yes (phoenixd) | Expected value `payment_received`. |
11+
| `amountSat` | Yes (phoenixd) | Payment amount in satoshis. |
12+
| `paymentHash` | Yes (phoenixd) | Lightning payment hash. |
13+
| `externalId` | Yes (phoenixd) | Lightning invoice identifier used to look up the quote. |
14+
15+
The webhook expects parameters in an `application/x-www-form-urlencoded` payload.
16+
17+
### Example
18+
19+
```
20+
POST /webhook
21+
wid=phoenixd&type=payment_received&amountSat=1000&paymentHash=<hash>&externalId=<invoice>
22+
```
23+
24+
## Validation Rules
25+
26+
Requests with `wid=phoenixd` are validated as follows:
27+
28+
1. Retrieve the quote by `externalId` and ensure it exists and has direction `RECEIVE`.
29+
2. Load the payment linked to the quote.
30+
3. Confirm `paymentHash` and `amountSat` match the stored payment.
31+
4. Verify the payment state is `PAID` and the webhook `type` is `payment_received`.
32+
33+
If validation succeeds, the payment is marked `CONFIRMED` and a `201 Created` response is returned. Any failure results in `401 Unauthorized`.
34+
35+
The `dummy` webhook id is provided for testing and creates a placeholder payment without validation.

0 commit comments

Comments
 (0)