Skip to content

Commit e34a17e

Browse files
authored
Prevent payment previews being truncated by the term end date (#3314)
* Preview payments from first payment date * Extend term for previews
1 parent c3e44be commit e34a17e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

modules/zuora/src/createSubscription/previewCreateSubscription.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export const previewCreateSubscription = async (
6767
});
6868

6969
const numberOfMonthsToPreview = 13; // 13 allows for annual subs to have a second invoice
70+
createSubscriptionOrderAction.createSubscription.terms.initialTerm.period =
71+
numberOfMonthsToPreview + 1; // This is to work round an issue where Zuora cuts off the preview at the term end date
72+
7073
const orderRequest: PreviewOrderRequest = {
7174
existingAccountNumber: accountNumber,
7275
orderDate: zuoraDateFormat(dayjs()),

modules/zuora/test/createSubscriptionIntegration.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('createSubscription integration', () => {
4444
const productPurchase: ProductPurchase = {
4545
product: 'NationalDelivery',
4646
ratePlan: 'EverydayPlus',
47-
firstDeliveryDate: dayjs().add(1, 'month').toDate(),
47+
firstDeliveryDate: dayjs().add(1, 'week').toDate(),
4848
deliveryContact: contact,
4949
deliveryInstructions: 'Leave at front door',
5050
deliveryAgent: 123,
@@ -265,4 +265,36 @@ describe('createSubscription integration', () => {
265265
)?.unitPrice,
266266
).toEqual(discountAmount);
267267
});
268+
test('Payment schedule is not truncated by the subscription term', async () => {
269+
const inputFields: PreviewCreateSubscriptionInputFields = {
270+
stage: 'CODE',
271+
accountNumber: 'A01036826',
272+
currency: currency,
273+
productPurchase: productPurchase,
274+
};
275+
const client = await ZuoraClient.create('CODE');
276+
const response = await previewCreateSubscription(
277+
client,
278+
productCatalog,
279+
mockPromotions,
280+
inputFields,
281+
);
282+
283+
// Check that all Digital Pack items have the same amount.
284+
// Previously we had a bug where the last item in the payment schedule was only covering the period
285+
// up until the end of the subscription term, causing it to be a different amount from all the other items.
286+
const digitalPackInvoiceItems =
287+
response.previewResult.invoices[0]?.invoiceItems.filter(
288+
(item) => item.chargeName === 'Digital Pack',
289+
) ?? [];
290+
291+
const [firstDigitalPackItem] = digitalPackInvoiceItems;
292+
expect(
293+
digitalPackInvoiceItems.every(
294+
(item) =>
295+
firstDigitalPackItem !== undefined &&
296+
item.amountWithoutTax === firstDigitalPackItem.amountWithoutTax,
297+
),
298+
).toBe(true);
299+
});
268300
});

0 commit comments

Comments
 (0)