57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { apiFetch } from './client';
|
|
|
|
export interface WalletTransaction {
|
|
transaction_id: string;
|
|
transaction_type: 'EARN' | 'REDEEM' | 'REFUND' | 'ADJUSTMENT' | string;
|
|
reference_type: string;
|
|
reference_id: string;
|
|
reference_no: string;
|
|
base_amount: number;
|
|
percentage_applied: number | null;
|
|
credit_amount: number;
|
|
status: 'PENDING' | 'MATURED' | 'COMPLETED' | 'VOIDED' | 'EXPIRED' | string;
|
|
matures_at: string | null;
|
|
matured_at: string | null;
|
|
voided_at: string | null;
|
|
void_reason: string | null;
|
|
description: string | null;
|
|
created_at: string | null;
|
|
}
|
|
|
|
export interface WalletSummary {
|
|
wallet_id: string;
|
|
customer_id: string;
|
|
active_balance: number;
|
|
pending_balance: number;
|
|
lifetime_earned: number;
|
|
lifetime_redeemed: number;
|
|
currency: string;
|
|
is_locked: boolean;
|
|
transactions: WalletTransaction[];
|
|
}
|
|
|
|
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 const creditService = {
|
|
/**
|
|
* Retrieves the current customer's spendable balance, pending balance, and transaction history.
|
|
*/
|
|
async getMyWallet(): Promise<WalletSummary> {
|
|
return apiFetch<WalletSummary>('/api/v1/credits/my-wallet');
|
|
},
|
|
|
|
/**
|
|
* Retrieves current credit & return window parameters.
|
|
*/
|
|
async getCreditSettings(): Promise<CreditSettings> {
|
|
return apiFetch<CreditSettings>('/api/v1/credits/settings', { skipAuth: true });
|
|
},
|
|
};
|