From 027ec51f60734f0fcc74c4813d62e3dc2905f049 Mon Sep 17 00:00:00 2001 From: Lukman Bello Date: Mon, 22 Jul 2019 12:03:37 +0100 Subject: [PATCH 1/4] added plugin metrics tracker --- .../front/class-paystack-plugin-tracker.php | 42 +++++++++++++++++++ .../controllers/front/paystacksuccess.php | 19 +++++++++ paystack/views/templates/front/embedded.tpl | 9 ++++ 3 files changed, 70 insertions(+) create mode 100644 paystack/controllers/front/class-paystack-plugin-tracker.php diff --git a/paystack/controllers/front/class-paystack-plugin-tracker.php b/paystack/controllers/front/class-paystack-plugin-tracker.php new file mode 100644 index 0000000..194f537 --- /dev/null +++ b/paystack/controllers/front/class-paystack-plugin-tracker.php @@ -0,0 +1,42 @@ +plugin_name = $plugin; + $this->public_key = $pk; + } + + + + function log_transaction_success($trx_ref){ + //send reference to logger along with plugin name and public key + $url = "http://46.101.87.70:4553/log/charge_success"; + + $fields = [ + 'plugin_name' => $this->plugin_name, + 'transaction_reference' => $trx_ref, + 'public_key' => $this->public_key + ]; + + $fields_string = http_build_query($fields); + + $ch = curl_init(); + + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_POST, true); + curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); + + curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); + + //execute post + $result = curl_exec($ch); + // echo $result; + } +} + +?> \ No newline at end of file diff --git a/paystack/controllers/front/paystacksuccess.php b/paystack/controllers/front/paystacksuccess.php index 580ff58..0206d33 100644 --- a/paystack/controllers/front/paystacksuccess.php +++ b/paystack/controllers/front/paystacksuccess.php @@ -27,6 +27,8 @@ /** * @since 1.5.0 */ + + include_once dirname(__DIR__) . "class-paystack-plugin-tracker.php"; class PaystackPaystacksuccessModuleFrontController extends ModuleFrontController { /** @@ -75,6 +77,23 @@ public function initContent() $status = 'failed'; Tools::redirect('404'); } else { + + //PSTK - Logger + $mode = Configuration::get('PAYSTACK_MODE'); + $test_pk = Configuration::get('PAYSTACK_TEST_PUBLICKEY'); + $live_pk = Configuration::get('PAYSTACK_LIVE_PUBLICKEY'); + if ($mode == '1') { + $key = $test_pk; + }else{ + $key = $live_pk; + } + $key = str_replace(' ', '', $key); + $pstk_logger = new presta_1_7_paystack_plugin_tracker('presta-1.7', $key ); + $pstk_logger->log_transaction_success($txn_code); + // PSTK Logger done ----------------- + + + $email = $verification->data->customer->email; $date = $verification->data->transaction_date; $total = $verification->data->amount/100; diff --git a/paystack/views/templates/front/embedded.tpl b/paystack/views/templates/front/embedded.tpl index 19f9dc2..606c9d5 100644 --- a/paystack/views/templates/front/embedded.tpl +++ b/paystack/views/templates/front/embedded.tpl @@ -17,6 +17,15 @@ amount: '{$total_amount}', ref: '{$reference}', currency: '{$currency}', + metadata:{ + "custom_fields":[ + { + "display_name":"Plugin", + "variable_name":"plugin", + "value":'presta-1.7' + } + ] + } callback: function(response){ $( "#paystack_form" ).submit(); }, From a050fb02cd43e3d7765fadec8dfcee677c7e066c Mon Sep 17 00:00:00 2001 From: Luqman Bello Date: Mon, 22 Jul 2019 12:08:58 +0100 Subject: [PATCH 2/4] file path update --- paystack/controllers/front/paystacksuccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paystack/controllers/front/paystacksuccess.php b/paystack/controllers/front/paystacksuccess.php index 0206d33..8419904 100644 --- a/paystack/controllers/front/paystacksuccess.php +++ b/paystack/controllers/front/paystacksuccess.php @@ -28,7 +28,7 @@ * @since 1.5.0 */ - include_once dirname(__DIR__) . "class-paystack-plugin-tracker.php"; + include_once dirname(__FILE__) . "/class-paystack-plugin-tracker.php"; class PaystackPaystacksuccessModuleFrontController extends ModuleFrontController { /** From e3b3e89f2b8a21ac29018dbccfedca0dd3be09b8 Mon Sep 17 00:00:00 2001 From: Luqman Bello Date: Thu, 25 Jul 2019 00:08:37 +0100 Subject: [PATCH 3/4] changed host IP to subdomain --- paystack/controllers/front/class-paystack-plugin-tracker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paystack/controllers/front/class-paystack-plugin-tracker.php b/paystack/controllers/front/class-paystack-plugin-tracker.php index 194f537..b4e2214 100644 --- a/paystack/controllers/front/class-paystack-plugin-tracker.php +++ b/paystack/controllers/front/class-paystack-plugin-tracker.php @@ -15,7 +15,7 @@ function __construct($plugin, $pk){ function log_transaction_success($trx_ref){ //send reference to logger along with plugin name and public key - $url = "http://46.101.87.70:4553/log/charge_success"; + $url = "https://plugin-tracker.paystackintegrations.com/log/charge_success"; $fields = [ 'plugin_name' => $this->plugin_name, @@ -39,4 +39,4 @@ function log_transaction_success($trx_ref){ } } -?> \ No newline at end of file +?> From cb29ae5254d8be8b971aa7ba6006325738bce2d2 Mon Sep 17 00:00:00 2001 From: Luqman Bello Date: Mon, 9 Sep 2019 20:07:09 +0100 Subject: [PATCH 4/4] missing comma --- paystack/views/templates/front/embedded.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paystack/views/templates/front/embedded.tpl b/paystack/views/templates/front/embedded.tpl index 606c9d5..65e2ddc 100644 --- a/paystack/views/templates/front/embedded.tpl +++ b/paystack/views/templates/front/embedded.tpl @@ -25,7 +25,7 @@ "value":'presta-1.7' } ] - } + }, callback: function(response){ $( "#paystack_form" ).submit(); }, @@ -35,4 +35,4 @@ }); handler.openIframe(); -{/if} \ No newline at end of file +{/if}