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..b4e2214 --- /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 = "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; + } +} + +?> diff --git a/paystack/controllers/front/paystacksuccess.php b/paystack/controllers/front/paystacksuccess.php index 580ff58..8419904 100644 --- a/paystack/controllers/front/paystacksuccess.php +++ b/paystack/controllers/front/paystacksuccess.php @@ -27,6 +27,8 @@ /** * @since 1.5.0 */ + + include_once dirname(__FILE__) . "/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..65e2ddc 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(); }, @@ -26,4 +35,4 @@ }); handler.openIframe(); -{/if} \ No newline at end of file +{/if}