File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as log from 'log'
22import Stripe from 'stripe'
33import * as jwt from 'jsonwebtoken'
4- import { getThingsOfUser , updateUserRecord } from './db'
4+ import { getThingsOfUser , getUserRecord , updateUserRecord } from './db'
55import { isProd , proactivelyRediscoverAllDevices } from './helper'
66import { publish } from './mqtt'
77import { PlanName } from './Plan'
@@ -188,11 +188,17 @@ export async function handleStripeInvoicePaymentFailed({
188188 return
189189 }
190190
191- const hasSubscription = await hasActiveStripeSubscription (
191+ const userRecord = await getUserRecord ( metadata . userId , false )
192+
193+ const hasStripeSubscription = await hasActiveStripeSubscription (
192194 stripeCustomerId as string
193195 )
194196
195- if ( ! hasSubscription ) {
197+ const hasPaddleSubscription =
198+ userRecord . paddleCustomerId &&
199+ ( await hasActivePaddleSubscription ( userRecord . paddleCustomerId ) )
200+
201+ if ( ! hasStripeSubscription && ! hasPaddleSubscription ) {
196202 await switchToPlan ( metadata . userId , PlanName . FREE )
197203 }
198204}
You can’t perform that action at this time.
0 commit comments