front-hub/src/api/wallet.ts

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-02-14 14:22:12 +00:00
import { makeRequest } from "@frontend/kitui";
import { SendPaymentRequest, SendPaymentResponse } from "@root/model/wallet";
import { parseAxiosError } from "@root/utils/parse-error";
2023-07-07 13:53:08 +00:00
2024-02-14 14:22:12 +00:00
const apiUrl = process.env.REACT_APP_DOMAIN + "/customer";
2023-07-07 13:53:08 +00:00
const testPaymentBody: SendPaymentRequest = {
2024-02-14 14:22:12 +00:00
type: "bankCard",
amount: 15020,
currency: "RUB",
bankCard: {
number: "RUB",
expiryYear: "2021",
expiryMonth: "05",
csc: "05",
cardholder: "IVAN IVANOV",
},
phoneNumber: "79000000000",
login: "login_test",
returnUrl: window.location.origin + "/wallet",
};
2023-07-07 13:53:08 +00:00
2024-02-14 14:22:12 +00:00
export async function sendPayment({
body = testPaymentBody,
fromSquiz = false,
}: {
body?: SendPaymentRequest;
fromSquiz: boolean;
}): Promise<[SendPaymentResponse | null, string?]> {
if (fromSquiz) body.returnUrl = "squiz.pena.digital/list?action=fromhub";
try {
const sendPaymentResponse = await makeRequest<
2023-08-30 14:02:56 +00:00
SendPaymentRequest,
SendPaymentResponse
>({
2024-02-14 14:22:12 +00:00
url: apiUrl + "/wallet",
contentType: true,
method: "POST",
useToken: true,
withCredentials: false,
body,
});
return [sendPaymentResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Ошибка оплаты. ${error}`];
}
2023-07-22 10:38:45 +00:00
}
2024-02-14 14:22:12 +00:00
2024-02-23 00:02:22 +00:00
export const sendRSPayment = async (money: number): Promise<string | null> => {
2024-02-14 14:22:12 +00:00
try {
await makeRequest<unknown, string>({
2024-02-14 14:22:12 +00:00
url: apiUrl + "/wallet/rspay",
method: "POST",
useToken: true,
body: {money: money},
2024-02-14 14:22:12 +00:00
withCredentials: false,
});
return null;
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return `Ошибка оплаты. ${error}`;
}
};