PromoCodes

This commit is contained in:
rafael1209
2024-02-22 18:50:45 +02:00
parent 8d2202c393
commit b253f16855
2 changed files with 79 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -33,17 +33,17 @@
</ul> </ul>
</div> </div>
<div v-if="showPromocodeStatus" class="error-promocode"> <div v-if="showPromocodeStatus" class="error-promocode">
<h2 v-if="errorPromocode" class="error-text__promocode">Промокод не найден</h2> <h2 v-if="errorPromocode" class="error-text__promocode">{{ promoResponse }}</h2>
<h2 v-else class="correct-text__promocode">Промокод успешно применён</h2> <h2 v-else class="correct-text__promocode">Промокод успешно применён</h2>
</div> </div>
<div class="deposit-promocode deposit-promocode__padding--input"> <div class="deposit-promocode deposit-promocode__padding--input">
<h3>Промокод</h3> <h3>Промокод</h3>
<div class="promokods"> <div class="promokods">
<input @focusout="checkValidationPromocode" v-model="promocode" class="promo-input" type="text" /> <input @focusout="checkValidationPromocode" v-model="promocode" class="promo-input" type="text" />
<button class="vvod_promocoda">Ввод</button> <button class="vvod_promocoda" @click="handleApplyPromoCode">Ввод</button>
</div>
</div> </div>
</div> <div class="error-checkbox" v-if="errorAgree">
<div class="error-checkbox" v-if="errorAgree">
<h2>Подтвердите согласие!</h2> <h2>Подтвердите согласие!</h2>
</div> </div>
<div class="deposit-checkbox checkbox-styles"> <div class="deposit-checkbox checkbox-styles">
@@ -120,12 +120,14 @@ import PaymentsModalNumbers from "@/mocks/PaymentsModalNumbers";
import { GettingMoneyOperation, WithdrawMoneyOperation } from "@/assets/js/moneyoperation/Claimmoney"; import { GettingMoneyOperation, WithdrawMoneyOperation } from "@/assets/js/moneyoperation/Claimmoney";
import CaptchaComponent from "@/components/CaptchaComponent.vue"; import CaptchaComponent from "@/components/CaptchaComponent.vue";
import {eventBus} from "@/main"; import {eventBus} from "@/main";
import { useVuelidate } from '@vuelidate/core' import { useVuelidate } from '@vuelidate/core'
import {maxValue, minValue, required, numeric, integer, minLength, maxLength} from "@vuelidate/validators"; import {maxValue, minValue, required, numeric, integer, minLength, maxLength} from "@vuelidate/validators";
import {GetCurrentMoney} from "@/assets/js/rest/RestMethods"; import {GetCurrentMoney} from "@/assets/js/rest/RestMethods";
import {GetCookie} from "@/assets/js/storage/CookieStorage"; import {GetCookie} from "@/assets/js/storage/CookieStorage";
import { ApplyPromoCode } from "@/assets/js/rest/RestMethods.js"; // Замените на правильный путь к файлу с функцией ApplyPromoCode
export default { export default {
components: { CaptchaComponent }, components: { CaptchaComponent },
@@ -215,10 +217,10 @@ export default {
closeModal() { closeModal() {
return this.$emit("closemodal"); return this.$emit("closemodal");
}, },
checkValidationPromocode() { // checkValidationPromocode() {
this.errorPromocode = !this.promocodeBase.includes(this.promocode); // this.errorPromocode = !this.promocodeBase.includes(this.promocode);
this.showPromocodeStatus = true // this.showPromocodeStatus = true
}, // },
completeValidationCheck() { completeValidationCheck() {
this.offBtn = true this.offBtn = true
@@ -235,6 +237,46 @@ export default {
this.captchaToken = Token this.captchaToken = Token
this.completeValidtaion.captchatokensaving = true 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() { async RedirectedMethodDep() {
this.v$.$touch() this.v$.$touch()