FRE-5348: Fix P1 billing issues
- Add null check for subscription items in updateSubscription - Implement webhook handlers with Prisma DB persistence - cancelSubscription already correctly passes cancel_at_period_end All P1 issues validated and fixed. Ready for Security Review. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -152,11 +152,19 @@ export class BillingService {
|
||||
|
||||
const newTierConfig = config.tiers[newTier];
|
||||
|
||||
// Ensure subscription has items before updating
|
||||
const firstItem = subscription.items.data[0];
|
||||
if (!firstItem?.id) {
|
||||
throw new Error(
|
||||
`Subscription ${subscriptionId} has no items to update`
|
||||
);
|
||||
}
|
||||
|
||||
const updated = await stripe.subscriptions.update(subscriptionId, {
|
||||
proration_behavior: 'create_prorations',
|
||||
items: [
|
||||
{
|
||||
id: subscription.items.data[0]?.id,
|
||||
id: firstItem.id,
|
||||
price: newTierConfig.priceId,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user