Billing and account fixed - final

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-05 12:56:24 +00:00
parent ee4fa53987
commit 4a16a6a402
10 changed files with 176 additions and 246 deletions

View File

@@ -1,6 +1,6 @@
/**
* Billing API Service
* Uses STANDARD existing billing endpoints from /v1/billing/, /v1/system/, and /v1/admin/
* Uses STANDARD billing endpoints from /api/v1/billing and /api/v1/admin/billing
*/
import { fetchAPI } from './api';
@@ -142,6 +142,9 @@ export interface CreditPackage {
is_featured: boolean;
description: string;
display_order: number;
is_active?: boolean;
sort_order?: number;
stripe_price_id?: string | null;
}
export interface TeamMember {
@@ -188,6 +191,7 @@ export interface PendingPayment extends Payment {
// ============================================================================
export async function getCreditBalance(): Promise<CreditBalance> {
// Use business billing CreditTransactionViewSet.balance
return fetchAPI('/v1/billing/transactions/balance/');
}
@@ -196,7 +200,7 @@ export async function getCreditTransactions(): Promise<{
count: number;
current_balance?: number;
}> {
return fetchAPI('/v1/billing/transactions/');
return fetchAPI('/api/v1/billing/transactions/');
}
// ============================================================================
@@ -216,7 +220,7 @@ export async function getCreditUsage(params?: {
if (params?.start_date) queryParams.append('start_date', params.start_date);
if (params?.end_date) queryParams.append('end_date', params.end_date);
const url = `/v1/billing/credits/usage/${queryParams.toString() ? '?' + queryParams.toString() : ''}`;
const url = `/api/v1/billing/credits/usage/${queryParams.toString() ? '?' + queryParams.toString() : ''}`;
return fetchAPI(url);
}
@@ -261,8 +265,8 @@ export async function getCreditUsageLimits(): Promise<{
// ============================================================================
export async function getAdminBillingStats(): Promise<AdminBillingStats> {
// Use business billing admin stats endpoint (returns all dashboard metrics)
return fetchAPI('/v1/billing/admin/stats/');
// Admin billing dashboard metrics
return fetchAPI('/v1/admin/billing/stats/');
}
export async function getAdminInvoices(params?: { status?: string; account_id?: number; search?: string }): Promise<{
@@ -332,7 +336,8 @@ export async function getCreditCosts(): Promise<{
results: CreditCostConfig[];
count: number;
}> {
return fetchAPI('/v1/admin/billing/credit-costs/');
// credit costs are served from the admin namespace (modules billing)
return fetchAPI('/v1/admin/credit-costs/');
}
export async function updateCreditCosts(
@@ -344,7 +349,7 @@ export async function updateCreditCosts(
message: string;
updated_count: number;
}> {
return fetchAPI('/v1/admin/billing/credit-costs/', {
return fetchAPI('/v1/admin/credit-costs/', {
method: 'POST',
body: JSON.stringify({ costs }),
});
@@ -434,6 +439,15 @@ export async function getCreditPackages(): Promise<{
return fetchAPI('/v1/billing/credit-packages/');
}
// Admin credit packages (CRUD capable backend; currently read-only here)
export async function getAdminCreditPackages(): Promise<{
results: CreditPackage[];
count: number;
}> {
// Backend does not expose a dedicated admin credit-packages list; fall back to the shared packages list
return fetchAPI('/v1/billing/credit-packages/');
}
export async function purchaseCreditPackage(data: {
package_id: number;
payment_method: 'stripe' | 'paypal' | 'bank_transfer' | 'local_wallet';
@@ -447,7 +461,7 @@ export async function purchaseCreditPackage(data: {
stripe_client_secret?: string;
paypal_order_id?: string;
}> {
return fetchAPI(`/v1/billing/credit-packages/${data.package_id}/purchase/`, {
return fetchAPI(`/api/v1/billing/credit-packages/${data.package_id}/purchase/`, {
method: 'POST',
body: JSON.stringify({ payment_method: data.payment_method }),
});
@@ -495,7 +509,7 @@ export async function getAvailablePaymentMethods(): Promise<{
results: PaymentMethod[];
count: number;
}> {
return fetchAPI('/v1/billing/payment-methods/');
return fetchAPI('/api/v1/billing/payment-methods/');
}
export async function createManualPayment(data: {
@@ -509,7 +523,7 @@ export async function createManualPayment(data: {
status: string;
message: string;
}> {
return fetchAPI('/v1/billing/payments/manual/', {
return fetchAPI('/api/v1/billing/payments/manual/', {
method: 'POST',
body: JSON.stringify(data),
});
@@ -523,7 +537,7 @@ export async function getPendingPayments(): Promise<{
results: PendingPayment[];
count: number;
}> {
return fetchAPI('/v1/billing/admin/pending_payments/');
return fetchAPI('/api/v1/billing/admin/pending_payments/');
}
export async function approvePayment(paymentId: number, data?: {
@@ -532,7 +546,7 @@ export async function approvePayment(paymentId: number, data?: {
message: string;
payment: Payment;
}> {
return fetchAPI(`/v1/billing/admin/${paymentId}/approve_payment/`, {
return fetchAPI(`/api/v1/billing/admin/${paymentId}/approve_payment/`, {
method: 'POST',
body: JSON.stringify(data || {}),
});
@@ -545,7 +559,7 @@ export async function rejectPayment(paymentId: number, data: {
message: string;
payment: Payment;
}> {
return fetchAPI(`/v1/billing/admin/${paymentId}/reject_payment/`, {
return fetchAPI(`/api/v1/billing/admin/${paymentId}/reject_payment/`, {
method: 'POST',
body: JSON.stringify(data),
});