2026-02-20 16:02:13 +00:00
|
|
|
import { apiClient } from './api/client';
|
2026-02-12 21:21:55 +00:00
|
|
|
import { Purchase, Product } from '../types';
|
2026-01-07 09:33:52 +00:00
|
|
|
|
|
|
|
|
const MOCK_PURCHASES: Purchase[] = [
|
2026-01-13 18:47:57 +00:00
|
|
|
{
|
|
|
|
|
id: 'p1',
|
|
|
|
|
orderId: 'ORD-9921',
|
|
|
|
|
date: '2023-10-24',
|
|
|
|
|
price: 29.99,
|
|
|
|
|
status: 'completed',
|
|
|
|
|
downloadUrl: '#',
|
|
|
|
|
license: { id: 'l1', name: 'Standard', price: 29.99, features: [] },
|
|
|
|
|
product: {
|
|
|
|
|
id: 'prod1',
|
|
|
|
|
title: 'Cyberpunk 2077 Drums',
|
|
|
|
|
type: 'pack',
|
|
|
|
|
price: 29.99,
|
|
|
|
|
currency: 'USD',
|
|
|
|
|
rating: 5,
|
|
|
|
|
coverUrl: 'https://picsum.photos/id/120/100/100',
|
|
|
|
|
author: 'Neon Audio',
|
2026-02-12 21:21:55 +00:00
|
|
|
} as Partial<Product> as Product,
|
2026-01-13 18:47:57 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'p2',
|
|
|
|
|
orderId: 'ORD-9850',
|
|
|
|
|
date: '2023-10-15',
|
|
|
|
|
price: 49.99,
|
|
|
|
|
status: 'completed',
|
|
|
|
|
downloadUrl: '#',
|
|
|
|
|
license: { id: 'l2', name: 'Premium', price: 49.99, features: [] },
|
|
|
|
|
product: {
|
|
|
|
|
id: 'prod2',
|
|
|
|
|
title: 'Ethereal Pads Vol. 1',
|
|
|
|
|
type: 'pack',
|
|
|
|
|
price: 49.99,
|
|
|
|
|
currency: 'USD',
|
|
|
|
|
rating: 4,
|
|
|
|
|
coverUrl: 'https://picsum.photos/id/140/100/100',
|
|
|
|
|
author: 'Soundscapes',
|
2026-02-12 21:21:55 +00:00
|
|
|
} as Partial<Product> as Product,
|
2026-01-13 18:47:57 +00:00
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const RECENT_SALES = [
|
2026-01-13 18:47:57 +00:00
|
|
|
{
|
|
|
|
|
id: 's1',
|
|
|
|
|
product: 'Cyberpunk 2077 Drums',
|
|
|
|
|
date: '2 mins ago',
|
|
|
|
|
amount: 29.99,
|
|
|
|
|
buyer: 'User_992',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 's2',
|
|
|
|
|
product: 'Dark Techno Bunker',
|
|
|
|
|
date: '1 hour ago',
|
|
|
|
|
amount: 49.99,
|
|
|
|
|
buyer: 'TechnoFan',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 's3',
|
|
|
|
|
product: 'Ethereal Pads Vol. 1',
|
|
|
|
|
date: '3 hours ago',
|
|
|
|
|
amount: 14.99,
|
|
|
|
|
buyer: 'AmbientSoul',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 's4',
|
|
|
|
|
product: 'Cyberpunk 2077 Drums',
|
|
|
|
|
date: '5 hours ago',
|
|
|
|
|
amount: 29.99,
|
|
|
|
|
buyer: 'ProducerX',
|
|
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const commerceService = {
|
2026-01-13 18:47:57 +00:00
|
|
|
getPurchases: async () => {
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
|
|
|
return MOCK_PURCHASES;
|
|
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
getSales: async () => {
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
|
|
|
return RECENT_SALES;
|
|
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
getSellerStats: async () => {
|
2026-02-20 16:02:13 +00:00
|
|
|
const response = await apiClient.get<{ data?: { revenue?: number; sales?: number; sales_count?: number } }>(
|
|
|
|
|
'/sell/stats'
|
|
|
|
|
);
|
|
|
|
|
const data = (response.data?.data ?? response.data) as Record<string, unknown> | undefined;
|
2026-01-13 18:47:57 +00:00
|
|
|
return {
|
2026-02-20 16:02:13 +00:00
|
|
|
revenue: (data?.revenue as number) ?? 0,
|
|
|
|
|
sales: (data?.sales_count ?? data?.sales) as number ?? 0,
|
|
|
|
|
views: 0,
|
|
|
|
|
conversion: 0,
|
2026-01-13 18:47:57 +00:00
|
|
|
};
|
|
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
|
2026-01-13 18:47:57 +00:00
|
|
|
requestRefund: async (_orderId: string, _reason: string) => {
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
|
|
|
return { success: true };
|
|
|
|
|
},
|
2026-01-07 09:33:52 +00:00
|
|
|
};
|