Skip to content

fix(billing): avoid grace period on abandoned checkout expiry - #13

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-b1fc
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-b1fc

Conversation

@cursor

@cursor cursor Bot commented Sep 23, 2026

Copy link
Copy Markdown

Bug and impact

When a user starts a Plus checkout (checkout_pending) but abandons the QRIS session, Xendit sends payment_session.expired. The webhook mapped this to renewal_failed, and applyVerifiedPaymentEvent unconditionally moved the workspace into grace_period with downgraded entitlements — even though the user never paid.

Impact: Incorrect billing state (plus/grace_period vs free/free), spurious entitlement downgrades, and divergence from the subscription state machine in platform-policy.ts.

Root cause

applyVerifiedPaymentEvent treated every renewal_failed lifecycle the same, without checking whether the workspace was in checkout_pending vs active_plus.

Fix

  • Read current subscription state inside the payment transaction.
  • checkout_pending + expired → revert to free (no grace period).
  • active_plus + renewal failure → enter grace_period (unchanged intent).
  • Other states → record the payment event but skip entitlement churn.

Validation

  • Added unit tests in packages/db/src/platform.test.ts for abandoned checkout and active renewal failure paths.
  • Added webhook forwarding test in apps/api/src/xendit-webhook.test.ts.
  • pnpm exec vitest run packages/db/src/platform.test.ts apps/api/src/xendit-webhook.test.ts — 16/16 passed.
Open in Web View Automation 

When Xendit sends payment_session.expired for a checkout that was never
paid, applyVerifiedPaymentEvent now reverts checkout_pending workspaces
back to free instead of entering grace_period. Grace period is reserved
for active_plus renewal failures only.

Co-authored-by: drferdiiskandar <drferdiiskandar@sentrahai.com>
@vercel

vercel Bot commented Sep 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentrabot-site Skipped Skipped Sep 23, 2026 11:07am UTC

This branch was previously deployed

1 inactive deployment
Preview — 87a8ce54 Deployed Sep 23, 2026 by vercel[bot]
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.

1 participant