{"record":{"id":"d0c55c34c358ae60","repo":"toeverything/AFFiNE","slug":"subscription-expired","errorCode":"subscription_expired","errorMessage":"Your subscription has expired.","messagePattern":"Your subscription has expired\\.","errorType":"exception","errorClass":"SubscriptionExpired","httpStatus":403,"severity":"error","filePath":"packages/backend/server/src/plugins/payment/service.ts","lineNumber":263,"sourceCode":"    idempotencyKey?: string\n  ) {\n    const target = subscriptionTarget(identity);\n    const subscription = await this.command<Subscription>({\n      action: 'mutate_subscription',\n      actorUserId: target.actor ?? target.id,\n      targetType: target.type,\n      targetId: target.id,\n      plan: identity.plan,\n      mutation,\n      intentId: idempotencyKey ?? randomUUID(),\n    });\n    return normalizeSubscription(subscription);\n  }\n\n  private async command<T = unknown>(input: Record<string, unknown>) {\n    try {\n      return await this.runtime.executePaymentCommandV1<T>(input);\n    } catch (error) {\n      throw mapPaymentError(error, input);\n    }\n  }\n}\n\nfunction checkoutTarget(\n  plan: SubscriptionPlan,\n  args: z.infer<typeof CheckoutExtraArgs>\n) {\n  if (plan === SubscriptionPlan.SelfHostedTeam)\n    return { type: 'instance', id: undefined };\n  if (plan === SubscriptionPlan.Team) {\n    if (!args.workspaceId) throw new InvalidCheckoutParameters();\n    return { type: 'workspace', id: args.workspaceId };\n  }\n  if (!args.user) throw new InvalidCheckoutParameters();\n  return { type: 'user', id: args.user.id };\n}","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/d897bb3d84099e54a6b3c0bd5f4265f8aa87d190/packages/backend/server/src/plugins/payment/service.ts#L245-L281","documentation":"Thrown by resumeSubscription when subscription.end is in the past. A canceled subscription can only be resumed before its scheduled end date; once end has passed, the subscription is terminated and the user must start a new checkout instead.","triggerScenarios":"User returns after the billing period ended and clicks Resume on a stale canceled row; clock/timezone bug in the client showing Resume past the deadline; delayed webhook left the row visible after expiration.","commonSituations":"Billing page left open across the period boundary; 'cancel at period end' with the user coming back weeks later; server clock skew in self-hosted deployments.","solutions":["Compare subscription.end with the current time client-side and swap Resume for a checkout/re-subscribe CTA once passed.","Hide expired canceled rows from the resume list; surface them as expired entitlements only.","On catching this code, route the user directly to the checkout flow for the same plan."],"exampleFix":"// before\nif (sub.canceledAt) await svc.resumeSubscription(identity);\n\n// after\nif (sub.canceledAt && sub.end && sub.end > new Date()) {\n  await svc.resumeSubscription(identity);\n} else {\n  router.push(`/checkout?plan=${identity.plan}`);\n}","handlingStrategy":"validation","validationCode":"const now = Date.now();\nconst withinWindow = subscription.end ? new Date(subscription.end).getTime() > now : false;\nif (!withinWindow) throw new Error('Resume window closed; start a new checkout');\nawait svc.resumeSubscription(identity, idempotencyKey);","typeGuard":"function isInResumeWindow(s: { end: Date | string | null }): boolean {\n  return s.end !== null && new Date(s.end).getTime() > Date.now();\n}","tryCatchPattern":"catch (e) { if (gqlErrorCode(e) === 'subscription_expired') { routeToCheckout(identity.plan); notify('Offer expired, please re-subscribe.'); return; } throw e; }","preventionTips":["Compare subscription.end with server time or a synced clock client-side before enabling Resume.","Hide expired canceled rows; show a re-subscribe CTA instead.","On catching subscription_expired, never retry resume; route to checkout."],"tags":["payment","subscription","resume","expiry","state-machine"],"backgroundTag":"expired-subscription","analyzedSha":"d897bb3d84099e54a6b3c0bd5f4265f8aa87d190","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}