From 89e98a144a1c1db2a6d860e459b4cfd57ece1e81 Mon Sep 17 00:00:00 2001 From: Lisa Chan Date: Fri, 10 Apr 2026 11:47:04 -0400 Subject: [PATCH] fix(payments-next): Show pre-discount tax --- .../customer/src/lib/invoice.manager.spec.ts | 41 ++++++++++++++++++- .../customer/src/lib/invoice.manager.ts | 3 ++ .../src/lib/subscriptionManagement.service.ts | 6 ++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/libs/payments/customer/src/lib/invoice.manager.spec.ts b/libs/payments/customer/src/lib/invoice.manager.spec.ts index 7a1d62c7b4b..1e6a8f86ac1 100644 --- a/libs/payments/customer/src/lib/invoice.manager.spec.ts +++ b/libs/payments/customer/src/lib/invoice.manager.spec.ts @@ -307,7 +307,37 @@ describe('InvoiceManager', () => { ); const mockPreviewUpcomingInvoice = InvoicePreviewFactory(); - jest + const spy = jest + .spyOn(stripeClient, 'invoicesRetrieveUpcoming') + .mockResolvedValue(mockUpcomingInvoice); + + mockedStripeInvoiceToFirstInvoicePreviewDTO.mockReturnValue( + mockPreviewUpcomingInvoice + ); + + const result = await invoiceManager.previewUpcomingSubscription({ + customer: mockCustomer, + subscription: mockSubscription, + }); + expect(result).toEqual(mockPreviewUpcomingInvoice); + expect(spy).toHaveBeenCalledWith({ + customer: mockCustomer.id, + subscription: mockSubscription.id, + subscription_details: { + cancel_at_period_end: false, + }, + }); + }); + + it('passes empty string discounts when excludeDiscounts is true', async () => { + const mockCustomer = StripeCustomerFactory({ currency: 'usd' }); + const mockSubscription = StripeSubscriptionFactory(); + const mockUpcomingInvoice = StripeResponseFactory( + StripeUpcomingInvoiceFactory() + ); + const mockPreviewUpcomingInvoice = InvoicePreviewFactory(); + + const spy = jest .spyOn(stripeClient, 'invoicesRetrieveUpcoming') .mockResolvedValue(mockUpcomingInvoice); @@ -318,8 +348,17 @@ describe('InvoiceManager', () => { const result = await invoiceManager.previewUpcomingSubscription({ customer: mockCustomer, subscription: mockSubscription, + excludeDiscounts: true, }); expect(result).toEqual(mockPreviewUpcomingInvoice); + expect(spy).toHaveBeenCalledWith({ + customer: mockCustomer.id, + subscription: mockSubscription.id, + subscription_details: { + cancel_at_period_end: false, + }, + discounts: '', + }); }); }); diff --git a/libs/payments/customer/src/lib/invoice.manager.ts b/libs/payments/customer/src/lib/invoice.manager.ts index 5be07ab641f..7fb94a8e494 100644 --- a/libs/payments/customer/src/lib/invoice.manager.ts +++ b/libs/payments/customer/src/lib/invoice.manager.ts @@ -187,9 +187,11 @@ export class InvoiceManager { async previewUpcomingSubscription({ customer, subscription, + excludeDiscounts, }: { customer: StripeCustomer; subscription: StripeSubscription; + excludeDiscounts?: boolean; }): Promise { const upcomingInvoice = await this.stripeClient.invoicesRetrieveUpcoming({ customer: customer.id, @@ -197,6 +199,7 @@ export class InvoiceManager { subscription_details: { cancel_at_period_end: false, }, + ...(excludeDiscounts ? { discounts: '' } : {}), }); return stripeInvoiceToInvoicePreviewDTO(upcomingInvoice); diff --git a/libs/payments/management/src/lib/subscriptionManagement.service.ts b/libs/payments/management/src/lib/subscriptionManagement.service.ts index 34a0a0652bf..c8c52d11392 100644 --- a/libs/payments/management/src/lib/subscriptionManagement.service.ts +++ b/libs/payments/management/src/lib/subscriptionManagement.service.ts @@ -459,6 +459,7 @@ export class SubscriptionManagementService { this.invoiceManager.previewUpcomingSubscription({ customer, subscription, + excludeDiscounts: true, }), this.churnInterventionService.determineStaySubscribedEligibility( uid, @@ -501,12 +502,13 @@ export class SubscriptionManagementService { const { nextInvoiceDate, - promotionName: nextPromotionName, subsequentAmount, subsequentAmountExcludingTax, subsequentTax, } = upcomingInvoice; + const nextPromotionName = subscription.discount?.coupon.name ?? null; + const totalExclusiveTax = taxAmounts .filter((tax) => !tax.inclusive) .reduce((sum, tax) => sum + tax.amount, 0); @@ -791,6 +793,7 @@ export class SubscriptionManagementService { await this.invoiceManager.previewUpcomingSubscription({ customer: stripeCustomer, subscription, + excludeDiscounts: true, }); if (!upcomingInvoice) { @@ -912,6 +915,7 @@ export class SubscriptionManagementService { await this.invoiceManager.previewUpcomingSubscription({ customer: stripeCustomer, subscription, + excludeDiscounts: true, }); if (!upcomingInvoice) {