Skip to content

Commit 903ff2d

Browse files
committed
fix(billing): fail coupon creation on partial product resolution
1 parent 6450ec8 commit 903ff2d

File tree

1 file changed

+17
-9
lines changed
  • apps/sim/app/api/v1/admin/referral-campaigns

1 file changed

+17
-9
lines changed

apps/sim/app/api/v1/admin/referral-campaigns/route.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,27 @@ async function resolveProductIds(stripe: Stripe, targets: AppliesTo[]): Promise<
127127
if (plan.annualDiscountPriceId) priceIds.push(plan.annualDiscountPriceId)
128128
}
129129

130-
const productIds = new Set<string>()
131-
await Promise.all(
130+
const results = await Promise.allSettled(
132131
priceIds.map(async (priceId) => {
133-
try {
134-
const price = await stripe.prices.retrieve(priceId)
135-
const productId = typeof price.product === 'string' ? price.product : price.product.id
136-
productIds.add(productId)
137-
} catch (err) {
138-
logger.warn('Failed to resolve product for price, skipping', { priceId, err })
139-
}
132+
const price = await stripe.prices.retrieve(priceId)
133+
return typeof price.product === 'string' ? price.product : price.product.id
140134
})
141135
)
142136

137+
const failures = results.filter((r) => r.status === 'rejected')
138+
if (failures.length > 0) {
139+
logger.error('Failed to resolve all Stripe products for appliesTo', {
140+
failed: failures.length,
141+
total: priceIds.length,
142+
})
143+
throw new Error('Could not resolve all Stripe products for the specified plan categories.')
144+
}
145+
146+
const productIds = new Set<string>()
147+
for (const r of results) {
148+
if (r.status === 'fulfilled') productIds.add(r.value)
149+
}
150+
143151
return [...productIds]
144152
}
145153

0 commit comments

Comments
 (0)