взятие недлстающей суммы для оплаты на хабе из ответа ошибки
This commit is contained in:
parent
a40b9ee0c8
commit
f08bd29ab8
@ -1,29 +1,29 @@
|
|||||||
import { Typography, Box } from "@mui/material";
|
import { Typography, Box } from "@mui/material";
|
||||||
import { useUserStore } from "@root/user"
|
import { useUserStore } from "@root/user";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
export const InfoPrivilege = () => {
|
export const InfoPrivilege = () => {
|
||||||
const user = useUserStore();
|
const user = useUserStore();
|
||||||
console.log(user)
|
console.log(user);
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Link to="/list">К списку квизов</Link>
|
<Link to="/list">К списку квизов</Link>
|
||||||
{Object.values(user?.userAccount?.privileges || {}).map((privilege) => {
|
{Object.values(user?.userAccount?.privileges || {}).map((privilege) => {
|
||||||
console.log(privilege)
|
console.log(privilege);
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
border: "1px solid",
|
border: "1px solid",
|
||||||
margin: "0 10px",
|
margin: "0 10px",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "space-around",
|
justifyContent: "space-around",
|
||||||
padding: "5px 0",
|
padding: "5px 0",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography>{privilege?.privilege_name}</Typography>
|
<Typography>{privilege?.privilege_name}</Typography>
|
||||||
<Typography>{privilege?.amount}</Typography>
|
<Typography>{privilege?.amount}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
@ -121,35 +121,33 @@ function TariffPage() {
|
|||||||
url: process.env.REACT_APP_DOMAIN + `/customer/cart?id=${id}`,
|
url: process.env.REACT_APP_DOMAIN + `/customer/cart?id=${id}`,
|
||||||
});
|
});
|
||||||
//Если нам хватает денежек - покупаем тариф
|
//Если нам хватает денежек - покупаем тариф
|
||||||
if (price * 100 <= cashCop) {
|
|
||||||
try {
|
|
||||||
const data = await makeRequest({
|
|
||||||
method: "POST",
|
|
||||||
url: process.env.REACT_APP_DOMAIN + "/customer/cart/pay",
|
|
||||||
});
|
|
||||||
console.log(data);
|
|
||||||
setCash(
|
|
||||||
currencyFormatter.format(Number(data.wallet.cash) / 100),
|
|
||||||
Number(data.wallet.cash),
|
|
||||||
Number(data.wallet.cash) / 100,
|
|
||||||
);
|
|
||||||
enqueueSnackbar("Тариф успешно приобретён");
|
|
||||||
} catch (e) {
|
|
||||||
enqueueSnackbar("Произошла ошибка. Попробуйте позже");
|
|
||||||
}
|
|
||||||
//Развращаем товары в корзину
|
|
||||||
inCart();
|
|
||||||
} else {
|
|
||||||
//Деняк не хватило
|
|
||||||
// history.pushState({}, null, "https://hub.pena.digital/wallet?action=squizpay");
|
|
||||||
|
|
||||||
var link = document.createElement("a");
|
try {
|
||||||
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${Math.round(
|
const data = await makeRequest({
|
||||||
price * 100 - cashCop,
|
method: "POST",
|
||||||
)}&data=${token}&userid=${userId}`;
|
url: process.env.REACT_APP_DOMAIN + "/customer/cart/pay",
|
||||||
document.body.appendChild(link);
|
});
|
||||||
link.click();
|
console.log(data);
|
||||||
|
setCash(
|
||||||
|
currencyFormatter.format(Number(data.wallet.cash) / 100),
|
||||||
|
Number(data.wallet.cash),
|
||||||
|
Number(data.wallet.cash) / 100,
|
||||||
|
);
|
||||||
|
enqueueSnackbar("Тариф успешно приобретён");
|
||||||
|
} catch (e) {
|
||||||
|
//если денег не хватило
|
||||||
|
if (e.response.data.message.includes("insufficient funds")) {
|
||||||
|
let cashDif = Number(e.response.data.message.split(":")[1]);
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.href = `https://${isTestServer ? "s" : ""}hub.pena.digital/quizpayment?action=squizpay&dif=${cashDif}&data=${token}&userid=${userId}`;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
}
|
||||||
|
//другая ошибка
|
||||||
|
enqueueSnackbar("Произошла ошибка. Попробуйте позже");
|
||||||
}
|
}
|
||||||
|
//Развращаем товары в корзину
|
||||||
|
inCart();
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredTariffs = tariffs.filter((tariff) => {
|
const filteredTariffs = tariffs.filter((tariff) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user