Skip to content

Commit 6727af9

Browse files
author
Toyeeb
committed
Added API Tracker
1 parent e2a6b44 commit 6727af9

File tree

5 files changed

+173
-37
lines changed

5 files changed

+173
-37
lines changed

dev/serve.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import Vue from 'vue';
22
import Dev from './serve.vue';
3+
import Flutterwave from "../src/entry";
34

45
Vue.config.productionTip = false;
56

7+
Vue.use(Flutterwave, { publicKey: 'FLWPUBK_TEST-0b04581c8d73fd08d5c720e1e0f803b4-X' } )
8+
9+
10+
611
new Vue({
712
render: (h) => h(Dev),
813
}).$mount('#app');

dev/serve.vue

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,52 @@ export default Vue.extend({
66
name: 'ServeDev',
77
components: {
88
FlutterwavePayButton,
9+
},
10+
data(){
11+
return {
12+
paymentData: {
13+
tx_ref: this.generateReference(),
14+
amount: 10,
15+
currency: 'NGN',
16+
payment_options: '',
17+
redirect_url: '',
18+
meta: {
19+
'counsumer_id': '7898',
20+
'consumer_mac': 'kjs9s8ss7dd'
21+
},
22+
customer: {
23+
name: 'Demo Customer Name',
24+
email: 'customer@mail.com',
25+
phone_number: '0818450***44'
26+
} ,
27+
customizations: {
28+
title: 'Customization Title',
29+
description: 'Customization Description',
30+
logo: 'https://flutterwave.com/images/logo-colored.svg'
31+
},
32+
callback: this.makePaymentCallback,
33+
onclose: this.closedPaymentModal
34+
}
35+
}
36+
} ,
37+
methods: {
38+
makePaymentCallback(response) {
39+
console.log("Pay", response)
40+
},
41+
closedPaymentModal() {
42+
console.log('payment is closed');
43+
},
44+
generateReference(){
45+
let date = new Date()
46+
return date.getTime().toString();
47+
}
948
}
1049
});
1150
</script>
1251

52+
1353
<template>
14-
<div id="app">
15-
<flutterwave-pay-button> Test </flutterwave-pay-button>
54+
<div>
55+
<flutterwave-pay-button v-bind="paymentData" > Click To Pay </flutterwave-pay-button>
1656
</div>
1757
</template>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flutterwave-vue-v3",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"private": false,
55
"description": "Flutterwave official Vue library to accept payment via Card , USSD, QrCode etc.",
66
"author": "Flutterwave",

src/api_tracker.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
export class ApiTracker {
2+
3+
static trackingEndPoint = 'https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/staging/sendevent';
4+
5+
static packageVersion = '1.0.2';
6+
static language = 'Vue V3'
7+
8+
/* static trackingFeatures = {
9+
10+
'initiateCardCharge': 'Initiate-Card-charge',
11+
'initiateCardChargeError': 'Initiate-Card-charge-error',
12+
'validateCardCharge': 'Validate-Card-charge',
13+
'validateCardChargeError': 'Validate-Card-charge-error',
14+
'verifyCardCharge': 'Verify-Card-charge',
15+
'verifyCardChargeError': 'Verify-Card-charge-error',
16+
'initiateAccountCharge': 'Initiate-Account-charge',
17+
'initiateAccountChargeError': 'Initiate-Account-charge-error',
18+
'accountChargeValidate': 'Account-charge-validate',
19+
'accountChargeValidateError': 'Account-charge-validate-error',
20+
'accountChargeVerify': 'Account-charge-verify',
21+
'accountChargeVerifyError': 'Account-charge-verify-error',
22+
23+
}*/
24+
25+
26+
constructor() {
27+
}
28+
/* {
29+
paymentData: object | any
30+
,
31+
response: object | any
32+
responseTime: string
33+
}*/
34+
35+
static track(data) {
36+
37+
const trackingData = {
38+
publicKey: data.paymentData.public_key,
39+
language: this.language,
40+
version: this.packageVersion,
41+
title: '',
42+
message: '0' // data.responseTime
43+
44+
}
45+
46+
const paymentOptions = data.paymentData.payment_options || ''
47+
const paymentOptionsArray = paymentOptions ? paymentOptions.split(',') : []
48+
49+
let title = ''
50+
51+
if (paymentOptionsArray.length === 0) {
52+
title = 'Initiate-Charge-Dashboard'
53+
} else if (paymentOptionsArray.length === 1) {
54+
title = 'Initiate-Charge-' + paymentOptions
55+
56+
} else {
57+
title = 'Initiate-Charge-Multiple'
58+
59+
}
60+
61+
trackingData.title = data.response.status === 'successful' ? title : title + '-error'
62+
63+
64+
this.submitTracking(trackingData)
65+
66+
}
67+
68+
static submitTracking(trackingData) {
69+
fetch(this.trackingEndPoint, {
70+
method: 'POST',
71+
body: JSON.stringify(trackingData)
72+
}).then((res) => {
73+
})
74+
}
75+
}

src/entry.js

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,67 @@
11
// Import vue components
22
import * as components from '@/lib-components/index';
3+
import {ApiTracker} from "./api_tracker";
34

45
// 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+
})
2945
};
3046

3147
// Create module definition for Vue.use()
3248
const Flutterwave = {
33-
install,
49+
install,
3450
};
3551

3652
// To auto-install on non-es builds, when vue is found
3753
// eslint-disable-next-line no-redeclare
3854
/* global window, global */
3955
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+
}
4965
}
5066
// Default export is library as a whole, registered via Vue.use()
5167
export default Flutterwave;

0 commit comments

Comments
 (0)