Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Orbit.Api/Controllers/SubscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task<IActionResult> CreateCheckout(
// Apply referral discount coupon if user has one, otherwise allow manual promo codes
if (!string.IsNullOrEmpty(user.ReferralCouponId))
{
sessionOptions.Discounts = [new SessionDiscountOptions { PromotionCode = user.ReferralCouponId }];
sessionOptions.Discounts = [new SessionDiscountOptions { Coupon = user.ReferralCouponId }];
logger.LogInformation("Applying referral coupon {CouponId} to checkout for user {UserId}", user.ReferralCouponId, userId);
}
else
Expand Down
28 changes: 3 additions & 25 deletions src/Orbit.Infrastructure/Services/StripeCouponRewardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ public async Task<string> CreateReferralCouponAsync(Guid userId, CancellationTok
if (user is null)
throw new InvalidOperationException($"User {userId} not found for coupon creation");

// Ensure user has a Stripe customer
if (string.IsNullOrEmpty(user.StripeCustomerId))
{
var customerService = new CustomerService();
var customer = await customerService.CreateAsync(new CustomerCreateOptions
{
Email = user.Email,
Name = user.Name,
Metadata = new Dictionary<string, string> { { "userId", userId.ToString() } }
}, cancellationToken: cancellationToken);
user.SetStripeCustomerId(customer.Id);
await unitOfWork.SaveChangesAsync(cancellationToken);
}

var couponService = new CouponService();
var coupon = await couponService.CreateAsync(new CouponCreateOptions
{
Expand All @@ -49,19 +35,11 @@ public async Task<string> CreateReferralCouponAsync(Guid userId, CancellationTok
}
}, cancellationToken: cancellationToken);

var promoCodeService = new PromotionCodeService();
var promoCode = await promoCodeService.CreateAsync(new PromotionCodeCreateOptions
{
Promotion = new PromotionCodePromotionOptions { Coupon = coupon.Id },
Customer = user.StripeCustomerId,
MaxRedemptions = 1
}, cancellationToken: cancellationToken);

logger.LogInformation(
"Created referral coupon for user {UserId}: coupon={CouponId}, promoCode={PromoCodeId}",
userId, coupon.Id, promoCode.Id);
"Created referral coupon for user {UserId}: couponId={CouponId}",
userId, coupon.Id);

return promoCode.Id;
return coupon.Id;
}

public async Task<string?> GetUserPromotionCodeAsync(Guid userId, CancellationToken cancellationToken = default)
Expand Down
Loading