Skip to content

Commit 15d48dd

Browse files
authored
Merge pull request #61 from lukman008/master
Added plugin metrics tracker
2 parents 13b340c + e7784e4 commit 15d48dd

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

public/class-paystack-forms-public.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require_once ABSPATH . "wp-admin" . '/includes/image.php';
44
require_once ABSPATH . "wp-admin" . '/includes/file.php';
55
require_once ABSPATH . "wp-admin" . '/includes/media.php';
6+
include_once plugin_dir_path(__FILE__) . 'class-paystack-plugin-tracker.php';
7+
68

79
class Kkd_Pff_Paystack_Public
810
{
@@ -1620,7 +1622,9 @@ function kkd_pff_paystack_submit_action()
16201622
);
16211623

16221624
//-------------------------------------------------------------------------------------------
1623-
1625+
1626+
// $pstk_logger = new paystack_plugin_tracker('pff-paystack', Kkd_Pff_Paystack_Public::fetchPublicKey());
1627+
// $pstk_logger->log_transaction_attempt($code);
16241628

16251629
echo json_encode($response);
16261630
die();
@@ -1804,6 +1808,8 @@ function kkd_pff_paystack_confirm_payment()
18041808
if ($result == 'success') {
18051809
///
18061810
//Create Plan
1811+
$pstk_logger = new kkd_pff_paystack_plugin_tracker('pff-paystack', Kkd_Pff_Paystack_Public::fetchPublicKey());
1812+
$pstk_logger->log_transaction_success($code);
18071813
$enabled_custom_plan = get_post_meta($payment_array->post_id, '_startdate_enabled', true);
18081814
if ($enabled_custom_plan == 1) {
18091815
$mode = esc_attr(get_option('mode'));
@@ -2025,6 +2031,9 @@ function kkd_pff_paystack_rconfirm_payment()
20252031
}
20262032

20272033
if ($result == 'success') {
2034+
//Log to amplitude
2035+
$pstk_logger = new paystack_plugin_tracker('pff-paystack', Kkd_Pff_Paystack_Public::fetchPublicKey());
2036+
$pstk_logger->log_transaction_success($code);
20282037
$sendreceipt = get_post_meta($payment_array->post_id, '_sendreceipt', true);
20292038
if ($sendreceipt == 'yes') {
20302039
$decoded = json_decode($payment_array->metadata);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
class kkd_pff_paystack_plugin_tracker {
3+
var $public_key;
4+
var $plugin_name;
5+
function __construct($plugin, $pk){
6+
//configure plugin name
7+
//configure public key
8+
$this->plugin_name = $plugin;
9+
$this->public_key = $pk;
10+
}
11+
12+
13+
14+
function log_transaction_success($trx_ref){
15+
//send reference to logger along with plugin name and public key
16+
$url = "https://plugin-tracker.paystackintegrations.com/log/charge_success";
17+
18+
$fields = [
19+
'plugin_name' => $this->plugin_name,
20+
'transaction_reference' => $trx_ref,
21+
'public_key' => $this->public_key
22+
];
23+
24+
$fields_string = http_build_query($fields);
25+
26+
$ch = curl_init();
27+
28+
curl_setopt($ch,CURLOPT_URL, $url);
29+
curl_setopt($ch,CURLOPT_POST, true);
30+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
31+
32+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
33+
34+
//execute post
35+
$result = curl_exec($ch);
36+
// echo $result;
37+
}
38+
}

public/js/paystack-forms-public.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function KkdPffPaystackFee() {
2-
2+
33
this.DEFAULT_PERCENTAGE = 0.015;
44
this.DEFAULT_ADDITIONAL_CHARGE = 10000;
55
this.DEFAULT_THRESHOLD = 250000;
@@ -377,6 +377,11 @@ function KkdPffPaystackFee() {
377377
dataType: "JSON",
378378
success: function (data) {
379379
$.unblockUI();
380+
data.custom_fields.push({
381+
"display_name":"Plugin",
382+
"variable_name":"plugin",
383+
"value":"pff-paystack"
384+
})
380385
if (data.result == "success") {
381386
var names = data.name.split(" ");
382387
var firstName = names[0] || "";
@@ -555,6 +560,11 @@ function KkdPffPaystackFee() {
555560
processData: false,
556561
dataType: "JSON",
557562
success: function (data) {
563+
data.custom_fields.push({
564+
"display_name":"Plugin",
565+
"variable_name":"plugin",
566+
"value":"pff-paystack"
567+
})
558568
$.unblockUI();
559569
if (data.result == "success") {
560570
var names = data.name.split(" ");

0 commit comments

Comments
 (0)