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