feat: add platform invoice dunning workflow

This commit is contained in:
Codex
2026-06-30 05:27:58 +08:00
parent f9f96bee63
commit c74432ce98
25 changed files with 858 additions and 23 deletions

View File

@@ -126,6 +126,24 @@ export interface PlatformInvoiceItem {
note?: string | null;
}
export interface PlatformInvoiceReminderItem {
id: string;
tenantId: string;
tenantSlug?: string | null;
tenantName?: string | null;
invoiceId: string;
invoiceNo?: string | null;
reminderType?: string | null;
channel?: string | null;
status?: string | null;
reminderDate?: string | null;
reminderLevel?: number | string | null;
dueDate?: string | null;
balanceCentsSnapshot?: number | string | null;
message?: string | null;
createdAt?: string | null;
}
export interface PlatformUsageItem {
id: string;
tenantId: string;
@@ -265,6 +283,12 @@ export interface ConfirmPlatformInvoicePaymentInput {
providerTradeNo?: string;
}
export interface ProcessPlatformOverdueInvoicesInput {
dryRun?: boolean;
channel?: string;
limit?: number;
}
export interface RecordPlatformUsageInput {
tenantId: string;
metricKey: string;
@@ -417,6 +441,34 @@ export async function confirmPlatformInvoicePayment(input: ConfirmPlatformInvoic
});
}
export async function processPlatformOverdueInvoices(input: ProcessPlatformOverdueInvoicesInput = {}) {
return apiRequest<{
item?: {
dryRun?: boolean;
processed?: number;
markedOverdue?: number;
reminderCreated?: number;
skippedReminder?: number;
items?: Array<PlatformInvoiceItem & {
wouldMarkOverdue?: boolean;
wouldCreateReminder?: boolean;
reminderCreated?: boolean;
}>;
};
}>('/api/platform-admin/invoices/process-overdue', {
method: 'POST',
body: input,
tenantId: null,
});
}
export async function loadPlatformInvoiceReminders(query: { tenantId?: string; invoiceId?: string; status?: string; reminderType?: string; limit?: number } = {}) {
return apiRequest<{ items?: PlatformInvoiceReminderItem[] }>('/api/platform-admin/invoices/reminders', {
query: { ...query, limit: query.limit || 100 },
tenantId: null,
});
}
export async function recordPlatformUsage(input: RecordPlatformUsageInput) {
return apiRequest<{ item?: Record<string, unknown> }>('/api/platform-admin/usage', {
method: 'POST',