From b7942fdcb03861234663c813e13d4b6745bd2c2a Mon Sep 17 00:00:00 2001 From: KwikKill Date: Sun, 3 Dec 2023 19:20:02 +0100 Subject: [PATCH] Add payment for tournaments --- src/models/tournament.ts | 1 + src/stores/tournament.store.ts | 36 ++++++++++++++++++++++++++++++++ src/views/Me.vue | 9 ++++++-- src/views/TournamentRegister.vue | 6 ++++-- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/models/tournament.ts b/src/models/tournament.ts index 83da3f8..e34f15a 100644 --- a/src/models/tournament.ts +++ b/src/models/tournament.ts @@ -20,6 +20,7 @@ interface BaseTournament { game: Game | Game['id']; manager_online_product: number; player_online_product: number; + substitute_online_product: number; maxTeam: number; validated_teams: number; description: string; diff --git a/src/stores/tournament.store.ts b/src/stores/tournament.store.ts index 899e730..58e4ab2 100755 --- a/src/stores/tournament.store.ts +++ b/src/stores/tournament.store.ts @@ -212,6 +212,41 @@ export const useTournamentStore = defineStore('tournament', () => { return res.data; } + async function payRegistration( + tournament: Tournament, + role: string, + ) { + await get_csrf(); + + let product_id; + if (role === 'player') { + product_id = tournament.player_online_product; + } else if (role === 'manager') { + product_id = tournament.manager_online_product; + } else if (role === 'substitute') { + product_id = tournament.substitute_online_product; + } + if (!product_id) return; + + const data = { + products: [product_id], + } as Record; + + const response = await axios.post<{ + redirect_url: string; + }>('payment/pay/', data, { + withCredentials: true, + headers: { + 'X-CSRFToken': csrf.value, + }, + }); + await fetchTournamentFull(tournament.id); + + const { redirect_url } = response.data; + + window.location.href = redirect_url; + } + function $reset() { eventsList.value = {}; tournamentsList.value = {}; @@ -242,6 +277,7 @@ export const useTournamentStore = defineStore('tournament', () => { fetchTournamentsFull, registerTeam, registerPlayerOrManager, + payRegistration, $reset, groupBy, }; diff --git a/src/views/Me.vue b/src/views/Me.vue index f173ac7..974c8f4 100755 --- a/src/views/Me.vue +++ b/src/views/Me.vue @@ -10,11 +10,15 @@ import { import placeholder from '@/assets/images/logo_home.png'; import FormField from '@/components/FormField.vue'; import Modal from '@/components/Modal.vue'; +import type { Tournament } from '@/models/tournament'; +import { useTournamentStore } from '@/stores/tournament.store'; import { useUserStore } from '@/stores/user.store'; const userStore = useUserStore(); +const tournamentStore = useTournamentStore(); const { user, role, inscriptions } = storeToRefs(userStore); const { fetch_user_inscription_full, patch_user } = userStore; +const { payRegistration } = tournamentStore; onMounted(async () => { await fetch_user_inscription_full(); @@ -226,11 +230,12 @@ const editField = (field: string) => { diff --git a/src/views/TournamentRegister.vue b/src/views/TournamentRegister.vue index fff2b02..f6c7f19 100755 --- a/src/views/TournamentRegister.vue +++ b/src/views/TournamentRegister.vue @@ -23,7 +23,9 @@ const { user } = useUserStore(); const tournamentStore = useTournamentStore(); -const { registerTeam, registerPlayerOrManager, getTournamentFull } = tournamentStore; +const { + registerTeam, registerPlayerOrManager, getTournamentFull, payRegistration, +} = tournamentStore; const { tournamentsList } = storeToRefs(tournamentStore); const tournament = computed(() => tournamentsList.value[props.id]); // const tournament = ref(); @@ -101,7 +103,7 @@ const register_player = async () => { }; const payment = async () => { - /* */ + await payRegistration(tournament.value as Tournament, register_form.role); }; const generate_password = () => {