add pay cart polling after payment
This commit is contained in:
parent
bdcac81cf2
commit
6200cca2f8
@ -16,10 +16,12 @@ interface PaymentBody {
|
|||||||
|
|
||||||
export async function sendPayment({
|
export async function sendPayment({
|
||||||
body,
|
body,
|
||||||
fromSquiz
|
fromSquiz,
|
||||||
|
paymentPurpose,
|
||||||
}: {
|
}: {
|
||||||
body: PaymentBody;
|
body: PaymentBody;
|
||||||
fromSquiz: boolean;
|
fromSquiz: boolean;
|
||||||
|
paymentPurpose: "paycart" | "replenishwallet";
|
||||||
}): Promise<[SendPaymentResponse | null, string?]> {
|
}): Promise<[SendPaymentResponse | null, string?]> {
|
||||||
try {
|
try {
|
||||||
const sendPaymentResponse = await makeRequest<
|
const sendPaymentResponse = await makeRequest<
|
||||||
@ -42,7 +44,7 @@ export async function sendPayment({
|
|||||||
},
|
},
|
||||||
phoneNumber: "79000000000",
|
phoneNumber: "79000000000",
|
||||||
login: "login_test",
|
login: "login_test",
|
||||||
returnUrl: `https://${isStaging}hub.pena.digital/afterpay?from=${fromSquiz ? "quiz" : "hub"}`,
|
returnUrl: `https://${isStaging}hub.pena.digital/afterpay?from=${fromSquiz ? "quiz" : "hub"}&purpose=${paymentPurpose}`,
|
||||||
...body
|
...body
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,16 +1,44 @@
|
|||||||
import { Box, Button, Typography, useTheme, useMediaQuery } from "@mui/material"
|
import { Box, Button, Typography, useTheme, useMediaQuery } from "@mui/material";
|
||||||
import wallet_icon from "@root/assets/Icons/ColorWallet.svg"
|
import { payCart } from "@root/api/cart";
|
||||||
|
import wallet_icon from "@root/assets/Icons/ColorWallet.svg";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
//Привет :)
|
|
||||||
|
|
||||||
|
const minute = 1000 * 60;
|
||||||
|
|
||||||
const { domain, pathname } = (() => {
|
const { domain, pathname } = (() => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const from = params.get("from") || "hub";
|
const from = params.get("from") || "hub";
|
||||||
|
|
||||||
|
const purpose = params.get("purpose");
|
||||||
|
|
||||||
|
if (purpose === "paycart") {
|
||||||
|
const payCartPendingRequestDeadline = localStorage.getItem("payCartPendingRequestDeadline");
|
||||||
|
const deadline = payCartPendingRequestDeadline
|
||||||
|
? Number(payCartPendingRequestDeadline)
|
||||||
|
: Date.now() + 20 * minute;
|
||||||
|
|
||||||
|
localStorage.setItem("payCartPendingRequestDeadline", deadline.toString());
|
||||||
|
|
||||||
|
tryPayCart();
|
||||||
|
|
||||||
|
async function tryPayCart() {
|
||||||
|
const [, payCartError] = await payCart();
|
||||||
|
|
||||||
|
if (!payCartError || Date.now() > deadline) {
|
||||||
|
localStorage.removeItem("payCartPendingRequestDeadline");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(tryPayCart, minute / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const host = window.location.hostname;
|
const host = window.location.hostname;
|
||||||
return {
|
return {
|
||||||
domain: (host.includes("s") ? "s" : "") + from,
|
domain: (host.includes("s") ? "s" : "") + from,
|
||||||
pathname: from === "hub" ? "/wallet" : ""
|
pathname: from === "hub" ? "/wallet" : ""
|
||||||
}
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
@ -67,5 +95,5 @@ export default () => {
|
|||||||
>На главную</Button>
|
>На главную</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box >
|
</Box >
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
@ -68,8 +68,7 @@ export default function Payment() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const handleCustomBackNavigation = useHistoryTracker();
|
const handleCustomBackNavigation = useHistoryTracker();
|
||||||
|
|
||||||
const notEnoughMoneyAmount =
|
const notEnoughMoneyAmount = (location.state?.notEnoughMoneyAmount as number) ?? 0;
|
||||||
(location.state?.notEnoughMoneyAmount as number) ?? 0;
|
|
||||||
|
|
||||||
const paymentValue = parseFloat(paymentValueField) * 100;
|
const paymentValue = parseFloat(paymentValueField) * 100;
|
||||||
|
|
||||||
@ -103,6 +102,7 @@ export default function Payment() {
|
|||||||
type: selectedPaymentMethod,
|
type: selectedPaymentMethod,
|
||||||
amount: Number(paymentValueField) * 100,
|
amount: Number(paymentValueField) * 100,
|
||||||
},
|
},
|
||||||
|
paymentPurpose: notEnoughMoneyAmount ? "paycart" : "replenishwallet",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sendPaymentError) {
|
if (sendPaymentError) {
|
||||||
@ -120,7 +120,7 @@ export default function Payment() {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(paymentValueField);
|
|
||||||
if (Number(paymentValueField) < 900) {
|
if (Number(paymentValueField) < 900) {
|
||||||
enqueueSnackbar("Минимальная сумма 900р");
|
enqueueSnackbar("Минимальная сумма 900р");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user