Untitled
case "customer.subscription.deleted": user = await User.findOne({ stripeCustomerId: event.data.object.customer }); user.subscription = undefined; user.paid = false; user.expiresAt = ""; user.stripeCustomerId = ""; user.subscriptionId = ""; !IS_DEV && (await unsubscribeUserFromStarGame({ phone: user.phone, reference: user?.reference, })); await user.save(); case "invoice.payment_succeeded": try { invoiceRes = await stripe.retrieveInvoiceInfo( event?.data?.object?.id ); if ( invoiceRes?.billing_reason === "subscription_update" || invoiceRes?.billing_reason === "subscription_cycle" ) { user = await User.findOne({ stripeCustomerId: invoiceRes.customer, }).populate("subscription"); user.expiresAt = addTime( user?.expiresAt, user?.subscription?.duration_type ); user.paid = true; await user.save(); !IS_DEV && (await extendUserSubscriptionToStarGame({ phone: user.phone, expDate: user.expiresAt, })); } break;
Leave a Comment