PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / public / cabinet.js
ameliabooking / v3 / src / assets / js / public Last commit date
actions.js 1 month ago booking.js 2 days ago cabinet.js 1 month ago cart.js 2 days ago catalog.js 2 days ago coupon.js 1 month ago customFields.js 1 month ago customFontFace.js 1 month ago eventFormCssVars.js 1 month ago events.js 1 month ago facebookPixel.js 1 month ago ivy.js 1 month ago package.js 2 days ago panel.js 1 month ago public.js 1 month ago renderActions.js 1 month ago restore.js 2 days ago slots.js 2 days ago stripePaymentIntent.js 2 days ago translation.js 1 month ago user.js 1 month ago
cabinet.js
215 lines
1 import { reactive } from 'vue'
2 import moment from 'moment'
3 import { settings } from '../../../plugins/settings'
4 import httpClient from '../../../plugins/axios'
5 import { useAppointmentBookingAmountData } from '../common/appointments'
6 import { usePackageBookingPrice } from '../admin/package'
7 import { useEventBookingsPrice } from '../admin/event'
8
9 const globalLabels = reactive(window.wpAmeliaLabels)
10
11 function usePaymentLink(store, method, reservation) {
12 if (reservation.type === 'package') store.commit('cabinet/setPackageLoading', true)
13 if (reservation.type === 'appointment') store.commit('cabinet/setAppointmentsLoading', true)
14 if (reservation.type === 'event') store.commit('cabinet/setEventsLoading', true)
15
16 store.commit(
17 'cabinet/setPaymentLinkLoader',
18 reservation.bookings ? reservation.bookings[0].id : reservation.id,
19 )
20
21 let appointmentData = JSON.parse(JSON.stringify(reservation))
22
23 let customer = JSON.parse(JSON.stringify(store.getters['auth/getProfile']))
24
25 customer.birthday = null
26
27 appointmentData['customer'] = customer
28
29 if (appointmentData['type'] !== 'package') {
30 appointmentData[appointmentData['type']] = reservation
31
32 appointmentData['booking'] = reservation.bookings[0]
33
34 appointmentData['paymentId'] = reservation.bookings[0].payments[0].id
35 } else {
36 appointmentData = Object.assign(appointmentData, appointmentData.package)
37 }
38
39 httpClient
40 .post('/payments/link', {
41 data: appointmentData,
42 paymentMethod: method,
43 })
44 .then((response) => {
45 if (!response.data.data.error && response.data.data.paymentLink) {
46 window.location.href = response.data.data.paymentLink
47 } else {
48 store.commit('cabinet/setPaymentLinkError', { value: true, type: reservation.type })
49 }
50 })
51 .catch((error) => {
52 store.commit('cabinet/setPaymentLinkError', { value: true, type: reservation.type })
53 })
54 .finally(() => {
55 store.commit('cabinet/setPaymentLinkLoader', null)
56 if (reservation.type === 'package') store.commit('cabinet/setPackageLoading', false)
57 if (reservation.type === 'appointment') store.commit('cabinet/setAppointmentsLoading', false)
58 if (reservation.type === 'event') store.commit('cabinet/setEventsLoading', false)
59 })
60 }
61
62 function usePaymentFromCustomerPanel(reservation, entitySettings) {
63 if (
64 reservation.type !== 'package' &&
65 (!reservation.bookings || reservation.bookings.length === 0)
66 ) {
67 return false
68 }
69
70 if (typeof entitySettings === 'string') {
71 entitySettings = JSON.parse(entitySettings)
72 } else if (!entitySettings) {
73 entitySettings = {}
74 }
75
76 let paymentLinksEnabled =
77 entitySettings &&
78 'payments' in entitySettings &&
79 entitySettings.payments &&
80 'paymentLinks' in entitySettings.payments &&
81 entitySettings.payments.paymentLinks &&
82 'enabled' in entitySettings.payments.paymentLinks
83 ? entitySettings.payments.paymentLinks
84 : settings.payments.paymentLinks
85
86 return (
87 usePaymentMethods(settings).length &&
88 settings &&
89 paymentLinksEnabled &&
90 paymentLinksEnabled.enabled
91 )
92 }
93
94 function usePaymentMethods(entitySettings) {
95 if (typeof entitySettings === 'string') {
96 entitySettings = JSON.parse(entitySettings)
97 } else if (!entitySettings) {
98 entitySettings = {}
99 }
100
101 let paymentOptions = []
102 entitySettings = entitySettings.payments || null
103
104 if (settings.payments.wc.enabled) {
105 paymentOptions.push({
106 value: 'wc',
107 label: globalLabels.wc,
108 })
109 } else if (
110 settings.payments.mollie.enabled &&
111 (!entitySettings || !('mollie' in entitySettings) || entitySettings.mollie.enabled)
112 ) {
113 paymentOptions.push({
114 value: 'mollie',
115 label: globalLabels.on_line,
116 })
117 } else {
118 if (
119 settings.payments.payPal.enabled &&
120 (!entitySettings || !('payPal' in entitySettings) || entitySettings.payPal.enabled)
121 ) {
122 paymentOptions.push({
123 value: 'payPal',
124 label: globalLabels.pay_pal,
125 })
126 }
127
128 if (
129 settings.payments.stripe.enabled &&
130 (!entitySettings || !('stripe' in entitySettings) || entitySettings.stripe.enabled)
131 ) {
132 paymentOptions.push({
133 value: 'stripe',
134 label: globalLabels.credit_card,
135 })
136 }
137
138 if (
139 settings.payments.razorpay.enabled &&
140 (!entitySettings || !('razorpay' in entitySettings) || entitySettings.razorpay.enabled)
141 ) {
142 paymentOptions.push({
143 value: 'razorpay',
144 label: globalLabels.razorpay,
145 })
146 }
147
148 if (
149 settings.payments.square.enabled &&
150 (!entitySettings || !('square' in entitySettings) || entitySettings.square.enabled)
151 ) {
152 paymentOptions.push({
153 value: 'square',
154 label: globalLabels.square,
155 })
156 }
157
158 if (
159 settings.payments.barion.enabled &&
160 (!entitySettings || !('barion' in entitySettings) || entitySettings.barion.enabled)
161 ) {
162 paymentOptions.push({
163 value: 'barion',
164 label: globalLabels.barion,
165 })
166 }
167 }
168
169 return paymentOptions
170 }
171
172 function usePayable(store, reservation) {
173 switch (reservation.type) {
174 case 'appointment': {
175 let amountData = useAppointmentBookingAmountData(
176 store,
177 {
178 price: reservation.bookings[0].price,
179 persons: reservation.bookings[0].persons,
180 aggregatedPrice: reservation.bookings[0].aggregatedPrice,
181 extras: reservation.bookings[0].extras,
182 serviceId: null,
183 tax: reservation.bookings[0].tax,
184 coupon: reservation.bookings[0].coupon,
185 },
186 false,
187 )
188
189 return (
190 amountData.total - amountData.discount + amountData.tax >
191 reservation.bookings[0].payments
192 .filter((p) => p.status !== 'refunded' && p.status !== 'pending')
193 .reduce((partialSum, a) => partialSum + a.amount, 0)
194 )
195 }
196
197 case 'event':
198 return (
199 useEventBookingsPrice(reservation) >
200 reservation.bookings[0].payments
201 .filter((p) => p.status !== 'refunded' && p.status !== 'pending')
202 .reduce((partialSum, a) => partialSum + a.amount, 0)
203 )
204 case 'package':
205 return (
206 usePackageBookingPrice(reservation) >
207 reservation.payments
208 .filter((p) => p.status !== 'refunded' && p.status !== 'pending')
209 .reduce((partialSum, a) => partialSum + a.amount, 0)
210 )
211 }
212 }
213
214 export { usePayable, usePaymentMethods, usePaymentFromCustomerPanel, usePaymentLink }
215