diff --git a/public/favicon.png b/public/favicon.png index 7e6f5eb..873aa6c 100644 Binary files a/public/favicon.png and b/public/favicon.png differ diff --git a/public/hpp-hosta-fix-label.zip b/public/hpp-hosta-fix-label.zip deleted file mode 100644 index d95b273..0000000 Binary files a/public/hpp-hosta-fix-label.zip and /dev/null differ diff --git a/public/index.html b/public/index.html index e852974..81ee695 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ - Svelte app + HPay diff --git a/src/Pages/DepositPage.svelte b/src/Pages/DepositPage.svelte index 8891af0..c860ac7 100644 --- a/src/Pages/DepositPage.svelte +++ b/src/Pages/DepositPage.svelte @@ -5,8 +5,15 @@ import axios from "axios"; import { sayError, sayInfo } from "../lib/toaster"; import LoadingSpinner from "../lib/loadingSpinner.svelte"; - import { addMinutes, formatDistanceToNow, parseISO } from "date-fns"; - import { ca, ru } from "date-fns/locale"; + import { + addMinutes, + differenceInMinutes, + differenceInSeconds, + formatDistanceToNow, + formatDistanceToNowStrict, + parseISO, + } from "date-fns"; + import { ca, el, ru } from "date-fns/locale"; const apiBase = "https://24paymentgateway.ru/api/v1/"; @@ -19,17 +26,19 @@ //http://localhost:8080/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE3MjQzNjEzOTgsImlhdCI6MTcyMTk0MjE5OCwiaW5fY3VycmVuY3lfY29kZSI6IktHUyIsImlzcyI6Ikhvc3RhcGF5Iiwib3JkZXJfaWQiOiIxZjhjOTI2NC1lZWQ3LTRhYzMtYTEyZC0xYzEzMjg4MWM4NzQiLCJvdXRfY3VycmVuY3lfY29kZSI6IktHUyJ9.w_ki56Hb81kX2SoS9qm0Je3atBhmUWTQaYYrLX-udCM /** * hpp: -1) GET: /api/v1/getPaymentMethods -2) GET: /api/v1/getRequisites -3) GET: /api/v1/getOrderStatus -4) POST: /api/v1/loadDisputeReceipt -5) POST: /api/v1/createDispute -5) POST: /api/v1/choosePaymentMethod -6) POST: /api/v1/cancelOrder - */ + 1) GET: /api/v1/getPaymentMethods + 2) GET: /api/v1/getRequisites + 3) GET: /api/v1/getOrderStatus + 4) POST: /api/v1/loadDisputeReceipt + 5) POST: /api/v1/createDispute + 5) POST: /api/v1/choosePaymentMethod + 6) POST: /api/v1/cancelOrder + */ + // let tries = 0; let tokenURL = ""; let orderID = ""; let invalidURL = true; + let validJWT = false; async function getTokenFromURL() { const queryString = window.location.search; // //console.log(queryString); @@ -39,13 +48,12 @@ //console.log(tokenURL); validateJWT(tokenURL); // //console.log(); - if (invalidURL == true) { + if (validJWT !== true) { sayError("Неверный ID заявки"); } else { await getOrderStatus(); //console.log(orderStatus); - - + switch (orderStatus) { case 1: getPaymentMethods(); @@ -68,6 +76,7 @@ default: break; } + invalidURL = false; // getPaymentMethods(); } @@ -80,9 +89,9 @@ let t = jwtDecode(token); orderID = t["order_id"]; // //console.log(t); - invalidURL = false; + validJWT = true; } catch (error) { - invalidURL = true; + validJWT = false; // //console.log(error); } } @@ -92,15 +101,34 @@ function calculateDate(src) { const originalDate = parseISO(src); //console.log(originalDate); - + const newDate = addMinutes(originalDate, 10); timeLeftInterval = setInterval(() => { - timeLeft = formatDistanceToNow(newDate, { - addSuffix: true, - includeSeconds: true, - locale: ru, - }); + const now = new Date(); + const minutes = differenceInMinutes(newDate, now); + const seconds = differenceInSeconds(newDate, now) % 60; + + // Форматируем минуты и секунды + const formattedMinutes = String(minutes).padStart(2, "0"); + const formattedSeconds = String(seconds).padStart(2, "0"); + + timeLeft = `${formattedMinutes}:${formattedSeconds}`; + if(timeLeft === "00:00" || timeLeft.includes("-")) + { + orderStatus = 6; + showTimeout = true; + clearInterval(timeLeftInterval); + } }, 1000); + const now = new Date(); + const minutes = differenceInMinutes(newDate, now); + const seconds = differenceInSeconds(newDate, now) % 60; + + // Форматируем минуты и секунды + const formattedMinutes = String(minutes).padStart(2, "0"); + const formattedSeconds = String(seconds).padStart(2, "0"); + + timeLeft = `${formattedMinutes}:${formattedSeconds}`; } let selectedBank = ""; @@ -182,12 +210,16 @@ "8d895e75b7a0def7699e6c4d7cd54c51d9844775bd5fd5e8e3d34748", ); const captchaInput = form.querySelector("input"); - if (captchaInput?.value !== "") { - captchaVerified = true; - captchaValue = captchaInput.value; - } else { - captchaVerified = true; - captchaValue = undefined; + try { + if (captchaInput?.value !== "") { + captchaVerified = true; + captchaValue = captchaInput.value; + } else { + captchaVerified = true; + captchaValue = undefined; + } + } catch (error) { + console.error(error); } }, 500); @@ -249,44 +281,61 @@ } // getRequisites(); + // window.location.href = "httpa://www.google.com"; + let orderStatus; + let redirectURL = ""; async function getOrderStatus() { + // tries++; try { let result = await axios.get(apiBase + "getOrderStatus", { - headers: { - Authorization: "Bearer " + tokenURL, - "Content-Type": "application/json", - }, - }); - orderStatus = result.data.status; - // //console.log(result); - if(orderStatus === 4) - { - selectedBank = result.data["bank_id"]+""; - } - else if (orderStatus === 5) - { - //console.log('hello!'); - - selectedBank = result.data["bank_id"] + ""; - requisites = result.data["requisite"]; - calculateDate(result.data["requisite_creation_time"]); - disableGetReqBtn = true; - showReqs = true; - } - } catch (error) { - //console.log(error); - - orderStatus=6; - } - - } + headers: { + Authorization: "Bearer " + tokenURL, + "Content-Type": "application/json", + }, + timeout: 5000, + }); + orderStatus = result.data.status; + if (result.data["successURL"] || result.data["errorURL"]) { + redirectURL = result.data["successURL"] + ? result.data["successURL"] + : result.data["errorURL"]; + } + // console.log("got redirect:", result.data["successURL"], result.data["errorURL"]); + // console.log("written: ", redirectURL); + // //console.log(result); + if (orderStatus === 4) { + selectedBank = result.data["bank_id"] + ""; + } else if (orderStatus === 5) { + //console.log('hello!'); + selectedBank = result.data["bank_id"] + ""; + requisites = result.data["requisite"]; + calculateDate(result.data["requisite_creation_time"]); + disableGetReqBtn = true; + + showReqs = true; + } + } catch (error) { + if (error.code === "ECONNABORTED") { + location.reload(); + } else { + orderStatus = 6; + } + //console.log(error); + // if (tries > 3) { + // } else { + // getOrderStatus(); + // } + } + } + let value_disputeSum = 0; async function loadReceipt() { const formData = new FormData(); let file = document.getElementById("loaded-file").files[0]; // formData.append("uuid", orderID); formData.append("data", file); + formData.append("amount", Number(value_disputeSum)); let result = await axios.post(apiBase + "openDispute", formData, { headers: { Authorization: "Bearer " + tokenURL, @@ -294,6 +343,11 @@ }, }); // //console.log(result); + if (result.status > 300) { + sayError("Что-то пошло не так"); + return; + } + sayInfo("Успешно!"); } async function createDispute() { @@ -344,37 +398,52 @@ //console.log(result); } - async function copyToClipboard() { + async function copyToClipboard(val) { try { - await navigator.clipboard.writeText(requisites[1]); + await navigator.clipboard.writeText(val); sayInfo("Скопировано!"); } catch (err) { //console.error("Failed to copy: ", err); } } - function startPingingStatus() {ping();} + function startPingingStatus() { + ping(); + } async function ping() { await getOrderStatus(); + // console.log(orderStatus); + // console.log("url", redirectURL); + if (orderStatus === 2) { showReject = true; showLoadingScreen = false; + await delay(500); + if (redirectURL !== "") { + window.open(redirectURL, "_self"); + } return; } - if(orderStatus === 3) - { + if (orderStatus === 3) { showAccept = true; showLoadingScreen = false; + await delay(500); + if (redirectURL !== "") { + window.open(redirectURL, "_self"); + } return; } - if(orderStatus===6) - { + if (orderStatus === 6) { showTimeout = true; showLoadingScreen = false; + await delay(500); + if (redirectURL !== "") { + window.open(redirectURL, "_self"); + } return; } - await delay(1000); + await delay(1500); ping(); } @@ -406,7 +475,7 @@ -{:else} +{:else if !showAccept && !showTimeout && !showReject}
@@ -418,7 +487,13 @@
{#if showBankSelection} -

{selectedBank === "" ? "Выбор банка":(requisites.length < 1 ? "Запрос реквизитов":"Оплата заявки")}

+

+ {selectedBank === "" + ? "Выбор банка" + : requisites.length < 1 + ? "Запрос реквизитов" + : "Оплата заявки"} +

{#each paymentMethods as pm}
-

Получатель: {requisites[0]}

+
+

+{requisites[2]}

+ +
+

{requisites[0]}

Время на оплату: {timeLeft}

@@ -519,6 +614,12 @@ {/if} {#if showHelpSection} +

Укажите сумму:

+

Загрузите чек, чтобы мы могли подтвердить перевод

@@ -659,9 +760,11 @@

Ваш платёж обрабатывается

-

Это не займет много времени

-

Номер платежа: {orderID}

-

+

+ Это не займет много времени +

+

Номер платежа: {orderID}

+

Телеграм: @hosta_pay @@ -710,9 +813,21 @@ class="fixed inset-0 bg-slate-950 flex justify-center items-center text-white" >

- - - + + +

Время заявки истекло

Номер платежа: {orderID}

@@ -725,4 +840,50 @@

+{:else if showReject} +
+
+ + + + +

Заявка отклонена

+

Номер платежа: {orderID}

+

+ Телеграм: @hosta_pay +

+

+ Почта: support@24paymentgateway.ru +

+
+
+ {/if}