fix: wallet API
This commit is contained in:
parent
bc6554d56e
commit
04a376bdb9
@ -1,32 +1,48 @@
|
|||||||
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",
|
||||||
amount: 15020,
|
amount: 15020,
|
||||||
currency: "RUB",
|
currency: "RUB",
|
||||||
bankCard: {
|
bankCard: {
|
||||||
number: "RUB",
|
number: "RUB",
|
||||||
expiryYear: "2021",
|
expiryYear: "2021",
|
||||||
expiryMonth: "05",
|
expiryMonth: "05",
|
||||||
csc: "05",
|
csc: "05",
|
||||||
cardholder: "IVAN IVANOV",
|
cardholder: "IVAN IVANOV",
|
||||||
},
|
},
|
||||||
phoneNumber: "79000000000",
|
phoneNumber: "79000000000",
|
||||||
login: "login_test",
|
login: "login_test",
|
||||||
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
|
||||||
url: apiUrl + "/wallet",
|
): Promise<[SendPaymentResponse | null, string?]> {
|
||||||
contentType: true,
|
try {
|
||||||
method: "POST",
|
const sendPaymentResponse = await makeRequest<
|
||||||
useToken: true,
|
SendPaymentRequest,
|
||||||
withCredentials: false,
|
SendPaymentResponse
|
||||||
body
|
>({
|
||||||
|
url: apiUrl + "/wallet",
|
||||||
|
contentType: true,
|
||||||
|
method: "POST",
|
||||||
|
useToken: true,
|
||||||
|
withCredentials: false,
|
||||||
|
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