feat: похуйу
This commit is contained in:
@@ -25,7 +25,7 @@ export interface PaymentQuote {
|
||||
|
||||
export async function getPaymentConfig(): Promise<PaymentConfig> {
|
||||
const csrf = await getCsrfToken()
|
||||
const res = await fetch(`${PAYMENT_API_URL}/config`, {
|
||||
const res = await fetch(`${PAYMENT_API_URL}/payment/config`, {
|
||||
credentials: 'include',
|
||||
headers: { 'X-CSRF-Token': csrf },
|
||||
})
|
||||
@@ -44,3 +44,53 @@ export async function getPaymentQuote(usdtAmount: number): Promise<PaymentQuote>
|
||||
if (!res.ok) throw data
|
||||
return data
|
||||
}
|
||||
|
||||
export interface CreateOrderPayload {
|
||||
usdt_amount: number
|
||||
usdt_exchange_rate: number
|
||||
gas_fee: number
|
||||
total_price: number
|
||||
}
|
||||
|
||||
export interface OrderResult {
|
||||
status_code: number
|
||||
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: string
|
||||
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 async function createOrder(payload: CreateOrderPayload): Promise<OrderResult> {
|
||||
const csrf = await getCsrfToken()
|
||||
const res = await fetch(`${PAYMENT_API_URL}/order/create`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrf,
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw data
|
||||
return data
|
||||
}
|
||||
|
||||
12
src/features/payment/hooks/useCreateOrder.ts
Normal file
12
src/features/payment/hooks/useCreateOrder.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { createOrder } from '../api/paymentApi'
|
||||
|
||||
export function useCreateOrder() {
|
||||
return useMutation({
|
||||
mutationFn: createOrder,
|
||||
onSuccess: (data) => {
|
||||
const url = data.order.itpay_payment_qr_url_desktop
|
||||
if (url) window.location.href = url
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { usePaymentConfig } from './hooks/usePaymentConfig'
|
||||
export { usePaymentQuote } from './hooks/usePaymentQuote'
|
||||
export type { PaymentConfig, PaymentQuote } from './api/paymentApi'
|
||||
export { useCreateOrder } from './hooks/useCreateOrder'
|
||||
export type { PaymentConfig, PaymentQuote, CreateOrderPayload, OrderResult } from './api/paymentApi'
|
||||
|
||||
Reference in New Issue
Block a user