ifixkart-admin/New admin panel/ikixkart-dashboard/services/api/creditService.ts
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

74 lines
2.1 KiB
TypeScript

import { apiFetch } from './client';
export interface CreditSettings {
credits_enabled: boolean;
credits_sales_percentage: number;
credits_sales_return_window_days: number;
credits_service_percentage: number;
credits_service_claim_window_days: number;
credits_minimum_order_value: number;
credits_expiry_days: number;
}
export interface CreditTransaction {
transaction_id: string;
transaction_type: 'EARN' | 'REDEEM' | 'VOID_RETURN' | 'ADJUSTMENT';
reference_type: 'ORDER' | 'SERVICE_JOB' | 'MANUAL_ADMIN' | 'PURCHASE_REDEMPTION';
reference_id: string;
reference_no?: string;
base_amount: number;
percentage_applied?: number;
credit_amount: number;
status: 'PENDING' | 'MATURED' | 'VOIDED' | 'EXPIRED';
matures_at?: string;
matured_at?: string;
voided_at?: string;
void_reason?: string;
description?: string;
created_at?: string;
}
export interface CustomerWalletSummary {
wallet_id: string;
customer_id: string;
active_balance: number;
pending_balance: number;
lifetime_earned: number;
lifetime_redeemed: number;
currency: string;
is_locked: boolean;
transactions: CreditTransaction[];
}
export const creditService = {
getSettings: async (): Promise<CreditSettings> => {
return apiFetch<CreditSettings>('/api/v1/credits/settings');
},
updateSettings: async (payload: Partial<CreditSettings>): Promise<CreditSettings> => {
return apiFetch<CreditSettings>('/api/v1/credits/settings', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
getCustomerWallet: async (customerId: string): Promise<CustomerWalletSummary> => {
return apiFetch<CustomerWalletSummary>(`/api/v1/credits/wallets/${customerId}`);
},
adjustWallet: async (
customerId: string,
payload: { amount: number; adjustment_type: 'CREDIT' | 'DEBIT'; reason: string }
) => {
return apiFetch(`/api/v1/credits/wallets/${customerId}/adjust`, {
method: 'POST',
body: JSON.stringify(payload),
});
},
triggerMaturitySweep: async () => {
return apiFetch<{ message: string; result: any }>('/api/v1/cron/process-credit-maturity', {
method: 'POST',
});
},
};