Skip to content

Commit 5693467

Browse files
committed
refactor(billing): remove unused promo code fields and simplify payment amount calculation logic
1 parent e0af65c commit 5693467

3 files changed

Lines changed: 5 additions & 60 deletions

File tree

src/resolvers/billingNew.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ export default {
177177
paymentAmount = pricing.finalAmount;
178178
paymentPromoChecksum = buildPaymentPromoData(pricing.promoCode._id.toString(), promoUtm);
179179
composePaymentPromo = {
180-
id: pricing.promoCode._id.toString(),
181-
benefitType: pricing.benefitType,
182180
originalAmount: pricing.originalAmount,
183181
finalAmount: pricing.finalAmount,
184-
discountAmount: pricing.discountAmount,
185182
};
186183
} catch (error) {
187184
throwPromoCodeGraphQLError(error);
@@ -375,23 +372,6 @@ debug: ${Boolean(workspace.isDebug)}`
375372
throw new UserInputError('Wrong checksum data');
376373
}
377374

378-
let planPaymentAmount = plan.monthlyCharge;
379-
380-
if (paymentData.promo?.id) {
381-
try {
382-
const pricing = await new PromoCodeService(factories).getPricingForPromoCodeId(
383-
paymentData.promo.id,
384-
user.id,
385-
paymentData.workspaceId,
386-
plan
387-
);
388-
389-
planPaymentAmount = pricing.finalAmount;
390-
} catch (error) {
391-
throwPromoCodeGraphQLError(error);
392-
}
393-
}
394-
395375
const token = fullUserInfo.bankCards?.find(card => card.id === args.input.cardId)?.token;
396376

397377
if (!token) {
@@ -425,7 +405,7 @@ debug: ${Boolean(workspace.isDebug)}`
425405
}
426406
}
427407

428-
let amount = planPaymentAmount;
408+
let amount = plan.monthlyCharge;
429409

430410
const isPaymentForCurrentTariffPlan = workspace.tariffPlanId.toString() === plan._id.toString();
431411

src/typeDefs/billing.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,6 @@ type VerifyPromoCodeResponse {
311311
Promo data returned with composePayment
312312
"""
313313
type ComposePaymentPromo {
314-
"""
315-
Applied promo code id
316-
"""
317-
id: ID!
318-
319-
"""
320-
Promo benefit type
321-
"""
322-
benefitType: PromoCodeBenefitType!
323-
324314
"""
325315
Plan price before promo
326316
"""
@@ -330,11 +320,6 @@ type ComposePaymentPromo {
330320
Plan price after promo
331321
"""
332322
finalAmount: Int!
333-
334-
"""
335-
Actual discount amount in money
336-
"""
337-
discountAmount: Int!
338323
}
339324
340325
"""

test/resolvers/billingNew.test.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,8 @@ describe('GraphQLBillingNew', () => {
356356
expect(result.plan.monthlyCharge).toBe(1000);
357357
expect(result.chargeAmount).toBe(750);
358358
expect(result.promo).toMatchObject({
359-
id: promoCodeId.toString(),
360-
benefitType: 'percent_discount',
361359
originalAmount: 1000,
362360
finalAmount: 750,
363-
discountAmount: 250,
364361
});
365362

366363
const checksumData = checksumService.parseAndVerifyChecksum(result.checksum);
@@ -566,8 +563,7 @@ describe('GraphQLBillingNew', () => {
566563
jest.clearAllMocks();
567564
});
568565

569-
it('should charge discounted amount and set full recurrent amount from checksum promo id', async () => {
570-
const promoCodeId = new ObjectId();
566+
it('should charge full plan amount for recurrent payment', async () => {
571567
const userId = new ObjectId().toString();
572568
const workspaceId = new ObjectId().toString();
573569
const cardId = 'card-1';
@@ -587,9 +583,6 @@ describe('GraphQLBillingNew', () => {
587583
tariffPlanId: newPlanId.toString(),
588584
shouldSaveCard: false,
589585
nextPaymentDate: new Date().toISOString(),
590-
promo: {
591-
id: promoCodeId.toString(),
592-
},
593586
});
594587
const dueDate = new Date();
595588
dueDate.setMonth(dueDate.getMonth() + 1);
@@ -626,21 +619,8 @@ describe('GraphQLBillingNew', () => {
626619
getBusinessOperationByTransactionId: jest.fn().mockResolvedValue({ _id: new ObjectId() }),
627620
} as any,
628621
releasesFactory: {} as any,
629-
promoCodesFactory: {
630-
findOne: jest.fn().mockResolvedValue({
631-
_id: promoCodeId,
632-
value: 'SAVE25',
633-
benefit: {
634-
type: 'percent_discount',
635-
percent: 25,
636-
},
637-
}),
638-
} as any,
639-
promoCodeUsagesFactory: {
640-
countByPromoCodeId: jest.fn().mockResolvedValue(0),
641-
findByPromoCodeAndUser: jest.fn().mockResolvedValue(null),
642-
findByPromoCodeAndWorkspace: jest.fn().mockResolvedValue(null),
643-
} as any,
622+
promoCodesFactory: {} as any,
623+
promoCodeUsagesFactory: {} as any,
644624
},
645625
};
646626

@@ -664,7 +644,7 @@ describe('GraphQLBillingNew', () => {
664644

665645
expect(cloudPaymentsApi.payByToken).toHaveBeenCalledWith(
666646
expect.objectContaining({
667-
Amount: 750,
647+
Amount: 1000,
668648
JsonData: expect.objectContaining({
669649
cloudPayments: expect.objectContaining({
670650
recurrent: expect.objectContaining({

0 commit comments

Comments
 (0)