Payment methode now selectable
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import {reactive, ref} from 'vue'
|
||||
import axios from 'axios'
|
||||
|
||||
export function useSignupForm(event, participantData, paymentMethod) {
|
||||
export function useSignupForm(event, participantData) {
|
||||
const currentStep = ref(1)
|
||||
const submitting = ref(false)
|
||||
const summaryLoading = ref(false)
|
||||
@@ -9,9 +9,13 @@ export function useSignupForm(event, participantData, paymentMethod) {
|
||||
|
||||
const selectedAddons = reactive({})
|
||||
|
||||
// Für die Aktion freigeschaltete Zahlungsmethoden; ist genau eine aktiv, wird sie vorausgewählt.
|
||||
const activeMethods = (event.paymentMethods ?? []).filter(m => m.active)
|
||||
|
||||
const formData = reactive({
|
||||
eatingHabit: 'EATING_HABIT_VEGAN',
|
||||
paymentMethod: paymentMethod ?? null,
|
||||
paymentMethod: activeMethods.length === 1 ? activeMethods[0].slug : null,
|
||||
paymentOptions: {},
|
||||
userId: participantData.id,
|
||||
eventId: event.id,
|
||||
vorname: participantData.firstname ?? '',
|
||||
@@ -52,33 +56,52 @@ export function useSignupForm(event, participantData, paymentMethod) {
|
||||
})
|
||||
|
||||
const summaryAmount = ref('')
|
||||
const summaryAmountValue = ref(0)
|
||||
|
||||
const fetchAmount = async () => {
|
||||
summaryLoading.value = true
|
||||
try {
|
||||
const res = await axios.post('/api/v1/event/' + event.id + '/calculate-amount', {
|
||||
arrival: formData.arrival,
|
||||
departure: formData.departure,
|
||||
event_id: event.id,
|
||||
participation_group: formData.participant_group,
|
||||
selected_amount: formData.beitrag,
|
||||
addons: selectedAddons,
|
||||
participationType: formData.participationType,
|
||||
beitrag: formData.beitrag,
|
||||
sibling: formData.sibling,
|
||||
})
|
||||
summaryAmount.value = res.data.amount
|
||||
summaryAmountValue.value = Number(res.data.amountValue ?? 0)
|
||||
} finally {
|
||||
summaryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Steps: ... 8 Allergien, 9 Zahlungsart, 10 Zusammenfassung.
|
||||
const STEP_PAYMENT = 9
|
||||
const STEP_SUMMARY = 10
|
||||
|
||||
const goToStep = async (step) => {
|
||||
if (step === 9) {
|
||||
summaryLoading.value = true
|
||||
summaryAmount.value = ''
|
||||
try {
|
||||
const res = await axios.post('/api/v1/event/' + event.id + '/calculate-amount', {
|
||||
arrival: formData.arrival,
|
||||
departure: formData.departure,
|
||||
event_id: event.id,
|
||||
participation_group: formData.participant_group,
|
||||
selected_amount: formData.beitrag,
|
||||
addons: selectedAddons,
|
||||
participationType: formData.participationType,
|
||||
beitrag: formData.beitrag,
|
||||
sibling: formData.sibling,
|
||||
})
|
||||
summaryAmount.value = res.data.amount
|
||||
} finally {
|
||||
summaryLoading.value = false
|
||||
if (step === STEP_PAYMENT) {
|
||||
// Betrag ermitteln: Bei 0 € wird die Zahlungsart-Auswahl übersprungen.
|
||||
await fetchAmount()
|
||||
if (summaryAmountValue.value <= 0) {
|
||||
formData.paymentMethod = null
|
||||
formData.paymentOptions = {}
|
||||
currentStep.value = STEP_SUMMARY
|
||||
return
|
||||
}
|
||||
} else if (step === STEP_SUMMARY) {
|
||||
await fetchAmount()
|
||||
}
|
||||
currentStep.value = step
|
||||
}
|
||||
|
||||
const submit = async () => {
|
||||
if (!formData.summary_information_correct || !formData.summary_accept_terms || !formData.legal_accepted || !formData.payment) {
|
||||
// Zahlungs-Bestätigung wird im Summary-Schritt kontextabhängig erzwungen (nur bei Überweisung).
|
||||
if (!formData.summary_information_correct || !formData.summary_accept_terms || !formData.legal_accepted) {
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
@@ -96,5 +119,16 @@ export function useSignupForm(event, participantData, paymentMethod) {
|
||||
}
|
||||
}
|
||||
|
||||
return { currentStep, goToStep, formData, selectedAddons, submit, submitting, submitResult, summaryLoading, summaryAmount }
|
||||
return {
|
||||
currentStep,
|
||||
goToStep,
|
||||
formData,
|
||||
selectedAddons,
|
||||
submit,
|
||||
submitting,
|
||||
submitResult,
|
||||
summaryLoading,
|
||||
summaryAmount,
|
||||
summaryAmountValue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user