MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getSubscriptionState

Function getSubscriptionState

packages/payments/src/subscription-state.ts:28–65  ·  view source on GitHub ↗
(
  org: SubscriptionStateInput
)

Source from the content-addressed store, hash-verified

26}
27
28export function getSubscriptionState(
29 org: SubscriptionStateInput
30): SubscriptionState {
31 if (process.env.SELF_HOSTED === 'true') {
32 return 'self_hosted';
33 }
34
35 const now = new Date();
36 const { subscriptionStatus, subscriptionCanceledAt, subscriptionEndsAt } = org;
37 const endsInFuture = Boolean(subscriptionEndsAt && subscriptionEndsAt > now);
38
39 switch (subscriptionStatus) {
40 case null:
41 case 'trialing':
42 return endsInFuture ? 'trialing' : 'trial_expired';
43 case 'active':
44 // Cancel-at-period-end keeps the Polar status as `active` while
45 // `canceledAt` is set; the subscription stays usable until it expires.
46 if (subscriptionCanceledAt) {
47 return 'canceling';
48 }
49 return subscriptionEndsAt && subscriptionEndsAt <= now
50 ? 'expired'
51 : 'active';
52 case 'past_due':
53 return 'past_due';
54 case 'unpaid':
55 return 'unpaid';
56 case 'incomplete':
57 return 'incomplete';
58 case 'incomplete_expired':
59 return 'expired';
60 case 'canceled':
61 return 'canceled';
62 default:
63 return 'expired';
64 }
65}
66
67/**
68 * Whether a given state should block access to the dashboard (and force the

Callers 3

computeFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected