[PR #5487] [CLOSED] Add cancel_at field to subscription table #31633

Closed
opened 2026-04-17 22:31:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5487
Author: @GautamBytes
Created: 10/22/2025
Status: Closed

Base: canaryHead: feat/stripe-add-cancel-at


📝 Commits (2)

  • de45862 add cancel_at to subscription table
  • 1b71302 Merge branch 'canary' into feat/stripe-add-cancel-at

📊 Changes

6 files changed (+106 additions, -0 deletions)

View changed files

📝 docs/content/docs/plugins/stripe.mdx (+6 -0)
📝 packages/stripe/src/hooks.ts (+3 -0)
📝 packages/stripe/src/index.ts (+1 -0)
📝 packages/stripe/src/schema.ts (+4 -0)
📝 packages/stripe/src/stripe.test.ts (+87 -0)
📝 packages/stripe/src/types.ts (+5 -0)

📄 Description

Fixes #5388 #5535

What this PR does

This PR resolves an issue where the customer.subscription.updated webhook handler was not saving the cancel_at timestamp, causing the local database to be out of sync with Stripe.

This is particularly important for subscriptions canceled via the billing portal that have a specific cancellation time (cancel_at) rather than just at the period end (cancel_at_period_end).

Changes

  • Schema: Added a cancelAt (type: date, optional) field to the subscription schema in packages/stripe/src/schema.ts.
  • Types: Updated the Subscription interface in packages/stripe/src/types.ts with the new cancelAt?: Date property.
  • Logic (Webhook): Modified onSubscriptionUpdated in packages/stripe/src/hooks.ts to read subscriptionUpdated.cancel_at and save it to the database.
  • Logic (Restore): Updated restoreSubscription in packages/stripe/src/index.ts to set cancelAt: null for data integrity when a subscription is restored.
  • Docs: Added the new cancelAt field to the subscription schema documentation in docs/content/docs/plugins/stripe.mdx.
  • Tests:
    • Added a new test to packages/stripe/src/stripe.test.ts to simulate a customer.subscription.updated event with cancel_at and assert it's saved correctly.
    • Updated an existing test snapshot to include the new cancelAt field in its default state.

Summary by cubic

Add cancelAt to subscriptions and persist Stripe’s cancel_at in the webhook so scheduled cancellations are saved correctly. Prevents database drift when cancellations are set via the billing portal.

  • Bug Fixes
    • Schema/types: added cancelAt?: Date to subscription.
    • Webhook: read cancel_at and save as Date.
    • Restore: set cancelAt to null on subscription restore.
    • Docs: documented cancelAt in the subscription schema.
    • Tests: added coverage for customer.subscription.updated with cancel_at; updated snapshot.

Written for commit 1b71302. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5487 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 10/22/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/stripe-add-cancel-at` --- ### 📝 Commits (2) - [`de45862`](https://github.com/better-auth/better-auth/commit/de458622794ac4fe6e0d75c87cb3b66fb470ebb7) add cancel_at to subscription table - [`1b71302`](https://github.com/better-auth/better-auth/commit/1b713021808637c15be193a0109a1b6cd01c4696) Merge branch 'canary' into feat/stripe-add-cancel-at ### 📊 Changes **6 files changed** (+106 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/stripe.mdx` (+6 -0) 📝 `packages/stripe/src/hooks.ts` (+3 -0) 📝 `packages/stripe/src/index.ts` (+1 -0) 📝 `packages/stripe/src/schema.ts` (+4 -0) 📝 `packages/stripe/src/stripe.test.ts` (+87 -0) 📝 `packages/stripe/src/types.ts` (+5 -0) </details> ### 📄 Description Fixes #5388 #5535 ## What this PR does This PR resolves an issue where the `customer.subscription.updated` webhook handler was not saving the `cancel_at` timestamp, causing the local database to be out of sync with Stripe. This is particularly important for subscriptions canceled via the billing portal that have a specific cancellation time (`cancel_at`) rather than just at the period end (`cancel_at_period_end`). ## Changes - **Schema:** Added a `cancelAt` (type: `date`, optional) field to the `subscription` schema in `packages/stripe/src/schema.ts`. - **Types:** Updated the `Subscription` interface in `packages/stripe/src/types.ts` with the new `cancelAt?: Date` property. - **Logic (Webhook):** Modified `onSubscriptionUpdated` in `packages/stripe/src/hooks.ts` to read `subscriptionUpdated.cancel_at` and save it to the database. - **Logic (Restore):** Updated `restoreSubscription` in `packages/stripe/src/index.ts` to set `cancelAt: null` for data integrity when a subscription is restored. - **Docs:** Added the new `cancelAt` field to the `subscription` schema documentation in `docs/content/docs/plugins/stripe.mdx`. - **Tests:** - Added a new test to `packages/stripe/src/stripe.test.ts` to simulate a `customer.subscription.updated` event with `cancel_at` and assert it's saved correctly. - Updated an existing test snapshot to include the new `cancelAt` field in its default state. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add cancelAt to subscriptions and persist Stripe’s cancel_at in the webhook so scheduled cancellations are saved correctly. Prevents database drift when cancellations are set via the billing portal. - **Bug Fixes** - Schema/types: added cancelAt?: Date to subscription. - Webhook: read cancel_at and save as Date. - Restore: set cancelAt to null on subscription restore. - Docs: documented cancelAt in the subscription schema. - Tests: added coverage for customer.subscription.updated with cancel_at; updated snapshot. <sup>Written for commit 1b71302. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:31:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#31633