Skip to content

Commit 8809a53

Browse files
committed
do not switch to FREE plan if user has a Paddle subscription
1 parent d0a49bb commit 8809a53

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

subscription.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as log from 'log'
22
import Stripe from 'stripe'
33
import * as jwt from 'jsonwebtoken'
4-
import { getThingsOfUser, updateUserRecord } from './db'
4+
import { getThingsOfUser, getUserRecord, updateUserRecord } from './db'
55
import { isProd, proactivelyRediscoverAllDevices } from './helper'
66
import { publish } from './mqtt'
77
import { 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
}

0 commit comments

Comments
 (0)