почему не уходят поля cardName: response.cardName,
cardType: response.cardType,
trxDate: response.trxDate,
trxTime: response.trxTime,
termNum: response.termNum,
authCode: response.authCode,
rrn: response.rrn,
merchantTSN: response.merchantTSN,
merchantBatchNum: response.merchantBatchNum,
clientCard: response.clientCard,
clientExpireDate: response.clientExpiryDate,
hash: response.hash,
ownCard: response.ownCard,
import { axiosInstance, paymentApi } from '@/shared/api/axiosInstance.ts';
import { reportError } from '@/entities/error';
import { formatErrorText } from '@/shared/utils';
import { bool } from 'yup';
export interface PaymentItem {
title: string;
count: number;
price: number;
}
export interface PaymentData {
items: PaymentItem[];
phoneOrEmail: string;
payStatus: boolean;
}
export interface PaymentQrResponse {
ceid: string;
amount: string;
typePlatform?: string;
ya_client_id?: string;
payment_id: string;
uid: string;
url: string;
sbp: string;
}
export interface GetPaymentQrParams {
ceid: string;
amount: number;
typePlatform?: string;
ya_client_id?: string;
}
export interface PaymentQrApiPayload {
ceid: string;
amount: string;
typePlatform?: string;
ya_client_id?: string;
}
export interface SuccessfulPayment {
ceid: string;
terminalId: number;
price: number;
}
export interface StatusSBP {
data: {
uid: string;
status: string;
amount: string;
};
}
export interface PaymentResponse {
success: boolean;
}
export interface RegisterCardPayload {
ceid: string;
sum: number;
dateTime: string;
statusCheck: boolean;
requestId: string;
amountClear: number;
amount: number;
cardName: string;
cardType: string;
trxDate: string;
trxTime: string;
termNum: string;
authCode: string;
rrn: string;
merchantTSN: string;
merchantBatchNum: string;
clientCard: string;
clientExpireDate: string;
hash: string;
ownCard: number;
}
interface PaymentCardResponse {
result: string;
description: string;
amountClear: string;
amount: string;
cardName: string;
cardType: string;
trxDate: string;
trxTime: string;
termNum: string;
merchNum: string;
authCode: string;
rrn: string;
merchantTSN: string;
merchantBatchNum: string;
clientCard: string;
clientExpiryDate: string;
hash: string;
ownCard: number;
loyaltyIdentifier: string;
errorData: string;
}
interface CheckClient {
ceid: string;
sum: number;
dateTime: string;
statusCheck: boolean;
requestId: string;
}
export async function paymentEvent(
paymentData: PaymentData
): Promise {
try {
const response = await paymentApi.post(
'/',
paymentData,
{
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
}
);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Payment event failed: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function checkId(ceid: string): Promise {
try {
const response = await axiosInstance.post<{ status: boolean }>(
'/api/eos/checksId',
{ ceid }
);
return response.data.status;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Client check failed for CEID ${ceid}: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function checkClient(
ceid: string,
sum: number
): Promise {
try {
const now = new Date();
const dateTime = ${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}T${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')};
const response = await axiosInstance.post<CheckClient>(
'/api/eos/checkCard',
{
ceid,
sum,
dateTime,
}
);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Client check failed for CEID ${ceid}: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function changeKKTStatus(id: number): Promise {
try {
const response = await axiosInstance.post<{
status: string;
details: string;
}>('/api/terminals/edit', { id, kkt: false });
return response.data.status === 'success';
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
KKT status update failed for terminal ${id}: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function getPaymentQr(
params: GetPaymentQrParams
): Promise {
try {
const payload: PaymentQrApiPayload = {
ceid: params.ceid,
amount: String(params.amount),
typePlatform: params.typePlatform || 'terminal',
...(params.ya_client_id && { ya_client_id: params.ya_client_id }),
};
const response = await axiosInstance.post<PaymentQrResponse>(
'/api/eos/paymentSBP',
payload
);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
QR-code generation failed: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function sendPaymentConfirmation(
params: SuccessfulPayment
): Promise {
try {
const response = await axiosInstance.post(
'/api/payments',
params
);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Payment confirmation failed: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function checkStatusSBP(uid: string): Promise {
try {
const response = await axiosInstance.post(
'/api/eos/checkSBP',
{
uid,
},
{ skipGlobalLoader: true }
);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Payment confirmation failed: ${error instanceof Error ? error.message : String(error)}
);
}
}
export async function registerCard(payload: RegisterCardPayload) {
try {
const response = await axiosInstance.post('/api/eos/registerCard', payload);
return response.data;
} catch (error) {
await reportError(formatErrorText(error));
throw new Error(
Register card failed: ${error instanceof Error ? error.message : String(error)}
);
}
}