mirror of
https://github.com/vernu/textbee.git
synced 2026-05-05 14:13:24 -04:00
chore(api): add more logs to billing webhook
This commit is contained in:
@@ -42,15 +42,19 @@ export class BillingController {
|
||||
// Handle Polar.sh webhook events
|
||||
switch (payload.type) {
|
||||
case 'subscription.created':
|
||||
console.log('polar subscription.created')
|
||||
console.log(payload)
|
||||
await this.billingService.switchPlan({
|
||||
userId: payload.data.userId,
|
||||
newPlanName: payload.data?.product?.name || 'pro',
|
||||
userId: payload.data.customerId,
|
||||
newPlanName: payload.data?.product?.name?.split(' ')[payload.data?.product?.name?.length - 1] || 'pro',
|
||||
newPlanPolarProductId: payload.data?.product?.id,
|
||||
})
|
||||
break
|
||||
|
||||
// @ts-ignore
|
||||
case 'subscription.cancelled':
|
||||
console.log('polar subscription.cancelled')
|
||||
console.log(payload)
|
||||
await this.billingService.switchPlan({
|
||||
// @ts-ignore
|
||||
userId: payload?.data?.userId,
|
||||
@@ -58,7 +62,7 @@ export class BillingController {
|
||||
})
|
||||
break
|
||||
default:
|
||||
console.log('Unhandled event type:', payload.type)
|
||||
console.log('Unhandled polar event type:', payload.type)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +105,10 @@ export class BillingService {
|
||||
customerEmail: user.email,
|
||||
customerName: user.name,
|
||||
customerIpAddress: req.ip,
|
||||
customerId: user._id?.toString(),
|
||||
metadata: {
|
||||
userId: user._id?.toString(),
|
||||
customerId: user._id?.toString(),
|
||||
},
|
||||
}
|
||||
const discount = await this.polarApi.discounts.get({
|
||||
|
||||
Reference in New Issue
Block a user