feat(billing): persist cancellation feedback and email the customer#1729
Open
giladresisi wants to merge 3 commits into
Open
feat(billing): persist cancellation feedback and email the customer#1729giladresisi wants to merge 3 commits into
giladresisi wants to merge 3 commits into
Conversation
POST /billing/cancel used to fire an internal email to EMAIL_FROM_ADDRESS before even calling Stripe — flooding the team inbox (it fired on reactivations and on Stripe failures too), throwing the customer's feedback away after the email, and giving the customer no confirmation at all. Now the controller calls setToCancel first and only acts on a real cancellation (cancel_at set): the feedback is persisted in a new SubscriptionCancellationFeedback table so it stays queryable/traceable (history survives cancel/reactivate cycles), and the customer gets a confirmation email with the access-end date and a link to the billing page. Reactivation saves and sends nothing. The internal email is removed; realtime internal notification will be handled by a separate mechanism. - Purely additive schema change (new model + back-relations); db push clean - New BillingCancelDto: @IsString() with empty string allowed — the frontend reactivate path posts feedback: '' - Email failure cannot fail the request; response shape { id, cancel_at } unchanged, no frontend changes Testing: prisma-generate / prisma-db-push / build:backend all pass. Synthetic e2e against the local stack (fresh Stripe test-mode customer+subscription, self-cleaning): missing feedback rejected with 400 and no row; cancel saves the row and emits exactly one Temporal send_email signal addressed to the customer (none to EMAIL_FROM_ADDRESS), body verified; reactivate returns cancel_at undefined with no new row/email and the Stripe subscription restored. Cancel/reactivate also verified manually through the billing UI with a test-card subscription. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Contribution-checker quality warning Heuristics that flagged:
If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Comment on lines
+123
to
+128
| if (result.cancel_at) { | ||
| await this._subscriptionService.saveCancellationFeedback( | ||
| org.id, | ||
| user.id, | ||
| body.feedback | ||
| ); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment.
Fixed in followup commit
Addresses the review comment on #1729: by the time we save the feedback the Stripe cancellation has already succeeded, so a transient DB error would return a 500 while the subscription is in fact cancelled, leaving the UI inconsistent. Log the failure and still return { id, cancel_at }, matching how the confirmation email is already guarded. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Motivation
POST /billing/cancelsent an internal email toEMAIL_FROM_ADDRESSbefore even calling Stripe. That meant:Changes
setToCancelfirst and only acts on a real cancellation (cancel_atset). Reactivation saves and sends nothing.SubscriptionCancellationFeedbacktable (purely additive schema change: new model + back-relations) persists the feedback per cancellation event, so history survives cancel/reactivate cycles.BillingCancelDto(@IsString(),@IsDefined()): the previously unvalidated inline body now rejects a missingfeedback, while the empty string stays valid because the frontend reactivate path postsfeedback: ''.{ id, cancel_at }response shape is unchanged and no frontend changes are needed. The chatbase-refund email in the same controller is untouched.Deployment
Requires a DB schema update (
pnpm run prisma-db-push) before or with the deploy — this repo usesprisma db push, so there is no migration file. The change is purely additive (one new tableSubscriptionCancellationFeedback+ back-relations onOrganization/User): no existing tables/columns are altered, no data backfill needed, and old backend code keeps working against the pushed schema, so the usual schema-push-first deploy order is safe.Testing
pnpm run prisma-generate,pnpm run prisma-db-push(clean, no drop warnings), andpnpm run build:backendall pass.feedback→ 400, no row saved{ id, cancel_at }returned, feedback row saved with correct org/user, exactly one Temporalsend_emailsignal addressed to the customer (payload inspected: subject, date, billing link) and none toEMAIL_FROM_ADDRESSfeedback: ''→cancel_atundefined, no new row, no email, Stripe subscription restored to active/non-cancelling🤖 Generated with Claude Code