Skip to content

Commit

Permalink
Merge pull request #12 from lukman008/master
Browse files Browse the repository at this point in the history
added plugin metrics tracker
  • Loading branch information
lukman008 authored Sep 9, 2019
2 parents 863c21e + cb29ae5 commit 4625848
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
42 changes: 42 additions & 0 deletions paystack/controllers/front/class-paystack-plugin-tracker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

// Add a prefix to this class name to avoid conflict with other plugins
class presta_1_7_paystack_plugin_tracker {
var $public_key;
var $plugin_name;
function __construct($plugin, $pk){
//configure plugin name
//configure public key
$this->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 = "https://plugin-tracker.paystackintegrations.com/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;
}
}

?>
19 changes: 19 additions & 0 deletions paystack/controllers/front/paystacksuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
/**
* @since 1.5.0
*/

include_once dirname(__FILE__) . "/class-paystack-plugin-tracker.php";
class PaystackPaystacksuccessModuleFrontController extends ModuleFrontController
{
/**
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion paystack/views/templates/front/embedded.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -26,4 +35,4 @@
});
handler.openIframe();
</script>
{/if}
{/if}

0 comments on commit 4625848

Please sign in to comment.