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