Skip to content

cancel subscription endpoint#1067

Merged
BilalG1 merged 6 commits intopayouts-tabfrom
payments-cancel-own-subscription
Jan 9, 2026
Merged

cancel subscription endpoint#1067
BilalG1 merged 6 commits intopayouts-tabfrom
payments-cancel-own-subscription

Conversation

@BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Dec 15, 2025

No description provided.

@cmux-agent
Copy link

cmux-agent bot commented Dec 15, 2025

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@vercel
Copy link

vercel bot commented Dec 15, 2025

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

Project Deployment Review Updated (UTC)
stack-backend Ready Ready Preview, Comment Jan 9, 2026 6:57pm
stack-dashboard Ready Ready Preview, Comment Jan 9, 2026 6:57pm
stack-demo Ready Ready Preview, Comment Jan 9, 2026 6:57pm
stack-docs Ready Ready Preview, Comment Jan 9, 2026 6:57pm
test-sandbox Building Building Preview, Comment Jan 9, 2026 6:57pm
test-sandbox-1767979426011-N9GJ Canceled Canceled Jan 9, 2026 6:57pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 15, 2025

Greptile Overview

Greptile Summary

Adds subscription cancellation functionality with a new DELETE endpoint that allows users to cancel their own subscriptions and team admins to cancel team subscriptions.

Key Changes:

  • New DELETE handler in route.ts with proper client/server authentication and permission checks
  • Client-side cancelSubscription() method with cache invalidation
  • Comprehensive test coverage for various cancellation scenarios including permission validation and one-time purchase rejection

Potential Issue:

  • The endpoint updates the database immediately after calling Stripe's cancel API, which may race with Stripe's webhook that also updates subscription status via syncStripeSubscriptions()

Confidence Score: 4/5

  • Safe to merge with one potential race condition that should be verified in testing
  • The implementation is solid with proper permission checks, validation logic, and comprehensive tests. However, there's a potential race condition between the manual database update and Stripe webhook sync that differs from existing patterns in the codebase. This should be tested to ensure it doesn't cause issues.
  • Pay attention to apps/backend/src/app/api/latest/payments/products/[customer_type]/[customer_id]/route.ts - verify the database update pattern after Stripe cancellation works correctly with webhooks

Important Files Changed

File Analysis

Filename Score Overview
apps/backend/src/app/api/latest/payments/products/[customer_type]/[customer_id]/route.ts 4/5 Added DELETE endpoint for subscription cancellation with proper permission checks and Stripe integration. Updates database immediately after Stripe cancellation which may cause race condition with webhooks.
apps/e2e/tests/backend/endpoints/api/v1/payments/products.test.ts 5/5 Added comprehensive test coverage for subscription cancellation including permission checks, one-time purchase rejection, and team admin scenarios.
apps/e2e/tests/js/payments.test.ts 5/5 Added end-to-end tests for client-side subscription cancellation for both user and team subscriptions.

Sequence Diagram

sequenceDiagram
    participant Client as Client App
    participant API as DELETE /payments/products
    participant Auth as Permission Check
    participant DB as Database
    participant Stripe as Stripe API
    participant Webhook as Stripe Webhook

    Client->>API: DELETE request with product_id
    API->>Auth: Verify client permissions
    alt User subscription
        Auth->>Auth: Check user owns subscription
    else Team subscription
        Auth->>DB: Check user has team_admin permission
    end
    
    API->>DB: Get owned products
    API->>API: Validate product type (not one_time)
    API->>DB: Find active/trialing subscription
    
    alt Stripe subscription exists
        API->>Stripe: stripe.subscriptions.cancel()
        Stripe-->>API: Cancellation confirmed
        Note over Stripe,Webhook: Stripe triggers webhook event
        Webhook->>DB: syncStripeSubscriptions() updates status
    end
    
    API->>DB: Update subscription status to canceled
    Note over API,DB: Potential race condition with webhook
    
    API-->>Client: Return success response
    Client->>Client: Invalidate product cache
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@BilalG1 BilalG1 requested a review from N2D4 December 18, 2025 02:40
@cmux-agent
Copy link

cmux-agent bot commented Jan 9, 2026

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Jan 9, 2026

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Jan 9, 2026

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Jan 9, 2026

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Jan 9, 2026

Preview Screenshots

Open Workspace (1 hr expiry) · Open Dev Browser (1 hr expiry) · Open Diff Heatmap

Screenshot capture was skipped.

No UI changes detected - screenshots skipped


Generated by cmux preview system

@BilalG1 BilalG1 merged commit 1bbb395 into payouts-tab Jan 9, 2026
21 checks passed
@BilalG1 BilalG1 deleted the payments-cancel-own-subscription branch January 9, 2026 19:02
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