Skip to content

Commit 437174f

Browse files
committed
test subscription saving customer id
1 parent d04fb5c commit 437174f

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

repos/License.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ const deleteLicense = async (userId: string): Promise<boolean> => {
118118

119119

120120

121-
const getLicenseByStripePaymentId = async (stripePaymentId: string): Promise<License | null> => {
121+
const getLicenseByCustomerId = async (customerId: string): Promise<License | null> => {
122122
const result = await db(tableName)
123-
.where({ stripe_payment_id: stripePaymentId })
123+
.where({ stripe_customer_id: customerId })
124124
.first('*')
125125

126126
return result || null
@@ -139,11 +139,11 @@ const updateLicenseByStripePaymentId = async (stripePaymentId: string, status: L
139139
}
140140

141141
export const LicenseRepo = {
142+
getLicenseByCustomerId,
142143
getActiveLicenseByUserId,
143144
getFreeTrialLicenseByUserId,
144145
getExistingSubscriptionLicenseByUserId,
145146
getLicenseByUserId,
146-
getLicenseByStripePaymentId,
147147
createLicense,
148148
updateLicense,
149149
deleteLicense,

services/WebhookService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const getNotificationEngine = (): NotificationEngine => {
1313
}
1414

1515
const handleCheckoutSessionCompleted = async (session: Stripe.Checkout.Session): Promise<void> => {
16-
const customerId = session.customer as string
16+
const customer = session.customer as Stripe.Customer
17+
console.log('customer', customer)
18+
const customerId = customer.id
1719
const userId = session.client_reference_id || session.metadata?.user_id
1820
const productId = session.metadata?.product_id
1921

@@ -114,7 +116,7 @@ const handleSubscriptionUpdated = async (subscription: Stripe.Subscription): Pro
114116
const notificationEngine = getNotificationEngine()
115117

116118
// Get license info to get user_id
117-
const license = await LicenseRepo.getLicenseByStripePaymentId(subscription.id)
119+
const license = await LicenseRepo.getLicenseByCustomerId(subscription.customer as string)
118120

119121
await notificationEngine.sendNotification({
120122
type: 'subscription_cancelled',

0 commit comments

Comments
 (0)