Skip to content

Commit 832485b

Browse files
committed
update message to subscription expired
1 parent 5727782 commit 832485b

File tree

2 files changed

+69
-38
lines changed

2 files changed

+69
-38
lines changed

services/WebhookService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ const handleSubscriptionDeleted = async (subscription: Stripe.Subscription): Pro
157157
const notificationEngine = getNotificationEngine()
158158

159159
await notificationEngine.sendNotification({
160-
type: 'subscription_cancelled',
160+
type: 'subscription_expired',
161161
user: {
162162
id: updatedLicense.user_id || 'unknown',
163163
email: 'N/A' // Email not available in subscription object
164164
},
165-
referenceId: `subscription_cancelled_${subscription.id}`,
165+
referenceId: `subscription_expired_${subscription.id}`,
166166
data: {
167167
subscription_id: subscription.id,
168168
customer_id: subscription.customer,
169169
license_id: updatedLicense.id,
170-
cancelled_at: new Date(),
170+
expired_at: new Date(),
171171
status: subscription.status
172172
}
173173
}, ['discord'])

services/providers/DiscordNotificationProvider.ts

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export class DiscordNotificationProvider implements NotificationProvider {
7272
return this.formatCheckoutCompletedNotification(payload)
7373
case 'subscription_cancelled':
7474
return this.formatSubscriptionCancelledNotification(payload)
75+
case 'subscription_expired':
76+
return this.formatSubscriptionExpiredNotification(payload)
7577
default:
7678
return this.formatGenericNotification(payload)
7779
}
@@ -302,10 +304,69 @@ export class DiscordNotificationProvider implements NotificationProvider {
302304
}
303305
}
304306

305-
private formatSubscriptionCancelledNotification(payload: NotificationPayload): DiscordWebhookPayload {
307+
private formatSubscriptionCancelledNotification(payload: NotificationPayload): DiscordWebhookPayload {
308+
const embed: DiscordEmbed = {
309+
title: '❌ Subscription Cancelled',
310+
description: `A user's subscription has been cancelled`,
311+
color: 0xFF4444, // Warning red color
312+
fields: [
313+
{
314+
name: '👤 User ID',
315+
value: payload.user.id,
316+
inline: true
317+
},
318+
{
319+
name: '🗓️ Cancelled At',
320+
value: payload.data?.cancelled_at ? `<t:${Math.floor(new Date(payload.data.cancelled_at).getTime() / 1000)}:R>` : 'Just now',
321+
inline: true
322+
},
323+
{
324+
name: '📋 Subscription ID',
325+
value: payload.data?.subscription_id || 'Unknown',
326+
inline: false
327+
}
328+
],
329+
footer: {
330+
text: 'Ebb Platform Notifications'
331+
},
332+
timestamp: new Date().toISOString()
333+
}
334+
335+
// Add optional fields if available
336+
if (payload.data?.license_id) {
337+
embed.fields?.push({
338+
name: '🎫 License ID',
339+
value: payload.data.license_id,
340+
inline: true
341+
})
342+
}
343+
344+
if (payload.data?.customer_id) {
345+
embed.fields?.push({
346+
name: '🏪 Customer ID',
347+
value: payload.data.customer_id,
348+
inline: true
349+
})
350+
}
351+
352+
if (payload.data?.status) {
353+
embed.fields?.push({
354+
name: '📊 Status',
355+
value: payload.data.status,
356+
inline: true
357+
})
358+
}
359+
360+
return {
361+
embeds: [embed],
362+
username: 'Ebb Notifications',
363+
}
364+
}
365+
366+
private formatSubscriptionExpiredNotification(payload: NotificationPayload): DiscordWebhookPayload {
306367
const embed: DiscordEmbed = {
307-
title: '❌ Subscription Cancelled',
308-
description: `A user's subscription has been cancelled`,
368+
title: '❌ Subscription Expired',
369+
description: `A user's subscription has expired`,
309370
color: 0xFF4444, // Warning red color
310371
fields: [
311372
{
@@ -314,14 +375,9 @@ export class DiscordNotificationProvider implements NotificationProvider {
314375
inline: true
315376
},
316377
{
317-
name: '🗓️ Cancelled At',
318-
value: payload.data?.cancelled_at ? `<t:${Math.floor(new Date(payload.data.cancelled_at).getTime() / 1000)}:R>` : 'Just now',
378+
name: '🗓️ Expired At',
379+
value: payload.data?.expired_at ? `<t:${Math.floor(new Date(payload.data.expired_at).getTime() / 1000)}:R>` : 'Just now',
319380
inline: true
320-
},
321-
{
322-
name: '📋 Subscription ID',
323-
value: payload.data?.subscription_id || 'Unknown',
324-
inline: false
325381
}
326382
],
327383
footer: {
@@ -330,31 +386,6 @@ export class DiscordNotificationProvider implements NotificationProvider {
330386
timestamp: new Date().toISOString()
331387
}
332388

333-
// Add optional fields if available
334-
if (payload.data?.license_id) {
335-
embed.fields?.push({
336-
name: '🎫 License ID',
337-
value: payload.data.license_id,
338-
inline: true
339-
})
340-
}
341-
342-
if (payload.data?.customer_id) {
343-
embed.fields?.push({
344-
name: '🏪 Customer ID',
345-
value: payload.data.customer_id,
346-
inline: true
347-
})
348-
}
349-
350-
if (payload.data?.status) {
351-
embed.fields?.push({
352-
name: '📊 Status',
353-
value: payload.data.status,
354-
inline: true
355-
})
356-
}
357-
358389
return {
359390
embeds: [embed],
360391
username: 'Ebb Notifications',

0 commit comments

Comments
 (0)