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