2023-07-07 13:53:08 +00:00
|
|
|
import { makeRequest } from "@frontend/kitui";
|
|
|
|
import { SendPaymentRequest, SendPaymentResponse } from "@root/model/wallet";
|
2023-08-30 14:02:56 +00:00
|
|
|
import { parseAxiosError } from "@root/utils/parse-error";
|
2023-07-07 13:53:08 +00:00
|
|
|
|
2023-08-30 14:02:56 +00:00
|
|
|
const apiUrl =
|
|
|
|
process.env.NODE_ENV === "production"
|
|
|
|
? "/customer"
|
|
|
|
: "https://hub.pena.digital/customer";
|
2023-07-07 13:53:08 +00:00
|
|
|
|
|
|
|
const testPaymentBody: SendPaymentRequest = {
|
2023-08-30 14:02:56 +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
|
|
|
};
|
|
|
|
|
2023-08-30 14:02:56 +00:00
|
|
|
export async function sendPayment(
|
|
|
|
body: SendPaymentRequest = testPaymentBody
|
|
|
|
): Promise<[SendPaymentResponse | null, string?]> {
|
|
|
|
try {
|
|
|
|
const sendPaymentResponse = await makeRequest<
|
|
|
|
SendPaymentRequest,
|
|
|
|
SendPaymentResponse
|
|
|
|
>({
|
|
|
|
url: apiUrl + "/wallet",
|
|
|
|
contentType: true,
|
|
|
|
method: "POST",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: false,
|
|
|
|
body,
|
2023-07-07 13:53:08 +00:00
|
|
|
});
|
2023-08-30 14:02:56 +00:00
|
|
|
|
|
|
|
return [sendPaymentResponse];
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
|
|
|
|
return [null, `Ошибка оплаты. ${error}`];
|
|
|
|
}
|
2023-07-22 10:38:45 +00:00
|
|
|
}
|