Skip to content

Commit 3cedb74

Browse files
committed
address comments
1 parent 007a6e6 commit 3cedb74

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

apps/sim/app/api/v1/admin/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export type {
103103
AdminOrganization,
104104
AdminOrganizationBillingSummary,
105105
AdminOrganizationDetail,
106-
AdminReferralCampaign,
107106
AdminSeatAnalytics,
108107
AdminSingleResponse,
109108
AdminSubscription,
@@ -118,7 +117,6 @@ export type {
118117
AdminWorkspaceMember,
119118
DbMember,
120119
DbOrganization,
121-
DbReferralCampaign,
122120
DbSubscription,
123121
DbUser,
124122
DbUserStats,
@@ -147,7 +145,6 @@ export {
147145
parseWorkflowVariables,
148146
toAdminFolder,
149147
toAdminOrganization,
150-
toAdminReferralCampaign,
151148
toAdminSubscription,
152149
toAdminUser,
153150
toAdminWorkflow,

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,30 @@ export const POST = withAdminAuth(async (request) => {
193193
...(effectiveDuration === 'repeating' ? { duration_in_months: durationInMonths } : {}),
194194
})
195195

196-
const promoParams: Stripe.PromotionCodeCreateParams = {
197-
coupon: coupon.id,
198-
...(code ? { code: code.trim().toUpperCase() } : {}),
199-
...(maxRedemptions ? { max_redemptions: maxRedemptions } : {}),
200-
...(expiresAt ? { expires_at: Math.floor(new Date(expiresAt).getTime() / 1000) } : {}),
201-
}
196+
let promoCode
197+
try {
198+
const promoParams: Stripe.PromotionCodeCreateParams = {
199+
coupon: coupon.id,
200+
...(code ? { code: code.trim().toUpperCase() } : {}),
201+
...(maxRedemptions ? { max_redemptions: maxRedemptions } : {}),
202+
...(expiresAt ? { expires_at: Math.floor(new Date(expiresAt).getTime() / 1000) } : {}),
203+
}
202204

203-
const promoCode = await stripe.promotionCodes.create(promoParams)
205+
promoCode = await stripe.promotionCodes.create(promoParams)
206+
} catch (promoError) {
207+
try {
208+
await stripe.coupons.del(coupon.id)
209+
} catch (cleanupError) {
210+
logger.error(
211+
'Admin API: Failed to clean up orphaned coupon after promo code creation failed',
212+
{
213+
couponId: coupon.id,
214+
cleanupError,
215+
}
216+
)
217+
}
218+
throw promoError
219+
}
204220

205221
logger.info('Admin API: Created Stripe promotion code', {
206222
promoCodeId: promoCode.id,

0 commit comments

Comments
 (0)