From b253f168553a2e93b693c716176947f93c0bee00 Mon Sep 17 00:00:00 2001 From: rafael1209 Date: Thu, 22 Feb 2024 18:50:45 +0200 Subject: [PATCH] PromoCodes --- .../src/assets/js/rest/RestMethods.js | 27 ++++++++ luckydiamond/src/components/PaymentsModal.vue | 62 ++++++++++++++++--- 2 files changed, 79 insertions(+), 10 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 716805b..41edb22 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -74,4 +74,31 @@ export async function GetChatHistory() { } } +export async function ApplyPromoCode(authToken, searchToken, promoCode) { + const data = { + userCredentials: { + searchToken: searchToken, + authtoken: authToken + }, + promoCode: promoCode + }; + try { + const response = await fetch(`${BackendApiUrl}/PromoCode/ApplyPromo`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + redirect: "follow" + }); + + if (!response.ok) { + console.log("Fetch error:", response.status); + } + + return await response.json(); + } catch (error) { + console.log("Fetch error:", error); + } +} diff --git a/luckydiamond/src/components/PaymentsModal.vue b/luckydiamond/src/components/PaymentsModal.vue index 2e6c485..fc6a23a 100644 --- a/luckydiamond/src/components/PaymentsModal.vue +++ b/luckydiamond/src/components/PaymentsModal.vue @@ -33,17 +33,17 @@
-

Промокод не найден

+

{{ promoResponse }}

Промокод успешно применён

Промокод

- - + + +
- -
+

Подтвердите согласие!

@@ -120,12 +120,14 @@ import PaymentsModalNumbers from "@/mocks/PaymentsModalNumbers"; import { GettingMoneyOperation, WithdrawMoneyOperation } from "@/assets/js/moneyoperation/Claimmoney"; import CaptchaComponent from "@/components/CaptchaComponent.vue"; + import {eventBus} from "@/main"; import { useVuelidate } from '@vuelidate/core' import {maxValue, minValue, required, numeric, integer, minLength, maxLength} from "@vuelidate/validators"; import {GetCurrentMoney} from "@/assets/js/rest/RestMethods"; import {GetCookie} from "@/assets/js/storage/CookieStorage"; +import { ApplyPromoCode } from "@/assets/js/rest/RestMethods.js"; // Замените на правильный путь к файлу с функцией ApplyPromoCode export default { components: { CaptchaComponent }, @@ -215,10 +217,10 @@ export default { closeModal() { return this.$emit("closemodal"); }, - checkValidationPromocode() { - this.errorPromocode = !this.promocodeBase.includes(this.promocode); - this.showPromocodeStatus = true - }, + // checkValidationPromocode() { + // this.errorPromocode = !this.promocodeBase.includes(this.promocode); + // this.showPromocodeStatus = true + // }, completeValidationCheck() { this.offBtn = true @@ -235,6 +237,46 @@ export default { this.captchaToken = Token this.completeValidtaion.captchatokensaving = true }, + async handleApplyPromoCode() { + const authToken = GetCookie("AUTHTOKEN"); + const searchToken = GetCookie("SearchToken"); + + try { + const response = await ApplyPromoCode(authToken, searchToken, this.promocode); + + console.log(response); + + if (response === 'Promo dont exist.') + { + this.showPromocodeStatus = true; + this.errorPromocode = true; + this.promoResponse = 'Промокод не найден'; + } + else if(response === 'promotional code has expired') + { + this.showPromocodeStatus = true; + this.errorPromocode = true; + this.promoResponse = 'Не действителен'; + } + else if(response === 'User is alredy use the promo') + { + this.showPromocodeStatus = true; + this.errorPromocode = true; + this.promoResponse = 'Уже использован'; + } + else + { + this.showPromocodeStatus = true; + this.errorPromocode = false; + this.promoResponse = response; + } + + } + catch (error) + { + console.error("Ошибка при применении промокода:", error); + } +}, async RedirectedMethodDep() { this.v$.$touch() @@ -317,4 +359,4 @@ export default { }, }, }; - + \ No newline at end of file