Skip to content

Commit 36af36d

Browse files
committed
refactor(billing): remove unused promo code fields and update charge amount calculation for clarity
1 parent 2e5ad23 commit 36af36d

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/resolvers/billingNew.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
BusinessOperationPayloadType,
77
PayloadOfDepositByUser,
88
PayloadOfWorkspacePlanPurchase,
9-
PromoCodeBenefitType,
109
Utm
1110
} from '@hawk.so/types';
1211
import checksumService from '../utils/checksumService';
@@ -119,11 +118,8 @@ export default {
119118
nextPaymentDate: Date;
120119
cloudPaymentsPublicId: string;
121120
promo?: {
122-
id: string;
123-
benefitType: PromoCodeBenefitType;
124121
originalAmount: number;
125122
finalAmount: number;
126-
discountAmount: number;
127123
};
128124
}> {
129125
const { workspaceId, tariffPlanId, shouldSaveCard, promoCode } = input;
@@ -165,7 +161,7 @@ export default {
165161
isCardLinkOperation = true;
166162
}
167163

168-
let paymentAmount = plan.monthlyCharge;
164+
let tariffChargeAmount = plan.monthlyCharge;
169165
let paymentPromoChecksum: PaymentPromoData | undefined;
170166
let composePaymentPromo;
171167

@@ -174,14 +170,11 @@ export default {
174170
const promoCodeService = new PromoCodeService(factories);
175171
const pricing = await promoCodeService.getPricingForPlan(promoCode, user.id, workspace._id.toString(), plan);
176172

177-
paymentAmount = pricing.finalAmount;
173+
tariffChargeAmount = pricing.finalAmount;
178174
paymentPromoChecksum = buildPaymentPromoData(pricing.promoCode._id.toString(), promoUtm);
179175
composePaymentPromo = {
180-
id: pricing.promoCode._id.toString(),
181-
benefitType: pricing.benefitType,
182176
originalAmount: pricing.originalAmount,
183177
finalAmount: pricing.finalAmount,
184-
discountAmount: pricing.discountAmount,
185178
};
186179
} catch (error) {
187180
throwPromoCodeGraphQLError(error);
@@ -216,7 +209,7 @@ export default {
216209

217210
const checksum = await checksumService.generateChecksum(checksumData);
218211

219-
const loggedAmount = isCardLinkOperation ? AMOUNT_FOR_CARD_VALIDATION : paymentAmount;
212+
const chargeAmount = isCardLinkOperation ? AMOUNT_FOR_CARD_VALIDATION : tariffChargeAmount;
220213

221214
/**
222215
* Send info to Telegram (non-blocking)
@@ -225,7 +218,7 @@ export default {
225218
.sendMessage(`👀 [Billing / Compose payment]
226219
227220
card link operation: ${isCardLinkOperation}
228-
amount: ${+loggedAmount} RUB
221+
amount: ${chargeAmount} RUB
229222
last charge date: ${workspace.lastChargeDate?.toISOString()}
230223
next payment date: ${nextPaymentDate.toISOString()}
231224
workspace id: ${workspace._id.toString()}
@@ -240,7 +233,7 @@ debug: ${Boolean(workspace.isDebug)}`
240233
name: plan.name,
241234
monthlyCharge: plan.monthlyCharge,
242235
},
243-
chargeAmount: isCardLinkOperation ? AMOUNT_FOR_CARD_VALIDATION : paymentAmount,
236+
chargeAmount,
244237
isCardLinkOperation,
245238
currency: 'RUB',
246239
checksum,

src/typeDefs/billing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ type ComposePaymentResponse {
337337
plan: ComposePaymentPlanInfo!
338338
339339
"""
340-
Amount to charge for this payment (may differ from plan.monthlyCharge when promo is applied)
340+
Amount to charge for this payment (card validation amount, promo price, or full plan price)
341341
"""
342342
chargeAmount: Int!
343343

0 commit comments

Comments
 (0)