PaymentCommon.vue
4 days ago
PaymentOnSite.vue
1 month ago
PaymentPayPal.vue
4 days ago
PaymentSquare.vue
4 days ago
PaymentStripe.vue
4 days ago
PaymentWc.vue
1 month ago
PaymentWc.vue
128 lines
| 1 | <template> |
| 2 | <div class="am-fs__payment_default"></div> |
| 3 | </template> |
| 4 | |
| 5 | <script setup> |
| 6 | // * Import from Vue |
| 7 | import { |
| 8 | // ref, |
| 9 | inject, |
| 10 | watchEffect, |
| 11 | } from 'vue' |
| 12 | |
| 13 | // * Import form Vuex |
| 14 | import { useStore } from 'vuex' |
| 15 | |
| 16 | // * Composables |
| 17 | import { |
| 18 | getErrorMessage, |
| 19 | useBookingData, |
| 20 | useCreateBookingError, |
| 21 | } from '../../../../../assets/js/public/booking.js' |
| 22 | |
| 23 | import httpClient from '../../../../../plugins/axios' |
| 24 | |
| 25 | // * Component props |
| 26 | let props = defineProps({ |
| 27 | instantBooking: { |
| 28 | type: Boolean, |
| 29 | default: false, |
| 30 | }, |
| 31 | }) |
| 32 | |
| 33 | const store = useStore() |
| 34 | |
| 35 | const shortcodeData = inject('shortcodeData') |
| 36 | |
| 37 | let stepsArray = inject('stepsArray') |
| 38 | |
| 39 | // ! treba da se prilagodi za services i packages |
| 40 | // let sidebarSteps = inject('sidebarSteps', ref([])) |
| 41 | |
| 42 | /************** |
| 43 | * Navigation * |
| 44 | *************/ |
| 45 | |
| 46 | const { footerButtonReset, footerButtonClicked } = inject('changingStepsFunctions', { |
| 47 | footerButtonReset: () => {}, |
| 48 | footerButtonClicked: { |
| 49 | value: false, |
| 50 | }, |
| 51 | }) |
| 52 | |
| 53 | defineExpose({ |
| 54 | continueWithBooking, |
| 55 | }) |
| 56 | |
| 57 | // * Labels |
| 58 | const amLabels = inject('labels') |
| 59 | |
| 60 | watchEffect(() => { |
| 61 | if (footerButtonClicked.value && !props.instantBooking) { |
| 62 | if (!store.getters['coupon/getCouponValidated']) { |
| 63 | footerButtonReset() |
| 64 | emits('payment-error', amLabels.value.coupon_mandatory) |
| 65 | } else { |
| 66 | continueWithBooking() |
| 67 | } |
| 68 | } |
| 69 | }) |
| 70 | |
| 71 | /*********** |
| 72 | * Payment * |
| 73 | **********/ |
| 74 | |
| 75 | function continueWithBooking() { |
| 76 | footerButtonReset() |
| 77 | |
| 78 | let bookingData = useBookingData( |
| 79 | store, |
| 80 | { |
| 81 | shortcode: shortcodeData.value, |
| 82 | steps: stepsArray.value.map((i) => i.name), |
| 83 | // ! it must be refactored |
| 84 | // sidebar: sidebarSteps.value.map(i => Object.assign({key: i.key, data: i.stepSelectedData})), |
| 85 | }, |
| 86 | false, |
| 87 | {}, |
| 88 | null, |
| 89 | ) |
| 90 | |
| 91 | store.commit('setLoading', true) |
| 92 | |
| 93 | payment('/payment/wc', bookingData, function (response) { |
| 94 | window.location = response.data.data.cartUrl |
| 95 | }) |
| 96 | } |
| 97 | |
| 98 | const emits = defineEmits(['payment-error']) |
| 99 | |
| 100 | function payment(endpoint, bookingData, success) { |
| 101 | httpClient |
| 102 | .post(endpoint, bookingData.data, bookingData.options) |
| 103 | .then(success) |
| 104 | .catch((error) => { |
| 105 | useCreateBookingError(store, error.response.data, () => { |
| 106 | emits('payment-error', getErrorMessage()) |
| 107 | }) |
| 108 | }) |
| 109 | } |
| 110 | </script> |
| 111 | |
| 112 | <script> |
| 113 | export default { |
| 114 | name: 'PaymentWc', |
| 115 | } |
| 116 | </script> |
| 117 | |
| 118 | <style lang="scss"> |
| 119 | .amelia-v2-booking { |
| 120 | #amelia-container { |
| 121 | .am-fs__payment_default { |
| 122 | &-btn { |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | </style> |
| 128 |