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:
@@ -655,6 +655,7 @@ const en: Dictionary = {
|
||||
},
|
||||
title: 'Invoices',
|
||||
subtitle: 'Review what each payment was for and pay open invoices.',
|
||||
subtotal: 'Subtotal',
|
||||
walletBalance: 'Wallet balance',
|
||||
toman: 'Toman',
|
||||
filterAll: 'All',
|
||||
@@ -1102,6 +1103,69 @@ const en: Dictionary = {
|
||||
saveFailedShort: 'Failed to save',
|
||||
hours: 'hours',
|
||||
days: 'days',
|
||||
discounts: {
|
||||
title: 'Discount codes',
|
||||
subtitle: 'Percentage discounts on different services — public or for specific users.',
|
||||
add: 'New discount',
|
||||
empty: 'No discount codes yet',
|
||||
edit: 'Edit',
|
||||
delete: 'Delete',
|
||||
deleteConfirm: 'Delete this discount code?',
|
||||
code: 'Code',
|
||||
codePlaceholder: 'NOWRUZ1403',
|
||||
name: 'Label',
|
||||
namePlaceholder: 'Nowruz discount',
|
||||
description: 'Description',
|
||||
percentOff: 'Percent off',
|
||||
scope: 'Eligible services',
|
||||
allServices: 'All services',
|
||||
selectServices: 'Select specific services',
|
||||
audience: 'Eligible users',
|
||||
public: 'Public (all users)',
|
||||
restricted: 'Specific users',
|
||||
searchUsers: 'Search users by name or email…',
|
||||
noUsersSelected: 'No users selected yet',
|
||||
limits: 'Limits',
|
||||
maxUses: 'Total usage cap',
|
||||
maxUsesPerUser: 'Per-user cap',
|
||||
unlimited: 'Unlimited',
|
||||
startsAt: 'Start date',
|
||||
endsAt: 'End date',
|
||||
active: 'Active',
|
||||
inactive: 'Inactive',
|
||||
used: 'Used',
|
||||
save: 'Save',
|
||||
saving: 'Saving…',
|
||||
cancel: 'Cancel',
|
||||
saved: 'Discount code saved',
|
||||
deleted: 'Discount code deleted',
|
||||
saveFailed: 'Failed to save discount code',
|
||||
groups: {
|
||||
runtime: 'App runtimes',
|
||||
optional: 'Optional services',
|
||||
managed: 'Managed services',
|
||||
addon: 'Add-ons',
|
||||
},
|
||||
coupon: {
|
||||
label: 'Discount code',
|
||||
placeholder: 'Enter discount code',
|
||||
apply: 'Apply',
|
||||
checking: 'Checking…',
|
||||
applied: 'Discount applied',
|
||||
remove: 'Remove',
|
||||
discountLine: 'Discount',
|
||||
},
|
||||
reasons: {
|
||||
not_found: 'Invalid discount code',
|
||||
inactive: 'This discount code is inactive',
|
||||
not_started: 'This code is not active yet',
|
||||
expired: 'This code has expired',
|
||||
max_uses_reached: 'This code has reached its usage limit',
|
||||
max_uses_per_user_reached: 'You have reached your usage limit for this code',
|
||||
not_eligible_user: 'This code is not available for your account',
|
||||
no_eligible_services: 'This code does not discount your selected services',
|
||||
},
|
||||
},
|
||||
},
|
||||
servicesNew: {
|
||||
steps: ['Service type', 'Configuration', 'Review & pay'],
|
||||
|
||||
Reference in New Issue
Block a user