feat(payments): add transparent balance guidance

This commit is contained in:
2026-03-11 14:52:09 +04:00
parent 8401688032
commit 79f96ba45b
25 changed files with 3855 additions and 93 deletions

View File

@@ -10,6 +10,7 @@ import {
import {
HOUSEHOLD_MEMBER_ABSENCE_POLICIES,
HOUSEHOLD_MEMBER_LIFECYCLE_STATUSES,
HOUSEHOLD_PAYMENT_BALANCE_ADJUSTMENT_POLICIES,
HOUSEHOLD_TOPIC_ROLES,
type HouseholdMemberAbsencePolicy,
type HouseholdMemberAbsencePolicyRecord,
@@ -18,6 +19,7 @@ import {
type HouseholdJoinTokenRecord,
type HouseholdMemberLifecycleStatus,
type HouseholdMemberRecord,
type HouseholdPaymentBalanceAdjustmentPolicy,
type HouseholdPendingMemberRecord,
type HouseholdTelegramChatRecord,
type HouseholdTopicBindingRecord,
@@ -47,6 +49,18 @@ function normalizeMemberLifecycleStatus(raw: string): HouseholdMemberLifecycleSt
throw new Error(`Unsupported household member lifecycle status: ${raw}`)
}
function normalizePaymentBalanceAdjustmentPolicy(
raw: string
): HouseholdPaymentBalanceAdjustmentPolicy {
const normalized = raw.trim().toLowerCase()
if ((HOUSEHOLD_PAYMENT_BALANCE_ADJUSTMENT_POLICIES as readonly string[]).includes(normalized)) {
return normalized as HouseholdPaymentBalanceAdjustmentPolicy
}
return 'utilities'
}
function normalizeMemberAbsencePolicy(raw: string): HouseholdMemberAbsencePolicy {
const normalized = raw.trim().toLowerCase()
@@ -206,6 +220,7 @@ function toCurrencyCode(raw: string): CurrencyCode {
function toHouseholdBillingSettingsRecord(row: {
householdId: string
settlementCurrency: string
paymentBalanceAdjustmentPolicy: string
rentAmountMinor: bigint | null
rentCurrency: string
rentDueDay: number
@@ -217,6 +232,9 @@ function toHouseholdBillingSettingsRecord(row: {
return {
householdId: row.householdId,
settlementCurrency: toCurrencyCode(row.settlementCurrency),
paymentBalanceAdjustmentPolicy: normalizePaymentBalanceAdjustmentPolicy(
row.paymentBalanceAdjustmentPolicy
),
rentAmountMinor: row.rentAmountMinor,
rentCurrency: toCurrencyCode(row.rentCurrency),
rentDueDay: row.rentDueDay,
@@ -917,6 +935,8 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
.select({
householdId: schema.householdBillingSettings.householdId,
settlementCurrency: schema.householdBillingSettings.settlementCurrency,
paymentBalanceAdjustmentPolicy:
schema.householdBillingSettings.paymentBalanceAdjustmentPolicy,
rentAmountMinor: schema.householdBillingSettings.rentAmountMinor,
rentCurrency: schema.householdBillingSettings.rentCurrency,
rentDueDay: schema.householdBillingSettings.rentDueDay,
@@ -948,6 +968,11 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
settlementCurrency: input.settlementCurrency
}
: {}),
...(input.paymentBalanceAdjustmentPolicy
? {
paymentBalanceAdjustmentPolicy: input.paymentBalanceAdjustmentPolicy
}
: {}),
...(input.rentAmountMinor !== undefined
? {
rentAmountMinor: input.rentAmountMinor
@@ -989,6 +1014,8 @@ export function createDbHouseholdConfigurationRepository(databaseUrl: string): {
.returning({
householdId: schema.householdBillingSettings.householdId,
settlementCurrency: schema.householdBillingSettings.settlementCurrency,
paymentBalanceAdjustmentPolicy:
schema.householdBillingSettings.paymentBalanceAdjustmentPolicy,
rentAmountMinor: schema.householdBillingSettings.rentAmountMinor,
rentCurrency: schema.householdBillingSettings.rentCurrency,
rentDueDay: schema.householdBillingSettings.rentDueDay,