This commit is contained in:
2026-05-22 22:34:00 +03:00
parent fac5e2ea5e
commit 52a0b7f3c7
14 changed files with 823 additions and 158 deletions

View File

@@ -107,3 +107,61 @@ export function createOrder(payload: CreateOrderPayload): Promise<OrderResult> {
body: JSON.stringify(payload),
}, true)
}
export type OrderStatus = 'pending' | 'completed' | 'cancelled' | 'failed'
export interface Order {
id: string
created_at: string
updated_at: string
user_id: string
usdt_amount: string
usdt_exchange_rate: string
gas_fee: string
total_price: string
service_fee: string
status: OrderStatus
client_payment_id: string
itpay_payment_qr_url_desktop: string
itpay_payment_qr_url_android: string
itpay_payment_qr_url_ios: string
itpay_payment_qr_image_desktop: string
itpay_payment_qr_image_android: string
itpay_payment_qr_image_ios: string
itpay_id: string
itpay_qr_id: string
itpay_amount: string
itpay_created_at: string
}
export interface Payment {
id: string
created_at: string
updated_at: string
user_id: string
order_id: string
status: OrderStatus
receipt_cloudekassir_id: string
receipt_cloudekassir_link: string
itpay_payment_id: string
itpay_paid_amount: string
transaction_id: string
web3_transaction_hash: string
paid_at: string
expired_date: string
}
export interface OrderWithPayment {
order: Order
payment: Payment
}
export interface OrdersResponse {
orders: OrderWithPayment[]
}
export const ORDERS_LIMIT = 20
export function getOrders(offset: number, limit: number = ORDERS_LIMIT): Promise<OrdersResponse> {
return doPaymentRequest(`/payment/orders?offset=${offset}&limit=${limit}`, {}, true)
}

View File

@@ -0,0 +1,15 @@
import { useInfiniteQuery } from '@tanstack/react-query'
import { getOrders, ORDERS_LIMIT } from '../api/paymentApi'
export function useOrders() {
return useInfiniteQuery({
queryKey: ['payment', 'orders'],
queryFn: ({ pageParam }) => getOrders(pageParam as number),
initialPageParam: 0,
getNextPageParam: (lastPage, allPages) => {
if (lastPage.orders.length < ORDERS_LIMIT) return undefined
return allPages.length * ORDERS_LIMIT
},
staleTime: 30_000,
})
}

View File

@@ -2,4 +2,5 @@ export { usePaymentConfig } from './hooks/usePaymentConfig'
export { usePaymentQuote } from './hooks/usePaymentQuote'
export { usePaymentQuoteByRub } from './hooks/usePaymentQuoteByRub'
export { useCreateOrder } from './hooks/useCreateOrder'
export type { PaymentConfig, PaymentQuote, CreateOrderPayload, OrderResult } from './api/paymentApi'
export { useOrders } from './hooks/useOrders'
export type { PaymentConfig, PaymentQuote, CreateOrderPayload, OrderResult, Order, Payment, OrderWithPayment, OrderStatus } from './api/paymentApi'