PaymentCommon.vue
1 month ago
PaymentOnSite.vue
1 month ago
PaymentPayPal.vue
1 month ago
PaymentSquare.vue
1 month ago
PaymentStripe.vue
1 month ago
PaymentWc.vue
1 month ago
PaymentCommon.vue
210 lines
| 1 | <template> |
| 2 | <div class="am-fs__payment_default"></div> |
| 3 | </template> |
| 4 | |
| 5 | <script setup> |
| 6 | // * Import from Vue |
| 7 | import { ref, inject, watchEffect } from 'vue' |
| 8 | |
| 9 | import httpClient from '../../../../../plugins/axios' |
| 10 | |
| 11 | // * Import from Vuex |
| 12 | import { useStore } from 'vuex' |
| 13 | |
| 14 | // * Composables |
| 15 | import { |
| 16 | useBookingData, |
| 17 | useCreateBooking, |
| 18 | useCreateBookingSuccess, |
| 19 | useCreateBookingError, |
| 20 | getErrorMessage, |
| 21 | } from '../../../../../assets/js/public/booking.js' |
| 22 | |
| 23 | const store = useStore() |
| 24 | |
| 25 | const emits = defineEmits(['payment-error']) |
| 26 | |
| 27 | const shortcodeData = inject('shortcodeData') |
| 28 | |
| 29 | let stepsArray = inject('stepsArray') |
| 30 | |
| 31 | let sidebarSteps = inject('sidebarSteps', ref([])) |
| 32 | |
| 33 | /************** |
| 34 | * Navigation * |
| 35 | *************/ |
| 36 | |
| 37 | const { nextStep, footerButtonReset, footerButtonClicked } = inject('changingStepsFunctions', { |
| 38 | nextStep: () => {}, |
| 39 | footerButtonReset: () => {}, |
| 40 | footerButtonClicked: { |
| 41 | value: false, |
| 42 | }, |
| 43 | }) |
| 44 | |
| 45 | // * Labels |
| 46 | const amLabels = inject('amLabels') |
| 47 | |
| 48 | watchEffect( |
| 49 | () => { |
| 50 | if (footerButtonClicked.value) { |
| 51 | if (!store.getters['coupon/getCouponValidated']) { |
| 52 | footerButtonReset() |
| 53 | emits('payment-error', amLabels.value.coupon_mandatory) |
| 54 | } else { |
| 55 | continueWithBooking() |
| 56 | } |
| 57 | } |
| 58 | }, |
| 59 | { flush: 'post' }, |
| 60 | ) |
| 61 | |
| 62 | /*********** |
| 63 | * Payment * |
| 64 | **********/ |
| 65 | |
| 66 | function razorpayVerify(paymentId, signature, orderId) { |
| 67 | let bookingData = useBookingData( |
| 68 | store, |
| 69 | null, |
| 70 | false, |
| 71 | { |
| 72 | paymentId: paymentId, |
| 73 | signature: signature, |
| 74 | orderId: orderId, |
| 75 | }, |
| 76 | null, |
| 77 | ) |
| 78 | |
| 79 | useCreateBooking( |
| 80 | store, |
| 81 | bookingData, |
| 82 | (response) => { |
| 83 | useCreateBookingSuccess(store, response, () => { |
| 84 | nextStep() |
| 85 | }) |
| 86 | }, |
| 87 | (error) => { |
| 88 | useCreateBookingError(store, error.response.data, () => { |
| 89 | emits('payment-error', getErrorMessage()) |
| 90 | }) |
| 91 | }, |
| 92 | ) |
| 93 | } |
| 94 | function continueWithBooking() { |
| 95 | footerButtonReset() |
| 96 | |
| 97 | let isEvent = store.getters['bookableType/getType'] === 'event' |
| 98 | |
| 99 | let gateway = isEvent |
| 100 | ? store.getters['payment/getPaymentGateway'] |
| 101 | : store.getters['booking/getPaymentGateway'] |
| 102 | |
| 103 | let formData = isEvent |
| 104 | ? { |
| 105 | shortcode: shortcodeData.value, |
| 106 | steps: stepsArray.value.map((i) => i.name), |
| 107 | } |
| 108 | : { |
| 109 | shortcode: shortcodeData.value, |
| 110 | steps: stepsArray.value.map((i) => i.key), |
| 111 | sidebar: sidebarSteps.value.map((i) => |
| 112 | Object.assign({ key: i.key, data: i.stepSelectedData }), |
| 113 | ), |
| 114 | } |
| 115 | |
| 116 | let bookingData = useBookingData( |
| 117 | store, |
| 118 | gateway === 'mollie' || gateway === 'barion' ? formData : null, |
| 119 | false, |
| 120 | {}, |
| 121 | null, |
| 122 | ) |
| 123 | |
| 124 | store.commit(isEvent ? 'setLoading' : 'booking/setLoading', true) |
| 125 | |
| 126 | switch (gateway) { |
| 127 | case 'mollie': |
| 128 | payment('/payment/mollie', bookingData, function (response) { |
| 129 | const bookings = response.data.data.bookings |
| 130 | if (sessionStorage.getItem('ameliaCacheData')) { |
| 131 | const ameliaCacheData = JSON.parse(sessionStorage.getItem('ameliaCacheData')) |
| 132 | ameliaCacheData.bookings = bookings |
| 133 | ameliaCacheData.packageCustomer = response.data.data.packageCustomer |
| 134 | sessionStorage.setItem('ameliaCacheData', JSON.stringify(ameliaCacheData)) |
| 135 | } |
| 136 | window.location = response.data.data.redirectUrl |
| 137 | }) |
| 138 | |
| 139 | break |
| 140 | |
| 141 | case 'razorpay': |
| 142 | payment('/payment/razorpay', bookingData, function (response) { |
| 143 | let options = response.data.data.data |
| 144 | |
| 145 | options.handler = function (razorpayResponse) { |
| 146 | razorpayVerify( |
| 147 | razorpayResponse.razorpay_payment_id, |
| 148 | razorpayResponse.razorpay_signature, |
| 149 | options.order_id, |
| 150 | ) |
| 151 | } |
| 152 | |
| 153 | options.modal = { |
| 154 | ondismiss: function () { |
| 155 | emits('payment-abandoned') |
| 156 | }, |
| 157 | } |
| 158 | |
| 159 | let razorpay = new Razorpay(options) |
| 160 | |
| 161 | razorpay.open() |
| 162 | }) |
| 163 | |
| 164 | break |
| 165 | |
| 166 | case 'barion': |
| 167 | payment('/payment/barion', bookingData, function (response) { |
| 168 | const bookings = response.data.data.bookings |
| 169 | if (sessionStorage.getItem('ameliaCacheData')) { |
| 170 | const ameliaCacheData = JSON.parse(sessionStorage.getItem('ameliaCacheData')) |
| 171 | ameliaCacheData.bookings = bookings |
| 172 | ameliaCacheData.packageCustomer = response.data.data.packageCustomer |
| 173 | sessionStorage.setItem('ameliaCacheData', JSON.stringify(ameliaCacheData)) |
| 174 | } |
| 175 | window.location = response.data.data.redirectUrl |
| 176 | }) |
| 177 | |
| 178 | break |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | function payment(endpoint, bookingData, success) { |
| 183 | httpClient |
| 184 | .post(endpoint, bookingData.data, bookingData.options) |
| 185 | .then(success) |
| 186 | .catch((error) => { |
| 187 | useCreateBookingError(store, error.response.data, () => { |
| 188 | emits('payment-error', getErrorMessage()) |
| 189 | }) |
| 190 | }) |
| 191 | } |
| 192 | </script> |
| 193 | |
| 194 | <script> |
| 195 | export default { |
| 196 | name: 'PaymentCommon', |
| 197 | } |
| 198 | </script> |
| 199 | |
| 200 | <style lang="scss"> |
| 201 | .amelia-v2-booking { |
| 202 | #amelia-container { |
| 203 | .am-fs__payment_default { |
| 204 | &-btn { |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | </style> |
| 210 |