| 50 | const logger = createLogger('AdminPromoCodes') |
| 51 | |
| 52 | function formatPromoCode(promo: { |
| 53 | id: string |
| 54 | code: string |
| 55 | coupon: { |
| 56 | id: string |
| 57 | name: string | null |
| 58 | percent_off: number | null |
| 59 | duration: string |
| 60 | duration_in_months: number | null |
| 61 | applies_to?: { products: string[] } |
| 62 | } |
| 63 | max_redemptions: number | null |
| 64 | expires_at: number | null |
| 65 | active: boolean |
| 66 | times_redeemed: number |
| 67 | created: number |
| 68 | }): AdminV1PromoCode { |
| 69 | return { |
| 70 | id: promo.id, |
| 71 | code: promo.code, |
| 72 | couponId: promo.coupon.id, |
| 73 | name: promo.coupon.name ?? '', |
| 74 | percentOff: promo.coupon.percent_off ?? 0, |
| 75 | duration: promo.coupon.duration, |
| 76 | durationInMonths: promo.coupon.duration_in_months, |
| 77 | appliesToProductIds: promo.coupon.applies_to?.products ?? null, |
| 78 | maxRedemptions: promo.max_redemptions, |
| 79 | expiresAt: promo.expires_at ? new Date(promo.expires_at * 1000).toISOString() : null, |
| 80 | active: promo.active, |
| 81 | timesRedeemed: promo.times_redeemed, |
| 82 | createdAt: new Date(promo.created * 1000).toISOString(), |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Resolve appliesTo values to unique Stripe product IDs. |