Skip to content

Commit 1f13ded

Browse files
Copilotniemyjski
andcommitted
Fix remaining Stripe.net v48 breaking changes: Invoice.Paid, Invoice.Discounts, and Coupon handling
Co-authored-by: niemyjski <[email protected]>
1 parent ea39f39 commit 1f13ded

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Exceptionless.Web/Controllers/OrganizationController.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public async Task<ActionResult<Invoice>> GetInvoiceAsync(string id)
239239
OrganizationId = organization.Id,
240240
OrganizationName = organization.Name,
241241
Date = stripeInvoice.Created,
242-
Paid = stripeInvoice.Paid,
242+
Paid = stripeInvoice.Status == "paid",
243243
Total = stripeInvoice.Total / 100.0m
244244
};
245245

@@ -260,7 +260,7 @@ public async Task<ActionResult<Invoice>> GetInvoiceAsync(string id)
260260
invoice.Items.Add(item);
261261
}
262262

263-
var coupon = stripeInvoice.Discount?.Coupon;
263+
var coupon = stripeInvoice.Discounts?.FirstOrDefault()?.Coupon;
264264
if (coupon is not null)
265265
{
266266
if (coupon.AmountOff.HasValue)
@@ -435,9 +435,6 @@ public async Task<ActionResult<ChangePlanResult>> ChangePlanAsync(string id, str
435435
Email = CurrentUser.EmailAddress
436436
};
437437

438-
if (!String.IsNullOrWhiteSpace(couponId))
439-
createCustomer.Coupon = couponId;
440-
441438
var customer = await customerService.CreateAsync(createCustomer);
442439

443440
// Create subscription separately since Plan is deprecated in CustomerCreateOptions
@@ -447,8 +444,14 @@ public async Task<ActionResult<ChangePlanResult>> ChangePlanAsync(string id, str
447444
Items = new List<SubscriptionItemOptions> { new SubscriptionItemOptions { Price = planId } }
448445
};
449446

447+
// Apply coupon as discount if provided
450448
if (!String.IsNullOrWhiteSpace(couponId))
451-
subscriptionCreateOptions.Coupon = couponId;
449+
{
450+
subscriptionCreateOptions.Discounts = new List<SubscriptionDiscountOptions>
451+
{
452+
new SubscriptionDiscountOptions { Coupon = couponId }
453+
};
454+
}
452455

453456
await subscriptionService.CreateAsync(subscriptionCreateOptions);
454457

@@ -485,6 +488,16 @@ public async Task<ActionResult<ChangePlanResult>> ChangePlanAsync(string id, str
485488
else
486489
{
487490
create.Items.Add(new SubscriptionItemOptions { Price = planId });
491+
492+
// Apply coupon as discount if provided
493+
if (!String.IsNullOrWhiteSpace(couponId))
494+
{
495+
create.Discounts = new List<SubscriptionDiscountOptions>
496+
{
497+
new SubscriptionDiscountOptions { Coupon = couponId }
498+
};
499+
}
500+
488501
await subscriptionService.CreateAsync(create);
489502
}
490503

0 commit comments

Comments
 (0)