Repository navigation
feat(coupons): Add lifecycle webhooks - #6306
Merged
groyoh merged 5 commits intoOct 19, 2026
Merged
Conversation
Welcome, @avanish-garg!Thanks for your first contribution! Before we proceed with the review, please sign the Fiduciary License Agreement: Once signed, this PR will be automatically updated. |
Thanks, @avanish-garg! 🎉Your CLA has been signed and is now on file. We'll proceed with the review shortly. |
groyoh
reviewed
Oct 15, 2026
groyoh
left a comment
Contributor
There was a problem hiding this comment.
Some points may block the merge: the
- The branch is based on a
mainfrom early September and needs a rebase.spec/models/webhook_endpoint_spec.rbwas added onmainsince then and fails with this change (see the inline comment). - A coupon also changes state when it is terminated, through the
terminateCouponGraphQL mutation or the dailyClock::TerminateCouponsJobfor expired coupons (Coupons::TerminateService). The payload exposesterminated_at, yet no webhook is sent for that change, so a consumer that mirrors coupons from these webhooks keeps them active. Sendingcoupon.updatedfromCoupons::TerminateService(both#calland.terminate_all_expired) would cover it. - The new webhooks are not documented in getlago/lago-openapi (
src/webhooks/hasbillable_metric_created.yamlbut nothing for coupons). A matching PR there would let SDK users and the docs see the payload.
groyoh
force-pushed
the
feature/coupon-lifecycle-webhooks
branch
from
October 15, 2026 17:03
2bfcc07 to
510adf3
Compare
Contributor
|
The branch was rebased on |
This was referenced Oct 15, 2026
groyoh
approved these changes
Oct 19, 2026
coupon.created/updated/deleted webhook event names already existed
(added for activity logs), but nothing ever fired them -- sibling
catalog resources Plan/BillableMetric/Feature all fire webhooks on
create/update/destroy, Coupon didn't.
Adds Webhooks::Coupons::{Created,Updated,Deleted}Service mirroring
the existing BillableMetrics webhook services, registers them in
SendWebhookJob::WEBHOOK_SERVICES, and wires the SendWebhookJob calls
into Coupons::{Create,Update,Destroy}Service.
## Context Webhook endpoints can only subscribe to the event types declared in `config/webhook_event_types.yml`. The `coupon.*` webhooks were added to `SendWebhookJob::WEBHOOK_SERVICES` without being declared there, so an endpoint that selects its events could not subscribe to them, and the webhook form did not list them. `spec/models/webhook_endpoint_spec.rb` also requires every handler type to be declared. ## Description `coupon.created`, `coupon.updated` and `coupon.deleted` are declared under a new `Coupons` category. The GraphQL schema was dumped again, since `EventTypeEnum` and `EventCategoryEnum` are built from this file.
## Context A coupon is terminated by the `terminateCoupon` GraphQL mutation, or by `Clock::TerminateCouponsJob` once its `expiration_at` has passed. The coupon webhook payload exposes `status` through `terminated_at`, but no webhook was sent on termination, so a consumer that mirrors coupons from the webhooks kept them active. ## Description `Coupons::TerminateService` now sends `coupon.updated` when it terminates a coupon, both for a single coupon and for the expired ones. Nothing is sent when the coupon was already terminated.
## Context Termination is a distinct step in a coupon's life, like `subscription.terminated` for subscriptions. Sending it as `coupon.updated` made it hard to tell apart from an edit. The expired coupons were also terminated by a loop that repeated the body of `Coupons::TerminateService#call`. ## Description `Coupons::TerminateService` now sends a new `coupon.terminated` webhook, declared in `config/webhook_event_types.yml`, in place of `coupon.updated`. `terminate_all_expired` calls the service for each expired coupon, so both paths terminate and notify the same way.
## Context The coupon webhook specs only checked a few keys of the payload, mostly by type, through the `creates webhook` shared example, which ignores the keys it is not given. A field missing from the payload, renamed or with a wrong value was not caught. ## Description Each spec now builds a percentage coupon with a recurring frequency, a time limit and a plan and a billable metric as targets, so most fields hold a real value, and compares the whole payload with `eq`. The terminated spec also checks `terminated_at`.
groyoh
force-pushed
the
feature/coupon-lifecycle-webhooks
branch
from
October 19, 2026 09:01
377561b to
b5230a9
Compare
groyoh
added a commit
to getlago/lago-openapi
that referenced
this pull request
Oct 19, 2026
## 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.
Contributor
|
Thanks for you contribution @avanish-garg ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Creating, updating or deleting a coupon sent no webhook, unlike plans, billable metrics and features. Terminating a coupon, by hand or when its expiration date passes, was not announced either, so a system that mirrors coupons from the webhooks could not keep them in sync.
Description
Four webhooks are added, with the coupon object as payload (the same object the coupon endpoints return):
coupon.created,coupon.updatedandcoupon.deleted, sent by the create, update and destroy services.coupon.terminated, sent byCoupons::TerminateServicewhen it terminates a coupon. This covers theterminateCouponmutation and the hourly job for expired coupons, which now calls the same service for each coupon. Nothing is sent when the coupon was already terminated.The types are declared in
config/webhook_event_types.ymlunder a newCouponscategory, so a webhook endpoint can subscribe to them and the webhook form lists them. The GraphQL schema was regenerated, since its event type and category enums are built from that file. Endpoints that listen to all events receive the new webhooks without any change.The webhook specs compare the whole payload, so a missing or renamed field is caught.
Fixes #6307