Skip to content

Commit 7895f49

Browse files
committed
Subscription expiry - add 5 mins grace
To give the payment provider time to try and renew the subscription before we try and refresh it.
1 parent 7bd585f commit 7895f49

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

firebase/functions/src/subscriptions/subscriptions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export type ChargebeeSubscriptionAPIClient = (subscriptionQuery: SusbcriptionQue
99

1010
export type CustomClaimsSetter = (userId: string, claims: Claims) => any;
1111

12+
// The grace period we add to Chargebee expiry dates, before marking as expired to us.
13+
// to give them time to refresh the user's subscription / payment status.
14+
const expiryGraceSecs = 60 * 5
15+
1216
/**
1317
* Shared Function
1418
*
@@ -51,7 +55,7 @@ export const refreshUserSubscriptionStatus = async (userId: string, { getSubscri
5155
// that still has 'time left' being subscribed.
5256
// next_billing_at will be present when a subscription is active or in trial, and will
5357
// indicate up till when we can trust the the user is subscribed.
54-
const expiry = entry.subscription['current_term_end'] || entry.subscription['next_billing_at']
58+
const expiry = (entry.subscription['current_term_end'] || entry.subscription['next_billing_at']) + expiryGraceSecs
5559
const subPlanId = entry.subscription.plan_id as UserPlan
5660
// console.log(`Valid subscription for UserId:${userId}, planId:${subPlanId}, expiry:${expiry}`);
5761

0 commit comments

Comments
 (0)