@djangocfg/ext-payments 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +206 -0
- package/dist/chunk-5KY6HVXF.js +2593 -0
- package/dist/hooks.cjs +2666 -0
- package/dist/hooks.d.cts +186 -0
- package/dist/hooks.d.ts +186 -0
- package/dist/hooks.js +1 -0
- package/dist/index.cjs +2590 -0
- package/dist/index.d.cts +1287 -0
- package/dist/index.d.ts +1287 -0
- package/dist/index.js +1 -0
- package/package.json +79 -0
- package/src/api/generated/ext_payments/_utils/fetchers/ext_payments__payments.ts +408 -0
- package/src/api/generated/ext_payments/_utils/fetchers/index.ts +28 -0
- package/src/api/generated/ext_payments/_utils/hooks/ext_payments__payments.ts +147 -0
- package/src/api/generated/ext_payments/_utils/hooks/index.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/Balance.schema.ts +23 -0
- package/src/api/generated/ext_payments/_utils/schemas/Currency.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaginatedPaymentListList.schema.ts +24 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentDetail.schema.ts +44 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentList.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/Transaction.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/index.ts +24 -0
- package/src/api/generated/ext_payments/api-instance.ts +131 -0
- package/src/api/generated/ext_payments/client.ts +301 -0
- package/src/api/generated/ext_payments/enums.ts +64 -0
- package/src/api/generated/ext_payments/errors.ts +116 -0
- package/src/api/generated/ext_payments/ext_payments__payments/client.ts +118 -0
- package/src/api/generated/ext_payments/ext_payments__payments/index.ts +2 -0
- package/src/api/generated/ext_payments/ext_payments__payments/models.ts +135 -0
- package/src/api/generated/ext_payments/http.ts +103 -0
- package/src/api/generated/ext_payments/index.ts +273 -0
- package/src/api/generated/ext_payments/logger.ts +259 -0
- package/src/api/generated/ext_payments/retry.ts +175 -0
- package/src/api/generated/ext_payments/schema.json +850 -0
- package/src/api/generated/ext_payments/storage.ts +161 -0
- package/src/api/generated/ext_payments/validation-events.ts +133 -0
- package/src/api/index.ts +9 -0
- package/src/config.ts +20 -0
- package/src/contexts/BalancesContext.tsx +62 -0
- package/src/contexts/CurrenciesContext.tsx +63 -0
- package/src/contexts/OverviewContext.tsx +173 -0
- package/src/contexts/PaymentsContext.tsx +121 -0
- package/src/contexts/PaymentsExtensionProvider.tsx +55 -0
- package/src/contexts/README.md +201 -0
- package/src/contexts/RootPaymentsContext.tsx +65 -0
- package/src/contexts/index.ts +45 -0
- package/src/contexts/types.ts +40 -0
- package/src/hooks/index.ts +20 -0
- package/src/index.ts +36 -0
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +92 -0
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +291 -0
- package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +290 -0
- package/src/layouts/PaymentsLayout/components/index.ts +2 -0
- package/src/layouts/PaymentsLayout/events.ts +47 -0
- package/src/layouts/PaymentsLayout/index.ts +16 -0
- package/src/layouts/PaymentsLayout/types.ts +6 -0
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +128 -0
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +142 -0
- package/src/layouts/PaymentsLayout/views/overview/components/index.ts +2 -0
- package/src/layouts/PaymentsLayout/views/overview/index.tsx +20 -0
- package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +277 -0
- package/src/layouts/PaymentsLayout/views/payments/components/index.ts +1 -0
- package/src/layouts/PaymentsLayout/views/payments/index.tsx +17 -0
- package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +273 -0
- package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +1 -0
- package/src/layouts/PaymentsLayout/views/transactions/index.tsx +17 -0
- package/src/utils/logger.ts +9 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, type ReactNode } from 'react';
|
|
4
|
+
import * as ExtPaymentsFetchers from '../api/generated/ext_payments/_utils/fetchers';
|
|
5
|
+
import { apiPayments } from '../api';
|
|
6
|
+
import {
|
|
7
|
+
usePaymentsPaymentsList,
|
|
8
|
+
useCreatePaymentsPaymentsCreateCreate,
|
|
9
|
+
useCreatePaymentsPaymentsConfirmCreate,
|
|
10
|
+
} from '../api/generated/ext_payments/_utils/hooks';
|
|
11
|
+
import type {
|
|
12
|
+
PaginatedPaymentListList,
|
|
13
|
+
PaymentDetail,
|
|
14
|
+
PaymentList,
|
|
15
|
+
} from './types';
|
|
16
|
+
|
|
17
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
18
|
+
// Context Type
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
export interface PaymentsContextValue {
|
|
22
|
+
// List
|
|
23
|
+
payments: PaginatedPaymentListList | undefined;
|
|
24
|
+
isLoadingPayments: boolean;
|
|
25
|
+
paymentsError: Error | undefined;
|
|
26
|
+
refreshPayments: () => Promise<void>;
|
|
27
|
+
|
|
28
|
+
// Operations
|
|
29
|
+
getPayment: (id: string) => Promise<PaymentDetail | undefined>;
|
|
30
|
+
createPayment: () => Promise<PaymentList>;
|
|
31
|
+
confirmPayment: (id: string) => Promise<PaymentList>;
|
|
32
|
+
checkPaymentStatus: (id: string) => Promise<PaymentList | undefined>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
36
|
+
// Context
|
|
37
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
const PaymentsContext = createContext<PaymentsContextValue | undefined>(undefined);
|
|
40
|
+
|
|
41
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
42
|
+
// Provider
|
|
43
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
export function PaymentsProvider({ children }: { children: ReactNode }) {
|
|
46
|
+
// List payments (first page only for count)
|
|
47
|
+
const {
|
|
48
|
+
data: payments,
|
|
49
|
+
error: paymentsError,
|
|
50
|
+
isLoading: isLoadingPayments,
|
|
51
|
+
mutate: mutatePayments,
|
|
52
|
+
} = usePaymentsPaymentsList({ page: 1, page_size: 1 }, apiPayments);
|
|
53
|
+
|
|
54
|
+
const refreshPayments = async () => {
|
|
55
|
+
await mutatePayments();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Mutations
|
|
59
|
+
const createPaymentMutation = useCreatePaymentsPaymentsCreateCreate();
|
|
60
|
+
const confirmPaymentMutation = useCreatePaymentsPaymentsConfirmCreate();
|
|
61
|
+
|
|
62
|
+
// Get single payment
|
|
63
|
+
const getPayment = async (id: string): Promise<PaymentDetail | undefined> => {
|
|
64
|
+
return ExtPaymentsFetchers.getPaymentsPaymentsRetrieve(id, apiPayments);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Create payment
|
|
68
|
+
const createPayment = async (): Promise<PaymentList> => {
|
|
69
|
+
const result = await createPaymentMutation(apiPayments);
|
|
70
|
+
await refreshPayments();
|
|
71
|
+
return result as PaymentList;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Confirm payment (user clicked "I paid")
|
|
75
|
+
const confirmPayment = async (id: string): Promise<PaymentList> => {
|
|
76
|
+
const result = await confirmPaymentMutation(id, apiPayments);
|
|
77
|
+
await refreshPayments();
|
|
78
|
+
return result as PaymentList;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Check payment status
|
|
82
|
+
const checkPaymentStatus = async (id: string): Promise<PaymentList | undefined> => {
|
|
83
|
+
return ExtPaymentsFetchers.getPaymentsPaymentsStatusRetrieve(id, apiPayments);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const value: PaymentsContextValue = {
|
|
87
|
+
payments,
|
|
88
|
+
isLoadingPayments,
|
|
89
|
+
paymentsError,
|
|
90
|
+
refreshPayments,
|
|
91
|
+
getPayment,
|
|
92
|
+
createPayment,
|
|
93
|
+
confirmPayment,
|
|
94
|
+
checkPaymentStatus,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return <PaymentsContext.Provider value={value}>{children}</PaymentsContext.Provider>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
101
|
+
// Hook
|
|
102
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
export function usePaymentsContext(): PaymentsContextValue {
|
|
105
|
+
const context = useContext(PaymentsContext);
|
|
106
|
+
if (!context) {
|
|
107
|
+
throw new Error('usePaymentsContext must be used within PaymentsProvider');
|
|
108
|
+
}
|
|
109
|
+
return context;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
113
|
+
// Re-export types
|
|
114
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
export type {
|
|
117
|
+
PaginatedPaymentListList,
|
|
118
|
+
PaymentDetail,
|
|
119
|
+
PaymentList,
|
|
120
|
+
};
|
|
121
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main Payments Extension Provider
|
|
3
|
+
*
|
|
4
|
+
* Wraps all payments contexts with ExtensionProvider for proper registration
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use client';
|
|
8
|
+
|
|
9
|
+
import type { ReactNode } from 'react';
|
|
10
|
+
import { ExtensionProvider } from '@djangocfg/ext-base/hooks';
|
|
11
|
+
import { extensionConfig } from '../config';
|
|
12
|
+
import { RootPaymentsProvider } from './RootPaymentsContext';
|
|
13
|
+
import { PaymentsProvider } from './PaymentsContext';
|
|
14
|
+
import { BalancesProvider } from './BalancesContext';
|
|
15
|
+
import { CurrenciesProvider } from './CurrenciesContext';
|
|
16
|
+
import { OverviewProvider } from './OverviewContext';
|
|
17
|
+
|
|
18
|
+
interface PaymentsExtensionProviderProps {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Main provider for Payments extension
|
|
24
|
+
*
|
|
25
|
+
* Provides all payments contexts:
|
|
26
|
+
* - Root payments context (currencies)
|
|
27
|
+
* - Payments context (payment operations)
|
|
28
|
+
* - Balances context (balance management)
|
|
29
|
+
* - Currencies context (currency operations)
|
|
30
|
+
* - Overview context (payment statistics)
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <PaymentsExtensionProvider>
|
|
35
|
+
* <YourApp />
|
|
36
|
+
* </PaymentsExtensionProvider>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function PaymentsExtensionProvider({ children }: PaymentsExtensionProviderProps) {
|
|
40
|
+
return (
|
|
41
|
+
<ExtensionProvider metadata={extensionConfig}>
|
|
42
|
+
<RootPaymentsProvider>
|
|
43
|
+
<PaymentsProvider>
|
|
44
|
+
<BalancesProvider>
|
|
45
|
+
<CurrenciesProvider>
|
|
46
|
+
<OverviewProvider>
|
|
47
|
+
{children}
|
|
48
|
+
</OverviewProvider>
|
|
49
|
+
</CurrenciesProvider>
|
|
50
|
+
</BalancesProvider>
|
|
51
|
+
</PaymentsProvider>
|
|
52
|
+
</RootPaymentsProvider>
|
|
53
|
+
</ExtensionProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Payments Contexts
|
|
2
|
+
|
|
3
|
+
Декомпозированные контексты для модуля Payments.
|
|
4
|
+
|
|
5
|
+
## Структура
|
|
6
|
+
|
|
7
|
+
### PaymentsContext
|
|
8
|
+
**Файл:** `PaymentsContext.tsx`
|
|
9
|
+
**Назначение:** Управление платежами
|
|
10
|
+
|
|
11
|
+
**API:**
|
|
12
|
+
- `payments: PaginatedPaymentListList` - список платежей (пагинированный)
|
|
13
|
+
- `isLoadingPayments: boolean` - статус загрузки
|
|
14
|
+
- `refreshPayments()` - обновить список
|
|
15
|
+
- `getPayment(id)` - получить конкретный платеж
|
|
16
|
+
- `createPayment(data)` - создать платеж
|
|
17
|
+
- `cancelPayment(id, data)` - отменить платеж
|
|
18
|
+
- `checkPaymentStatus(id, data)` - проверить статус платежа
|
|
19
|
+
|
|
20
|
+
**Использование:**
|
|
21
|
+
```tsx
|
|
22
|
+
import { PaymentsProvider, usePaymentsContext } from '@djangocfg/layouts/contexts';
|
|
23
|
+
|
|
24
|
+
function PaymentsList() {
|
|
25
|
+
const { payments, isLoadingPayments, refreshPayments } = usePaymentsContext();
|
|
26
|
+
// ...
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
### BalancesContext
|
|
33
|
+
**Файл:** `BalancesContext.tsx`
|
|
34
|
+
**Назначение:** Управление балансами пользователей (read-only)
|
|
35
|
+
|
|
36
|
+
**API:**
|
|
37
|
+
- `balances: PaginatedUserBalanceList` - список балансов
|
|
38
|
+
- `isLoadingBalances: boolean` - статус загрузки
|
|
39
|
+
- `refreshBalances()` - обновить список
|
|
40
|
+
- `getBalance(id)` - получить конкретный баланс
|
|
41
|
+
- `getBalanceSummary()` - получить сводку по балансу
|
|
42
|
+
|
|
43
|
+
**Использование:**
|
|
44
|
+
```tsx
|
|
45
|
+
import { BalancesProvider, useBalancesContext } from '@djangocfg/layouts/contexts';
|
|
46
|
+
|
|
47
|
+
function Balance() {
|
|
48
|
+
const { balances, getBalanceSummary } = useBalancesContext();
|
|
49
|
+
// ...
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### CurrenciesContext
|
|
56
|
+
**Файл:** `CurrenciesContext.tsx`
|
|
57
|
+
**Назначение:** Управление валютами и курсами обмена (read-only)
|
|
58
|
+
|
|
59
|
+
**API:**
|
|
60
|
+
- `currencies: PaginatedCurrencyListList` - список валют
|
|
61
|
+
- `isLoadingCurrencies: boolean` - статус загрузки
|
|
62
|
+
- `refreshCurrencies()` - обновить список
|
|
63
|
+
- `getCurrency(id)` - получить конкретную валюту
|
|
64
|
+
- `getCurrencyRates(baseCurrency, currencies)` - получить курсы обмена
|
|
65
|
+
|
|
66
|
+
**Использование:**
|
|
67
|
+
```tsx
|
|
68
|
+
import { CurrenciesProvider, useCurrenciesContext } from '@djangocfg/layouts/contexts';
|
|
69
|
+
|
|
70
|
+
function CurrencySelector() {
|
|
71
|
+
const { currencies, getCurrencyRates } = useCurrenciesContext();
|
|
72
|
+
// ...
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### ApiKeysContext
|
|
79
|
+
**Файл:** `ApiKeysContext.tsx`
|
|
80
|
+
**Назначение:** Управление API ключами
|
|
81
|
+
|
|
82
|
+
**API:**
|
|
83
|
+
- `apiKeys: PaginatedAPIKeyListList` - список API ключей
|
|
84
|
+
- `isLoadingApiKeys: boolean` - статус загрузки
|
|
85
|
+
- `refreshApiKeys()` - обновить список
|
|
86
|
+
- `getApiKey(id)` - получить конкретный ключ
|
|
87
|
+
- `createApiKey(data)` - создать ключ
|
|
88
|
+
- `deleteApiKey(id)` - удалить ключ
|
|
89
|
+
|
|
90
|
+
**Использование:**
|
|
91
|
+
```tsx
|
|
92
|
+
import { ApiKeysProvider, useApiKeysContext } from '@djangocfg/layouts/contexts';
|
|
93
|
+
|
|
94
|
+
function ApiKeysList() {
|
|
95
|
+
const { apiKeys, createApiKey, deleteApiKey } = useApiKeysContext();
|
|
96
|
+
// ...
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### OverviewContext
|
|
103
|
+
**Файл:** `OverviewContext.tsx`
|
|
104
|
+
**Назначение:** Дашборд и метрики платежной системы (read-only)
|
|
105
|
+
|
|
106
|
+
**API:**
|
|
107
|
+
- `overview: PaymentsDashboardOverview` - общий обзор
|
|
108
|
+
- `metrics: PaymentsMetrics` - метрики
|
|
109
|
+
- `balanceOverview: BalanceOverview` - обзор баланса
|
|
110
|
+
- `apiKeysOverview: APIKeysOverview` - обзор API ключей
|
|
111
|
+
- `subscriptionOverview: SubscriptionOverview` - обзор подписок
|
|
112
|
+
- `chartData: PaymentsChartResponse` - данные для графиков
|
|
113
|
+
- `recentPayments: PaginatedRecentPaymentList` - последние платежи
|
|
114
|
+
- `recentTransactions: PaginatedRecentTransactionList` - последние транзакции
|
|
115
|
+
- `isLoadingOverview: boolean` - статус загрузки
|
|
116
|
+
- `refreshOverview()` - обновить все данные
|
|
117
|
+
|
|
118
|
+
**Использование:**
|
|
119
|
+
```tsx
|
|
120
|
+
import { OverviewProvider, useOverviewContext } from '@djangocfg/layouts/contexts';
|
|
121
|
+
|
|
122
|
+
function Dashboard() {
|
|
123
|
+
const { overview, metrics, chartData } = useOverviewContext();
|
|
124
|
+
// ...
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Композиция провайдеров
|
|
131
|
+
|
|
132
|
+
Если нужно использовать несколько контекстов:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import {
|
|
136
|
+
PaymentsProvider,
|
|
137
|
+
BalancesProvider,
|
|
138
|
+
OverviewProvider
|
|
139
|
+
} from '@djangocfg/layouts/contexts';
|
|
140
|
+
|
|
141
|
+
function PaymentsDashboard() {
|
|
142
|
+
return (
|
|
143
|
+
<OverviewProvider>
|
|
144
|
+
<PaymentsProvider>
|
|
145
|
+
<BalancesProvider>
|
|
146
|
+
<YourComponent />
|
|
147
|
+
</BalancesProvider>
|
|
148
|
+
</PaymentsProvider>
|
|
149
|
+
</OverviewProvider>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Миграция со старого PaymentsContext
|
|
157
|
+
|
|
158
|
+
**Было:**
|
|
159
|
+
```tsx
|
|
160
|
+
import { PaymentsProvider, usePaymentsContext } from '@djangocfg/layouts/contexts';
|
|
161
|
+
|
|
162
|
+
const { payments, balances, apiKeys } = usePaymentsContext();
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Стало:**
|
|
166
|
+
```tsx
|
|
167
|
+
import {
|
|
168
|
+
PaymentsProvider, usePaymentsContext,
|
|
169
|
+
BalancesProvider, useBalancesContext,
|
|
170
|
+
ApiKeysProvider, useApiKeysContext
|
|
171
|
+
} from '@djangocfg/layouts/contexts';
|
|
172
|
+
|
|
173
|
+
// В разных компонентах или комбинируя:
|
|
174
|
+
const { payments } = usePaymentsContext();
|
|
175
|
+
const { balances } = useBalancesContext();
|
|
176
|
+
const { apiKeys } = useApiKeysContext();
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Преимущества декомпозиции
|
|
182
|
+
|
|
183
|
+
1. **Модульность** - каждый контекст отвечает за свою область
|
|
184
|
+
2. **Производительность** - меньше ненужных ре-рендеров
|
|
185
|
+
3. **Гибкость** - можно использовать только нужные контексты
|
|
186
|
+
4. **Читаемость** - явное разделение зон ответственности
|
|
187
|
+
5. **Масштабируемость** - проще добавлять новую функциональность
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Не включенные сущности
|
|
192
|
+
|
|
193
|
+
В текущей декомпозиции **не включены** (могут быть добавлены позже):
|
|
194
|
+
- `SubscriptionsContext` - управление подписками (CRUD)
|
|
195
|
+
- `TransactionsContext` - история транзакций (read-only)
|
|
196
|
+
- `TariffsContext` - тарифные планы (read-only)
|
|
197
|
+
- `NetworksContext` - блокчейн сети (read-only)
|
|
198
|
+
- `AdminContext` - админ-функции (для админки)
|
|
199
|
+
|
|
200
|
+
Эти сущности можно добавить по мере необходимости, следуя той же структуре.
|
|
201
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, type ReactNode } from 'react';
|
|
4
|
+
import { apiPayments } from '../api';
|
|
5
|
+
import { usePaymentsCurrenciesList } from '../api/generated/ext_payments/_utils/hooks';
|
|
6
|
+
|
|
7
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
8
|
+
// Context Type
|
|
9
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
export interface RootPaymentsContextValue {
|
|
12
|
+
// Currencies - simplified to single endpoint
|
|
13
|
+
currencies: any | undefined;
|
|
14
|
+
isLoadingCurrencies: boolean;
|
|
15
|
+
currenciesError: Error | undefined;
|
|
16
|
+
refreshCurrencies: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
20
|
+
// Context
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
const RootPaymentsContext = createContext<RootPaymentsContextValue | undefined>(undefined);
|
|
24
|
+
|
|
25
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
26
|
+
// Provider
|
|
27
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export function RootPaymentsProvider({ children }: { children: ReactNode }) {
|
|
30
|
+
// Get currencies list from /cfg/payments/currencies/
|
|
31
|
+
// In v2.0, this returns all currencies with network info embedded
|
|
32
|
+
const {
|
|
33
|
+
data: currencies,
|
|
34
|
+
error: currenciesError,
|
|
35
|
+
isLoading: isLoadingCurrencies,
|
|
36
|
+
mutate: mutateCurrencies,
|
|
37
|
+
} = usePaymentsCurrenciesList(apiPayments);
|
|
38
|
+
|
|
39
|
+
const refreshCurrencies = async () => {
|
|
40
|
+
await mutateCurrencies();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const value: RootPaymentsContextValue = {
|
|
44
|
+
currencies,
|
|
45
|
+
isLoadingCurrencies,
|
|
46
|
+
currenciesError,
|
|
47
|
+
refreshCurrencies,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<RootPaymentsContext.Provider value={value}>{children}</RootPaymentsContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
56
|
+
// Hook
|
|
57
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
export function useRootPaymentsContext(): RootPaymentsContextValue {
|
|
60
|
+
const context = useContext(RootPaymentsContext);
|
|
61
|
+
if (!context) {
|
|
62
|
+
throw new Error('useRootPaymentsContext must be used within RootPaymentsProvider');
|
|
63
|
+
}
|
|
64
|
+
return context;
|
|
65
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Payments
|
|
2
|
+
export {
|
|
3
|
+
PaymentsProvider,
|
|
4
|
+
usePaymentsContext
|
|
5
|
+
} from './PaymentsContext';
|
|
6
|
+
export type {
|
|
7
|
+
PaymentsContextValue,
|
|
8
|
+
} from './PaymentsContext';
|
|
9
|
+
|
|
10
|
+
// Balances
|
|
11
|
+
export {
|
|
12
|
+
BalancesProvider,
|
|
13
|
+
useBalancesContext
|
|
14
|
+
} from './BalancesContext';
|
|
15
|
+
export type {
|
|
16
|
+
BalancesContextValue,
|
|
17
|
+
} from './BalancesContext';
|
|
18
|
+
|
|
19
|
+
// Currencies
|
|
20
|
+
export {
|
|
21
|
+
CurrenciesProvider,
|
|
22
|
+
useCurrenciesContext
|
|
23
|
+
} from './CurrenciesContext';
|
|
24
|
+
export type {
|
|
25
|
+
CurrenciesContextValue,
|
|
26
|
+
} from './CurrenciesContext';
|
|
27
|
+
|
|
28
|
+
// Overview
|
|
29
|
+
export {
|
|
30
|
+
OverviewProvider,
|
|
31
|
+
useOverviewContext
|
|
32
|
+
} from './OverviewContext';
|
|
33
|
+
export type {
|
|
34
|
+
OverviewContextValue,
|
|
35
|
+
} from './OverviewContext';
|
|
36
|
+
|
|
37
|
+
// Root Payments (Global)
|
|
38
|
+
export {
|
|
39
|
+
RootPaymentsProvider,
|
|
40
|
+
useRootPaymentsContext
|
|
41
|
+
} from './RootPaymentsContext';
|
|
42
|
+
export type {
|
|
43
|
+
RootPaymentsContextValue,
|
|
44
|
+
} from './RootPaymentsContext';
|
|
45
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payments Types
|
|
3
|
+
* Centralized type definitions for payments contexts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
usePaymentsPaymentsList,
|
|
8
|
+
usePaymentsPaymentsRetrieve,
|
|
9
|
+
usePaymentsBalanceRetrieve,
|
|
10
|
+
usePaymentsCurrenciesList,
|
|
11
|
+
usePaymentsTransactionsList,
|
|
12
|
+
} from '../api/generated/ext_payments/_utils/hooks';
|
|
13
|
+
|
|
14
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
15
|
+
// Payments Types
|
|
16
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export type PaginatedPaymentListList = NonNullable<Awaited<ReturnType<typeof usePaymentsPaymentsList>>['data']>;
|
|
19
|
+
export type PaymentDetail = NonNullable<Awaited<ReturnType<typeof usePaymentsPaymentsRetrieve>>['data']>;
|
|
20
|
+
export type PaymentList = NonNullable<Awaited<ReturnType<typeof usePaymentsPaymentsList>>['data']> extends { results: infer T } ? T extends Array<infer U> ? U : never : never;
|
|
21
|
+
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// Balance Types
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
export type Balance = NonNullable<Awaited<ReturnType<typeof usePaymentsBalanceRetrieve>>['data']>;
|
|
27
|
+
|
|
28
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
29
|
+
// Currency Types
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
export type Currency = NonNullable<Awaited<ReturnType<typeof usePaymentsCurrenciesList>>['data']> extends { results: infer T } ? T extends Array<infer U> ? U : never : never;
|
|
33
|
+
export type PaginatedCurrencyList = NonNullable<Awaited<ReturnType<typeof usePaymentsCurrenciesList>>['data']>;
|
|
34
|
+
|
|
35
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
36
|
+
// Transaction Types
|
|
37
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
export type Transaction = NonNullable<Awaited<ReturnType<typeof usePaymentsTransactionsList>>['data']> extends { results: infer T } ? T extends Array<infer U> ? U : never : never;
|
|
40
|
+
export type PaginatedTransactionList = NonNullable<Awaited<ReturnType<typeof usePaymentsTransactionsList>>['data']>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @djangocfg/ext-payments/hooks
|
|
5
|
+
*
|
|
6
|
+
* React hooks for payments extension.
|
|
7
|
+
* Use this entry point in client components.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Re-export everything from main entry (server-safe code)
|
|
11
|
+
export * from '../index';
|
|
12
|
+
|
|
13
|
+
// SWR hooks from generated API
|
|
14
|
+
export * from '../api/generated/ext_payments/_utils/hooks';
|
|
15
|
+
|
|
16
|
+
// Payments contexts (from local contexts)
|
|
17
|
+
export * from '../contexts';
|
|
18
|
+
|
|
19
|
+
// Layout components (they use hooks internally)
|
|
20
|
+
export * from '../layouts/PaymentsLayout/components';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @djangocfg/ext-payments
|
|
3
|
+
*
|
|
4
|
+
* Payments system extension.
|
|
5
|
+
* This entry point is server-safe (no SWR/React hooks).
|
|
6
|
+
*
|
|
7
|
+
* For React hooks, import from '@djangocfg/ext-payments/hooks'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// API client (server-safe)
|
|
11
|
+
export * from './api/generated/ext_payments';
|
|
12
|
+
export { API } from './api/generated/ext_payments';
|
|
13
|
+
export { apiPayments } from './api';
|
|
14
|
+
|
|
15
|
+
// Layout components
|
|
16
|
+
export { PaymentsLayout } from './layouts/PaymentsLayout';
|
|
17
|
+
export type { PaymentsLayoutProps } from './layouts/PaymentsLayout/PaymentsLayout';
|
|
18
|
+
|
|
19
|
+
// Events
|
|
20
|
+
export * from './layouts/PaymentsLayout/events';
|
|
21
|
+
|
|
22
|
+
// Types
|
|
23
|
+
export type { PaymentTab } from './layouts/PaymentsLayout/types';
|
|
24
|
+
|
|
25
|
+
// Re-export API types for convenience
|
|
26
|
+
export type {
|
|
27
|
+
Balance,
|
|
28
|
+
Currency,
|
|
29
|
+
PaymentList,
|
|
30
|
+
PaymentDetail,
|
|
31
|
+
Transaction,
|
|
32
|
+
PaginatedPaymentListList,
|
|
33
|
+
} from './api/generated/ext_payments/_utils/schemas';
|
|
34
|
+
|
|
35
|
+
// Note: Hooks are NOT exported here to keep this bundle server-safe
|
|
36
|
+
// Use: import { usePaymentsList } from '@djangocfg/ext-payments/hooks'
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Payments Layout (v2.0 - Simplified)
|
|
4
|
+
*
|
|
5
|
+
* Simplified layout with 3 tabs: Overview, Payments, Transactions
|
|
6
|
+
* Removed: API Keys, Tariffs (deprecated in v2.0)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use client';
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import {
|
|
13
|
+
PaymentsProvider,
|
|
14
|
+
OverviewProvider,
|
|
15
|
+
RootPaymentsProvider,
|
|
16
|
+
} from '../../contexts';
|
|
17
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@djangocfg/ui-nextjs';
|
|
18
|
+
import { Wallet, CreditCard, History } from 'lucide-react';
|
|
19
|
+
import { OverviewView } from './views/overview';
|
|
20
|
+
import { PaymentsView } from './views/payments';
|
|
21
|
+
import { TransactionsView } from './views/transactions';
|
|
22
|
+
import { CreatePaymentDialog, PaymentDetailsDialog } from './components';
|
|
23
|
+
|
|
24
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
25
|
+
// Payments Layout
|
|
26
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
export interface PaymentsLayoutProps {
|
|
29
|
+
children?: React.ReactNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const PaymentsLayout: React.FC<PaymentsLayoutProps> = () => {
|
|
33
|
+
return (
|
|
34
|
+
<RootPaymentsProvider>
|
|
35
|
+
<div className="h-full p-6 space-y-6">
|
|
36
|
+
{/* Page Header */}
|
|
37
|
+
<div>
|
|
38
|
+
<h1 className="text-3xl font-bold tracking-tight">Payments</h1>
|
|
39
|
+
<p className="text-muted-foreground">
|
|
40
|
+
Manage your payments, balance, and transaction history
|
|
41
|
+
</p>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
{/* Main Content with Tabs */}
|
|
45
|
+
<Tabs defaultValue="overview" className="space-y-6">
|
|
46
|
+
<TabsList className="inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground">
|
|
47
|
+
<TabsTrigger value="overview" className="inline-flex items-center gap-2 px-3 py-1.5">
|
|
48
|
+
<Wallet className="h-4 w-4" />
|
|
49
|
+
<span className="hidden sm:inline">Overview</span>
|
|
50
|
+
</TabsTrigger>
|
|
51
|
+
<TabsTrigger value="payments" className="inline-flex items-center gap-2 px-3 py-1.5">
|
|
52
|
+
<CreditCard className="h-4 w-4" />
|
|
53
|
+
<span className="hidden sm:inline">Payments</span>
|
|
54
|
+
</TabsTrigger>
|
|
55
|
+
<TabsTrigger value="transactions" className="inline-flex items-center gap-2 px-3 py-1.5">
|
|
56
|
+
<History className="h-4 w-4" />
|
|
57
|
+
<span className="hidden sm:inline">Transactions</span>
|
|
58
|
+
</TabsTrigger>
|
|
59
|
+
</TabsList>
|
|
60
|
+
|
|
61
|
+
{/* Overview Tab - Balance + Recent Payments */}
|
|
62
|
+
<TabsContent value="overview" className="space-y-6">
|
|
63
|
+
<OverviewProvider>
|
|
64
|
+
<PaymentsProvider>
|
|
65
|
+
<OverviewView />
|
|
66
|
+
<CreatePaymentDialog />
|
|
67
|
+
</PaymentsProvider>
|
|
68
|
+
</OverviewProvider>
|
|
69
|
+
</TabsContent>
|
|
70
|
+
|
|
71
|
+
{/* Payments Tab - Full Payment List */}
|
|
72
|
+
<TabsContent value="payments" className="space-y-6">
|
|
73
|
+
<PaymentsProvider>
|
|
74
|
+
<PaymentsView />
|
|
75
|
+
<CreatePaymentDialog />
|
|
76
|
+
</PaymentsProvider>
|
|
77
|
+
</TabsContent>
|
|
78
|
+
|
|
79
|
+
{/* Transactions Tab - Transaction History */}
|
|
80
|
+
<TabsContent value="transactions" className="space-y-6">
|
|
81
|
+
<OverviewProvider>
|
|
82
|
+
<TransactionsView />
|
|
83
|
+
</OverviewProvider>
|
|
84
|
+
</TabsContent>
|
|
85
|
+
</Tabs>
|
|
86
|
+
|
|
87
|
+
{/* Global Payment Details Dialog */}
|
|
88
|
+
<PaymentDetailsDialog />
|
|
89
|
+
</div>
|
|
90
|
+
</RootPaymentsProvider>
|
|
91
|
+
);
|
|
92
|
+
};
|