Skip to content

Commit

Permalink
feat: fix ts
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Dec 4, 2024
1 parent 3b688f2 commit b981da8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions web/app/api/webhook/handlers/subscription-canceled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { updateClerkMetadata } from '@/lib/services/clerk';
import { db, UserUsageTable } from '@/drizzle/schema';
import { eq } from 'drizzle-orm';
import { updateUserSubscriptionData } from '../utils';
import Stripe from 'stripe';

function getSubscriptionProduct(subscription: any): string | null {
const productKey = subscription.items?.data?.[0]?.price?.product?.metadata?.srm_product_key;
Expand All @@ -22,15 +23,15 @@ async function deleteUserSubscriptionData(userId: string) {
}

export const handleSubscriptionCanceled = createWebhookHandler(
async (event) => {
async (event: Stripe.CustomerSubscriptionDeletedEvent) => {
const subscription = event.data.object;
const userId = subscription.metadata?.userId;

await deleteUserSubscriptionData(userId);

const customerData: CustomerData = {
userId,
customerId: subscription.customer,
customerId: typeof subscription.customer === 'string' ? subscription.customer : subscription.customer.id,
status: 'canceled',
paymentStatus: 'canceled',
product: getSubscriptionProduct(subscription) || 'none',
Expand Down

0 comments on commit b981da8

Please sign in to comment.