|
1 | 1 | // Import vue components |
2 | 2 | import * as components from '@/lib-components/index'; |
| 3 | +import {ApiTracker} from "./api_tracker"; |
3 | 4 |
|
4 | 5 | // install function executed by Vue.use() |
5 | | -const install = function installFlutterwaveVueV3(Vue, { publicKey = ''}) { |
6 | | - if (install.installed) return; |
7 | | - install.installed = true; |
8 | | - Object.entries(components).forEach(([componentName, component]) => { |
9 | | - Vue.component(componentName, component); |
10 | | - }); |
11 | | - Vue.mixin({ |
12 | | - mounted() { |
13 | | - const inlineSdk = "https://checkout.flutterwave.com/v3.js"; |
14 | | - const script = document.createElement('script') |
15 | | - script.src = inlineSdk; |
16 | | - if (!document.querySelector(`[src="${inlineSdk}"]`)) { |
17 | | - document.body.appendChild(script) |
18 | | - } |
19 | | - }, |
20 | | - methods: { |
21 | | - payWithFlutterwave(paymentParams) { |
22 | | - window.FlutterwaveCheckout({ |
23 | | - ...paymentParams, |
24 | | - public_key: paymentParams.public_key || publicKey, |
25 | | - }) |
26 | | - }, |
27 | | - } |
28 | | - }) |
| 6 | +const install = function installFlutterwaveVueV3(Vue, {publicKey = ''}) { |
| 7 | + if (install.installed) return; |
| 8 | + install.installed = true; |
| 9 | + Object.entries(components).forEach(([componentName, component]) => { |
| 10 | + Vue.component(componentName, component); |
| 11 | + }); |
| 12 | + Vue.mixin({ |
| 13 | + mounted() { |
| 14 | + const inlineSdk = "https://checkout.flutterwave.com/v3.js"; |
| 15 | + const script = document.createElement('script') |
| 16 | + script.src = inlineSdk; |
| 17 | + if (!document.querySelector(`[src="${inlineSdk}"]`)) { |
| 18 | + document.body.appendChild(script) |
| 19 | + } |
| 20 | + }, |
| 21 | + methods: { |
| 22 | + payWithFlutterwave(paymentParams) { |
| 23 | + |
| 24 | + let payData = { |
| 25 | + ...paymentParams, |
| 26 | + public_key: paymentParams.public_key || publicKey, |
| 27 | + callback: (response) => { |
| 28 | + |
| 29 | + ApiTracker.track( |
| 30 | + { |
| 31 | + paymentData: payData, |
| 32 | + response: response, |
| 33 | + responseTime: 1000 |
| 34 | + }) |
| 35 | + |
| 36 | + paymentParams.callback(response) |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + window.FlutterwaveCheckout(payData) |
| 42 | + }, |
| 43 | + } |
| 44 | + }) |
29 | 45 | }; |
30 | 46 |
|
31 | 47 | // Create module definition for Vue.use() |
32 | 48 | const Flutterwave = { |
33 | | - install, |
| 49 | + install, |
34 | 50 | }; |
35 | 51 |
|
36 | 52 | // To auto-install on non-es builds, when vue is found |
37 | 53 | // eslint-disable-next-line no-redeclare |
38 | 54 | /* global window, global */ |
39 | 55 | if ('false' === process.env.ES_BUILD) { |
40 | | - let GlobalVue = null; |
41 | | - if (typeof window !== 'undefined') { |
42 | | - GlobalVue = window.Vue; |
43 | | - } else if (typeof global !== 'undefined') { |
44 | | - GlobalVue = global.Vue; |
45 | | - } |
46 | | - if (GlobalVue) { |
47 | | - GlobalVue.use(Flutterwave); |
48 | | - } |
| 56 | + let GlobalVue = null; |
| 57 | + if (typeof window !== 'undefined') { |
| 58 | + GlobalVue = window.Vue; |
| 59 | + } else if (typeof global !== 'undefined') { |
| 60 | + GlobalVue = global.Vue; |
| 61 | + } |
| 62 | + if (GlobalVue) { |
| 63 | + GlobalVue.use(Flutterwave); |
| 64 | + } |
49 | 65 | } |
50 | 66 | // Default export is library as a whole, registered via Vue.use() |
51 | 67 | export default Flutterwave; |
|
0 commit comments