feat(billing): add percentage discount coupons

Admins can create coupon codes that discount specific services (app
runtimes, optional services, managed products, custom-domain addon, or
all) and restrict them to specific users or make them public, with total
and per-user usage caps and an active date window.

Coupons apply in deploy, renewal, and upgrade flows: cost-breakdown lines
are tagged with a service key, the eligible portion is discounted and
capped to the payable amount, the invoice records discountAmount/
discountCode, and the redemption is recorded once when the invoice is
fully paid (covering wallet, gateway, and mixed payments).

- Discount + DiscountRedemption entities; invoice discount columns
- DiscountService (CRUD, validation, redemption) + admin/validate API
- Idempotent schema bootstrap on init so production (synchronize off)
  provisions the tables/columns without a migration runner
- Admin discounts UI, coupon entry in deploy/renewal, invoice discount line
- fa/en strings; discount.service unit spec

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
keyhan
2026-06-20 11:48:45 +03:30
parent b232129ee2
commit 49726f1dfd
21 changed files with 2013 additions and 20 deletions
+26
View File
@@ -172,6 +172,22 @@ export class CalculateDeployCostDto extends CalculateCostDto {
@ApiProperty({ enum: BillingCycle, example: 'monthly' })
@IsEnum(BillingCycle)
cycle: BillingCycle;
@ApiPropertyOptional({ example: 'NOWRUZ1403', description: 'Coupon discount code' })
@IsOptional()
@IsString()
couponCode?: string;
}
export class PayApplicationDto {
@ApiProperty({ enum: BillingCycle, example: 'monthly' })
@IsEnum(BillingCycle)
cycle: BillingCycle;
@ApiPropertyOptional({ example: 'NOWRUZ1403', description: 'Coupon discount code' })
@IsOptional()
@IsString()
couponCode?: string;
}
// ─── Renewal & Upgrade DTOs ─────────────────────────────────────────
@@ -180,6 +196,11 @@ export class RenewApplicationDto {
@ApiProperty({ enum: BillingCycle, example: 'monthly' })
@IsEnum(BillingCycle)
cycle: BillingCycle;
@ApiPropertyOptional({ example: 'NOWRUZ1403', description: 'Coupon discount code' })
@IsOptional()
@IsString()
couponCode?: string;
}
export class UpgradeResourcesDto {
@@ -236,6 +257,11 @@ export class UpgradeResourcesDto {
@ValidateNested()
@Type(() => OptionalServiceResourcesDto)
rabbitmqResources?: OptionalServiceResourcesDto;
@ApiPropertyOptional({ example: 'NOWRUZ1403', description: 'Coupon discount code' })
@IsOptional()
@IsString()
couponCode?: string;
}
export class CalculateUpgradeCostDto extends UpgradeResourcesDto {}