Skip to content

docs(webhooks): Document the coupon webhooks - #651

Merged
groyoh merged 1 commit into
mainfrom
docs/coupon-webhooks
Oct 19, 2026
Merged

groyoh merged 1 commit into
mainfrom
docs/coupon-webhooks

Conversation

@groyoh

@groyoh groyoh commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Context

lago-api sends coupon.created, coupon.updated, coupon.deleted and coupon.terminated webhooks once getlago/lago-api#6306 is merged. The payload is the coupon object, the same one the coupon endpoints return. These webhooks are not documented yet.

Description

The four webhooks are documented with CouponObject as payload, following the billable metric and plan webhooks. coupon.terminated is sent when a coupon is terminated, by hand or because its expiration date has passed.

This PR should be merged after getlago/lago-api#6306.

## Context

lago-api sends `coupon.created`, `coupon.updated`, `coupon.deleted` and `coupon.terminated` webhooks (getlago/lago-api#6306), with the coupon object as payload. They were not documented.

## Description

The four webhooks are documented with `CouponObject` as payload, like the billable metric and plan webhooks.
@groyoh
groyoh merged commit 8b66e92 into main Oct 19, 2026
3 checks passed
@groyoh
groyoh deleted the docs/coupon-webhooks branch October 19, 2026 09:14
groyoh pushed a commit that referenced this pull request Oct 19, 2026
…yment definitions (#661)

## Context

OpenAPI guardian check of `payments` (incremental run), compared with lago-api at `2d7c3c1` and the SDK clients.

## Description

- `POST /payments` documents `403` and `404`. Recording a manual payment is refused with a forbidden error when the organization is not on a premium plan or when the invoice does not accept a manual payment, and with a not found error when the invoice does not exist.

  <details>
  <summary>Code references (lago-api at <code>2d7c3c1</code>)</summary>

  - Service: [`Payments::ManualCreateService#check_preconditions`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/services/payments/manual_create_service.rb#L74-L84) answers not found for an unknown invoice and forbidden in the two cases above.
  - Controller: [`Api::V1::PaymentsController#create`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/controllers/api/v1/payments_controller.rb#L8-L21) renders the error from that service.

  </details>

- `GET /payments` and `GET /customers/{external_customer_id}/payments` document `422`. An `invoice_id` that is not a valid identifier is rejected before the query runs.

  <details>
  <summary>Code references (lago-api at <code>2d7c3c1</code>)</summary>

  - Contract: [`Queries::PaymentsQueryFiltersContract`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/contracts/queries/payments_query_filters_contract.rb#L5-L8) requires `invoice_id` to match the identifier format.
  - Query: [`PaymentsQuery#call`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/queries/payments_query.rb#L7-L8) returns early when the filters do not validate, and [`BaseQuery#validate_filters`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/queries/base_query.rb#L63-L72) turns that into a validation failure.
  - Concern: [`PaymentIndex#payment_index`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/controllers/concerns/payment_index.rb#L7-L35) renders that error, and both list endpoints go through it.

  </details>

- `PaymentCreateInput.payment.invoice_id` now uses `format: uuid` and says which invoice it points at. Lago looks the invoice up by its identifier inside the organization.

  <details>
  <summary>Code references (lago-api at <code>2d7c3c1</code>)</summary>

  - Controller: [`Api::V1::PaymentsController#create_params`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/controllers/api/v1/payments_controller.rb#L38-L45) permits `invoice_id`.
  - Service: [`Payments::ManualCreateService#invoice`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/services/payments/manual_create_service.rb#L70-L72) looks it up by the invoice identifier.
  - Schema: [`db/structure.sql`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/db/structure.sql#L3958-L3959) declares `invoices.id` as a UUID.

  </details>

- `PaymentObject.status` now says that the value is always `succeeded` for a manual payment, which was not obvious from a description that only talked about payment providers.

  <details>
  <summary>Code references (lago-api at <code>2d7c3c1</code>)</summary>

  - Service: [`Payments::ManualCreateService#call`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/services/payments/manual_create_service.rb#L24-L35) creates the payment with the status `succeeded`.
  - Serializer: [`V1::PaymentSerializer#serialize`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/serializers/v1/payment_serializer.rb#L15-L19) sends that column as `status`.

  </details>

- Wording: `PaymentObject.payment_status` reads as a sentence now, `PaymentObject.external_customer_id` was missing its final period, and the `reference` and `paid_at` descriptions of `PaymentCreateInput` say what the field holds and what happens when it is left out.

  <details>
  <summary>Code references (lago-api at <code>2d7c3c1</code>)</summary>

  - Service: [`Payments::ManualCreateService#parsed_paid_at`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/services/payments/manual_create_service.rb#L64-L68) leaves the creation timestamp to the current time when `paid_at` is blank.
  - Model: [`Payment`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/models/payment.rb#L30-L31) requires `reference` on a manual payment and refuses it on the other kinds.

  </details>

### SDK drift (spec is right, needs an `sdk-clients-update` run)
| Client | Divergence |
|---|---|
| Go | [`Payment`](https://github.com/getlago/lago-go-client/blob/a3ce9d82ff8c76658f205782da161d70d9228673/payment.go#L40-L53) has no field for `lago_customer_id`, `lago_payable_id`, `payable_type`, `status`, `payment_provider_code`, `payment_provider_type`, `provider_payment_id` or `provider_customer_id`, all of which [`V1::PaymentSerializer#serialize`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/serializers/v1/payment_serializer.rb#L6-L30) sends. |
| Python | [`PaymentResponse`](https://github.com/getlago/lago-python-client/blob/c3dee54252c75256ece3fbeea63d44e5d880347b/lago_python_client/models/payment.py#L13-L24) has the same gaps and also drops `external_customer_id` and `next_action`. |

### Needs human confirmation (not changed)
- `PaymentObject.payment_status` is documented as always present with one of four values. In lago-api the column [`payments.payable_payment_status`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/db/structure.sql#L4564) allows `null` and [`Payment`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/models/payment.rb#L36) declares the enum with `allow_nil`, but no creation path that leaves it empty was found, and every payment flow reads the value right after setting it. Making the field nullable would be breaking, so nothing was changed. Can a payment be stored without that status?

<details>
<summary>Agent notes</summary>

Run: incremental since 2026-10-11, queue reason for this resource: api. Compatibility checker: WARN (advisory); nothing is breaking. Four warnings are the newly documented `403`, `404` and `422` statuses, which lago-api already answers, so only their description is new. The fifth is the `format: uuid` added to `invoice_id` in the create body, an annotation on a value that already has to be a Lago invoice identifier.

The security fix that made `V1::PaymentSerializer` tolerate a deleted invoice or payment request was checked against the contract and needs no spec change: the customer keys stay always present because [`payments.customer_id`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/db/structure.sql#L4570) is `NOT NULL`, and `invoice_ids` and `invoice_numbers` can now come back empty, which the spec already allows since both are plain arrays. The list filters were read side by side with `PaymentsQuery`: the query also supports a currency filter and a search term, which neither list endpoint passes, so the spec is right not to document them.

**Deliberately not documented**
- The `x402` value of `PaymentObject.type` and the x402 settlement object on a payment, unreleased: `x402_payments`.

**Docs-guardian leads**
- The most recent documentation sweep reports no suspected spec issues. The sweep before it asked whether `BillableMetricObject.aggregation_type` is missing `custom_agg`. It is not: [`BillableMetric::AGGREGATION_TYPES`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/app/models/billable_metric.rb#L30-L39) marks the value as a deprecated type kept for legacy metrics that must not be documented in the public API, so the spec stays as it is. The lead is closed, not deferred.

**Report-only findings from this run**
- `webhooks` is clean and needs no pull request. The registry, the `required` lists and the four keys every webhook payload carries were checked across every file in `src/webhooks/` and agree with lago-api. One question came out of it: the documentation site lists `add_on.created`, `add_on.updated`, `add_on.deleted`, `coupon.created`, `coupon.updated`, `coupon.deleted` and `coupon.terminated`, which have no entry in [`config/webhook_event_types.yml`](https://github.com/getlago/lago-api/blob/2d7c3c11e8759ba0411d4a5f279ac7dbd9d8495b/config/webhook_event_types.yml) and no service under `app/services/webhooks/`, so an endpoint cannot subscribe to them today. Pull requests #651 and #652 add exactly those files to the specification and were left untouched by this run. Will lago-api add the matching registry entries and services?

**Queue**
- `customers` (spec+api), `api_logs` (spec+api), `features` (spec), `payment_requests` (spec), `invoices` (api), `payments` (api), `wallets` (api), `organizations` (api), `webhooks` (api). Every one was checked. `activity_logs` was skipped because it already has an open guardian pull request.

**Deferred to next run**
- Nothing. Every resource in the queue was checked.

Run started: 2026-10-19T07:51:37Z.

### Process feedback for the retro
- The two settled rulings for this resource, the short provider enum on `payment_provider_type` and `format: date` on `paid_at`, were both still correct and cost nothing to skip. The settled list works well when it names the exact field.
- Two resources this run were queued on an lago-api change that never reached a serializer, a permitted parameter list or a route, so neither could produce a spec change. Filtering the queue on that condition would free checking capacity.
- The three standard webhook checks are fully mechanical. They would be cheaper and more reliable as a script committed to this repository than as a task repeated by hand each sweep.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants