Skip to content

Commit

Permalink
[PM-18268] SM Marketing Initiated Trials cause invoice previewing to … (
Browse files Browse the repository at this point in the history
#5404)

(cherry picked from commit 288f08d)
  • Loading branch information
jonashendrickx authored and cturnbull-bitwarden committed Feb 14, 2025
1 parent b6da145 commit 12673f0
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/Core/Services/Implementations/StripePaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,6 @@ public async Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(
Enabled = true,
},
Currency = "usd",
Discounts = new List<InvoiceDiscountOptions>(),
SubscriptionDetails = new InvoiceSubscriptionDetailsOptions
{
Items =
Expand Down Expand Up @@ -1903,29 +1902,23 @@ public async Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(
];
}

if (gatewayCustomerId != null)
if (!string.IsNullOrWhiteSpace(gatewayCustomerId))
{
var gatewayCustomer = await _stripeAdapter.CustomerGetAsync(gatewayCustomerId);

if (gatewayCustomer.Discount != null)
{
options.Discounts.Add(new InvoiceDiscountOptions
{
Discount = gatewayCustomer.Discount.Id
});
options.Coupon = gatewayCustomer.Discount.Coupon.Id;
}
}

if (gatewaySubscriptionId != null)
{
var gatewaySubscription = await _stripeAdapter.SubscriptionGetAsync(gatewaySubscriptionId);
if (!string.IsNullOrWhiteSpace(gatewaySubscriptionId))
{
var gatewaySubscription = await _stripeAdapter.SubscriptionGetAsync(gatewaySubscriptionId);

if (gatewaySubscription?.Discount != null)
{
options.Discounts.Add(new InvoiceDiscountOptions
{
Discount = gatewaySubscription.Discount.Id
});
}
if (gatewaySubscription?.Discount != null)
{
options.Coupon ??= gatewaySubscription.Discount.Coupon.Id;
}
}

Expand Down Expand Up @@ -1976,7 +1969,6 @@ public async Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(
Enabled = true,
},
Currency = "usd",
Discounts = new List<InvoiceDiscountOptions>(),
SubscriptionDetails = new InvoiceSubscriptionDetailsOptions
{
Items =
Expand Down Expand Up @@ -2069,7 +2061,7 @@ public async Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(

if (gatewayCustomer.Discount != null)
{
options.Discounts.Add(new InvoiceDiscountOptions { Discount = gatewayCustomer.Discount.Id });
options.Coupon = gatewayCustomer.Discount.Coupon.Id;
}
}

Expand All @@ -2079,10 +2071,7 @@ public async Task<PreviewInvoiceResponseModel> PreviewInvoiceAsync(

if (gatewaySubscription?.Discount != null)
{
options.Discounts.Add(new InvoiceDiscountOptions
{
Discount = gatewaySubscription.Discount.Id
});
options.Coupon ??= gatewaySubscription.Discount.Coupon.Id;
}
}

Expand Down

0 comments on commit 12673f0

Please sign in to comment.