Skip to content

Commit 4c25dc0

Browse files
committed
feat(billing): introduce PaymentPromoBenefitType and update promo data structure
1 parent e926076 commit 4c25dc0

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/billing/types/paymentData.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { Utm } from '@hawk.so/types';
1+
import type { PromoCodeBenefitType, Utm } from '@hawk.so/types';
2+
3+
/**
4+
* Promo benefit types that can be applied during payment.
5+
*/
6+
export type PaymentPromoBenefitType = Exclude<PromoCodeBenefitType, 'grant_plan'>;
27

38
/**
49
* Data for setting up recurring payments
@@ -49,7 +54,7 @@ export interface PaymentPromoData {
4954
/**
5055
* Promo benefit type
5156
*/
52-
benefitType: 'percent_discount' | 'amount_discount' | 'fixed_price';
57+
benefitType: PaymentPromoBenefitType;
5358

5459
/**
5560
* Plan price before promo

src/resolvers/billingNew.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as telegram from '../utils/telegram';
1414
import { TelegramBotURLs } from '../utils/telegram';
1515
import PromoCodeService, { PromoCodeError, PromoCodeErrorCode, PromoCodePreviewResult, buildPaymentPromoData } from '../utils/promoCodeService';
1616
import { publish } from '../rabbitmq';
17+
import type { PaymentPromoData } from '../billing/types/paymentData';
1718
import type { Utm } from '@hawk.so/types';
1819
import { validateUtmParams } from '../utils/utm/utm';
1920

@@ -117,13 +118,7 @@ export default {
117118
checksum: string;
118119
nextPaymentDate: Date;
119120
cloudPaymentsPublicId: string;
120-
promo?: {
121-
id: string;
122-
benefitType: 'percent_discount' | 'amount_discount' | 'fixed_price';
123-
originalAmount: number;
124-
finalAmount: number;
125-
discountAmount: number;
126-
};
121+
promo?: PaymentPromoData;
127122
}> {
128123
const { workspaceId, tariffPlanId, shouldSaveCard, promoCode } = input;
129124
const promoUtm = validateUtmParams(input.promoUtm);

src/utils/promoCodeService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import PromoCodeModel from '../models/promoCode';
88
import WorkspaceModel from '../models/workspace';
99
import { ContextFactories } from '../types/graphql';
1010
import type { Utm } from '@hawk.so/types';
11-
import type { PaymentPromoData } from '../billing/types/paymentData';
11+
import type { PaymentPromoData, PaymentPromoBenefitType } from '../billing/types/paymentData';
1212

1313
const PROMO_CODE_REGEXP = /^[A-Z0-9_-]+$/;
1414
const DEFAULT_MIN_FINAL_PRICE = 1;
@@ -342,7 +342,7 @@ function validateBenefitStructure(benefit: PromoCodeBenefit): void {
342342
export function buildPaymentPromoData(pricing: PromoCodePricingResult, utm?: Utm): PaymentPromoData {
343343
return {
344344
id: pricing.promoCode._id.toString(),
345-
benefitType: pricing.benefitType as PaymentPromoData['benefitType'],
345+
benefitType: pricing.benefitType as PaymentPromoBenefitType,
346346
originalAmount: pricing.originalAmount,
347347
finalAmount: pricing.finalAmount,
348348
discountAmount: pricing.discountAmount,

0 commit comments

Comments
 (0)