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?
1 Reply
ThunderJ
ThunderJ3w ago
I think this will require the subscription restore not upgrade (subscript again). I had a PR created that introduces this feature and waiting for test deploy and merge: https://github.com/better-auth/better-auth/pull/1705

Did you find this page helpful?