1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-11 22:52:15 -05:00

[PM-21345] Re-add existing customer coupon after subscription update (#5788)

* Re-add existing customer coupon after subscription update

* Run dotnet format
This commit is contained in:
Alex Morask 2025-05-08 14:07:35 -04:00 committed by GitHub
parent af08d4b2a5
commit e3f6562d3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -112,6 +112,8 @@ public class StripePaymentService : IPaymentService
throw new BadRequestException("You do not have an active subscription. Reinstate your subscription to make changes.");
}
var existingCoupon = sub.Customer.Discount?.Coupon?.Id;
var collectionMethod = sub.CollectionMethod;
var daysUntilDue = sub.DaysUntilDue;
var chargeNow = collectionMethod == "charge_automatically";
@ -216,6 +218,19 @@ public class StripePaymentService : IPaymentService
DaysUntilDue = daysUntilDue,
});
}
var customer = await _stripeAdapter.CustomerGetAsync(sub.CustomerId);
var newCoupon = customer.Discount?.Coupon?.Id;
if (!string.IsNullOrEmpty(existingCoupon) && string.IsNullOrEmpty(newCoupon))
{
// Re-add the lost coupon due to the update.
await _stripeAdapter.CustomerUpdateAsync(sub.CustomerId, new CustomerUpdateOptions
{
Coupon = existingCoupon
});
}
}
return paymentIntentClientSecret;