appointments.js
1 year ago
attendees.js
1 year ago
colorManipulation.js
3 years ago
customer.js
1 year ago
date.js
1 year ago
defaultCustomize.js
1 year ago
employee.js
1 year ago
events.js
1 year ago
formFieldsTemplates.js
3 years ago
formatting.js
1 year ago
helper.js
1 year ago
image.js
1 year ago
integrationApple.js
1 year ago
integrationGoogle.js
1 year ago
integrationOutlook.js
1 year ago
integrationStripe.js
1 year ago
integrationZoom.js
1 year ago
licence.js
2 years ago
objectAndArrayManipulation.js
3 years ago
pricing.js
1 year ago
recurring.js
1 year ago
responsive.js
1 year ago
scrollElements.js
4 years ago
settings.js
1 year ago
translationsElementPlus.js
1 year ago
integrationStripe.js
108 lines
| 1 | import httpClient from "../../../plugins/axios"; |
| 2 | import {useAuthorizationHeaderObject} from "../public/panel"; |
| 3 | |
| 4 | function useStripeSync (store) { |
| 5 | store.commit('auth/setStripeLoading', true) |
| 6 | |
| 7 | httpClient.get( |
| 8 | '/stripe/accounts/' + store.getters['employee/getId'], |
| 9 | Object.assign( |
| 10 | { |
| 11 | }, |
| 12 | useAuthorizationHeaderObject(store) |
| 13 | ) |
| 14 | ).then((response) => { |
| 15 | if (response.data.data.account) { |
| 16 | store.commit('auth/setStripeProvider', response.data.data.account) |
| 17 | |
| 18 | if (!store.getters['employee/getStripeConnect']) { |
| 19 | store.commit('employee/setStripeConnect', { |
| 20 | id: response.data.data.account.id, |
| 21 | amount: null, |
| 22 | }) |
| 23 | } |
| 24 | } |
| 25 | }).catch((error) => { |
| 26 | console.log(error) |
| 27 | }).finally(() => { |
| 28 | store.commit('auth/setStripeLoading', false) |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | function useStripeConnect (store, accountType) { |
| 33 | store.commit('auth/setStripeLoading', true) |
| 34 | |
| 35 | httpClient.post( |
| 36 | '/stripe/onboard/' + store.getters['auth/getProfile'].id, |
| 37 | Object.assign( |
| 38 | { |
| 39 | returnUrl: window.location.href, |
| 40 | accountType: accountType, |
| 41 | }, |
| 42 | useAuthorizationHeaderObject(store) |
| 43 | ) |
| 44 | ).then((response) => { |
| 45 | window.location.href = response.data.data.url |
| 46 | }).catch((error) => { |
| 47 | store.commit('auth/setStripeLoading', false) |
| 48 | console.log('response' in error && 'data' in error.response && 'message' in error.response.data ? error.response.data.message : error.message) |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | function useStripeDisconnect (store) { |
| 53 | store.commit('auth/setStripeLoading', true) |
| 54 | |
| 55 | httpClient.post( |
| 56 | '/stripe/disconnect/' + store.getters['auth/getProfile'].id, |
| 57 | useAuthorizationHeaderObject(store) |
| 58 | ).then(() => { |
| 59 | store.commit( |
| 60 | 'auth/setStripeProvider', |
| 61 | { |
| 62 | id: '', |
| 63 | email: '', |
| 64 | type: '', |
| 65 | completed: false, |
| 66 | } |
| 67 | ) |
| 68 | |
| 69 | store.commit('employee/setStripeConnect', null) |
| 70 | }).catch((error) => { |
| 71 | console.log(error) |
| 72 | }).finally(() => { |
| 73 | store.commit('auth/setStripeLoading', false) |
| 74 | }) |
| 75 | } |
| 76 | |
| 77 | function useStripePreview (store) { |
| 78 | let stripeProvider = store.getters['auth/getStripeProvider'] |
| 79 | |
| 80 | store.commit('auth/setStripeLoading', true) |
| 81 | |
| 82 | if (stripeProvider.type === 'standard') { |
| 83 | window.open('https://dashboard.stripe.com/' + stripeProvider.id, '_blank') |
| 84 | |
| 85 | store.commit('auth/setStripeLoading', false) |
| 86 | } else if (stripeProvider.type === 'express') { |
| 87 | httpClient.post( |
| 88 | '/stripe/dashboard/' + store.getters['auth/getProfile'].id, |
| 89 | useAuthorizationHeaderObject(store) |
| 90 | ).then((response) => { |
| 91 | if (response.data.data.url) { |
| 92 | window.open(response.data.data.url, '_blank') |
| 93 | } |
| 94 | }).catch((error) => { |
| 95 | console.log(error) |
| 96 | }).finally(() => { |
| 97 | store.commit('auth/setStripeLoading', false) |
| 98 | }) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | export { |
| 103 | useStripeSync, |
| 104 | useStripeConnect, |
| 105 | useStripeDisconnect, |
| 106 | useStripePreview, |
| 107 | } |
| 108 |