mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
- Remove legacy .eslintrc.cjs and .eslintignore - Add eslint.config.js with flat config, security rules (no-eval, no-implied-eval, no-new-func, no-script-url) - Add .prettierrc and .prettierignore - Format entire codebase with prettier
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import axios, { AxiosError } from 'axios';
|
|
|
|
export interface MiniappCreatePaymentPayload {
|
|
initData: string;
|
|
method: string;
|
|
amountKopeks?: number | null;
|
|
option?: string | null;
|
|
}
|
|
|
|
export interface MiniappCreatePaymentResponse {
|
|
payment_url: string;
|
|
amount_kopeks?: number;
|
|
extra?: Record<string, unknown>;
|
|
}
|
|
|
|
export const miniappApi = {
|
|
// Create payment inside Telegram Mini App (same flow as miniapp/index.html)
|
|
createPayment: async (
|
|
payload: MiniappCreatePaymentPayload,
|
|
): Promise<MiniappCreatePaymentResponse> => {
|
|
try {
|
|
const response = await axios.post<MiniappCreatePaymentResponse>(
|
|
'/miniapp/payments/create',
|
|
{
|
|
initData: payload.initData || '',
|
|
method: payload.method,
|
|
amountKopeks: payload.amountKopeks ?? null,
|
|
option: payload.option ?? null,
|
|
},
|
|
{
|
|
headers: { 'Content-Type': 'application/json' },
|
|
},
|
|
);
|
|
return response.data;
|
|
} catch (error) {
|
|
const axiosError = error as AxiosError<{ detail?: string; message?: string }>;
|
|
const message =
|
|
axiosError.response?.data?.detail ||
|
|
axiosError.response?.data?.message ||
|
|
'Failed to create payment';
|
|
throw new Error(message);
|
|
}
|
|
},
|
|
};
|