armand
armand
BABetter Auth
Created by armand on 4/5/2025 in #bug-reports
Stripe plugin: seems we can't reactivate a canceled subscription
Hello, The title is self-explanatory, once a subscription is canceled, it seems there's no way to return to the portal to reactivate it before it truly gets canceled. Steps to reproduce: 1. Call authClient.subscription.cancel 2. Then, try to call authClient.subscription.upgrade (only other method available) 3. You get: You're already subscribed to this plan After a quick digging in source code, I found the issue in the upgradeSubscription endpoint (packages/stripe/src/index.ts). The code doesn't check cancelAtPeriodEnd when validating subscription status:
if (
existingSubscription &&
existingSubscription.status === "active" &&
existingSubscription.plan === ctx.body.plan
) {
throw new APIError("BAD_REQUEST", {
message: STRIPE_ERROR_CODES.ALREADY_SUBSCRIBED_PLAN,
});
}
if (
existingSubscription &&
existingSubscription.status === "active" &&
existingSubscription.plan === ctx.body.plan
) {
throw new APIError("BAD_REQUEST", {
message: STRIPE_ERROR_CODES.ALREADY_SUBSCRIBED_PLAN,
});
}
A potential fix would be to add cancelAtPeriodEnd check to allow reactivation of canceled subscriptions:
if (
existingSubscription &&
existingSubscription.status === "active" &&
existingSubscription.plan === ctx.body.plan &&
!existingSubscription.cancelAtPeriodEnd // This would solve the issue
) {
throw new APIError("BAD_REQUEST", {
message: STRIPE_ERROR_CODES.ALREADY_SUBSCRIBED_PLAN,
});
}
if (
existingSubscription &&
existingSubscription.status === "active" &&
existingSubscription.plan === ctx.body.plan &&
!existingSubscription.cancelAtPeriodEnd // This would solve the issue
) {
throw new APIError("BAD_REQUEST", {
message: STRIPE_ERROR_CODES.ALREADY_SUBSCRIBED_PLAN,
});
}
Am I missing something, or is it really a bug I ran into?
2 replies