fix: wallet API
This commit is contained in:
parent
bc6554d56e
commit
04a376bdb9
@ -1,8 +1,11 @@
|
|||||||
import { makeRequest } from "@frontend/kitui";
|
import { makeRequest } from "@frontend/kitui";
|
||||||
import { SendPaymentRequest, SendPaymentResponse } from "@root/model/wallet";
|
import { SendPaymentRequest, SendPaymentResponse } from "@root/model/wallet";
|
||||||
|
import { parseAxiosError } from "@root/utils/parse-error";
|
||||||
|
|
||||||
|
const apiUrl =
|
||||||
const apiUrl = process.env.NODE_ENV === "production" ? "/customer" : "https://hub.pena.digital/customer";
|
process.env.NODE_ENV === "production"
|
||||||
|
? "/customer"
|
||||||
|
: "https://hub.pena.digital/customer";
|
||||||
|
|
||||||
const testPaymentBody: SendPaymentRequest = {
|
const testPaymentBody: SendPaymentRequest = {
|
||||||
type: "bankCard",
|
type: "bankCard",
|
||||||
@ -20,13 +23,26 @@ const testPaymentBody: SendPaymentRequest = {
|
|||||||
returnUrl: window.location.origin + "/wallet",
|
returnUrl: window.location.origin + "/wallet",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sendPayment(body: SendPaymentRequest = testPaymentBody) {
|
export async function sendPayment(
|
||||||
return makeRequest<SendPaymentRequest, SendPaymentResponse>({
|
body: SendPaymentRequest = testPaymentBody
|
||||||
|
): Promise<[SendPaymentResponse | null, string?]> {
|
||||||
|
try {
|
||||||
|
const sendPaymentResponse = await makeRequest<
|
||||||
|
SendPaymentRequest,
|
||||||
|
SendPaymentResponse
|
||||||
|
>({
|
||||||
url: apiUrl + "/wallet",
|
url: apiUrl + "/wallet",
|
||||||
contentType: true,
|
contentType: true,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
useToken: true,
|
useToken: true,
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
body
|
body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return [sendPaymentResponse];
|
||||||
|
} catch (nativeError) {
|
||||||
|
const [error] = parseAxiosError(nativeError);
|
||||||
|
|
||||||
|
return [null, `Ошибка оплаты. ${error}`];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,16 +49,17 @@ export default function Payment() {
|
|||||||
|
|
||||||
const paymentValue = parseFloat(paymentValueField) * 100;
|
const paymentValue = parseFloat(paymentValueField) * 100;
|
||||||
|
|
||||||
function handleChoosePaymentClick() {
|
async function handleChoosePaymentClick() {
|
||||||
if (Number(paymentValueField) !== 0) {
|
if (Number(paymentValueField) !== 0) {
|
||||||
sendPayment()
|
const [sendPaymentResponse, sendPaymentError] = await sendPayment();
|
||||||
.then((result) => {
|
|
||||||
setPaymentLink(result.link);
|
if (sendPaymentError) {
|
||||||
})
|
return enqueueSnackbar(sendPaymentError);
|
||||||
.catch((error) => {
|
}
|
||||||
const message = getMessageFromFetchError(error);
|
|
||||||
if (message) enqueueSnackbar(message);
|
if (sendPaymentResponse) {
|
||||||
});
|
setPaymentLink(sendPaymentResponse.link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user