Skip to content

Commit 0fef381

Browse files
authored
Merge pull request #6 from lukman008/master
added plugin metrics tracker
2 parents 284cb62 + d236609 commit 0fef381

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

modules/gateways/callback/paystack.php

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/ ********************************************************************* \
66
* *
77
* Paystack Payment Gateway *
8-
* Version: 1.0.1 *
8+
* Version: 1.0.1 *
99
* Build Date: 18 May 2017 *
1010
* *
1111
************************************************************************
@@ -16,6 +16,46 @@
1616
\ ********************************************************************* /
1717
**/
1818

19+
20+
class whmcs_paystack_plugin_tracker {
21+
var $public_key;
22+
var $plugin_name;
23+
function __construct($plugin, $pk){
24+
//configure plugin name
25+
//configure public key
26+
$this->plugin_name = $plugin;
27+
$this->public_key = $pk;
28+
}
29+
30+
31+
32+
function log_transaction_success($trx_ref){
33+
//send reference to logger along with plugin name and public key
34+
$url = "https://plugin-tracker.paystackintegrations.com/log/charge_success";
35+
36+
$fields = [
37+
'plugin_name' => $this->plugin_name,
38+
'transaction_reference' => $trx_ref,
39+
'public_key' => $this->public_key
40+
];
41+
42+
$fields_string = http_build_query($fields);
43+
44+
$ch = curl_init();
45+
46+
curl_setopt($ch,CURLOPT_URL, $url);
47+
curl_setopt($ch,CURLOPT_POST, true);
48+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
49+
50+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
51+
52+
//execute post
53+
$result = curl_exec($ch);
54+
// echo $result;
55+
}
56+
}
57+
58+
1959
// Require libraries needed for gateway module functions.
2060
require_once __DIR__ . '/../../../init.php';
2161
require_once __DIR__ . '/../../../includes/gatewayfunctions.php';
@@ -142,7 +182,23 @@
142182
case 'subscription.disable':
143183
break;
144184
case 'charge.success':
185+
145186
$trxref = $event->data->reference;
187+
188+
//PSTK Logger
189+
190+
if ($gatewayParams['testMode'] == 'on') {
191+
$pk = $gatewayParams['testPublicKey'];
192+
} else {
193+
$pk = $gatewayParams['livePublicKey'];
194+
}
195+
$pstk_logger = new whmcs_paystack_plugin_tracker('whmcs',$pk );
196+
$pstk_logger->log_transaction_success($trxref);
197+
198+
199+
//-------------------------------------
200+
201+
146202
$order_details = explode( '_', $trxref);
147203
$invoiceId = (int) $order_details[0];
148204

@@ -180,6 +236,21 @@
180236
. "\r\nInvoice ID: " . $invoiceId
181237
. "\r\nStatus: succeeded";
182238
logTransaction($gatewayModuleName, $output, "Successful");
239+
240+
241+
//PSTK Logger
242+
243+
if ($gatewayParams['testMode'] == 'on') {
244+
$pk = $gatewayParams['testPublicKey'];
245+
} else {
246+
$pk = $gatewayParams['livePublicKey'];
247+
}
248+
$pstk_logger_ = new whmcs_paystack_plugin_tracker('whmcs',$pk );
249+
$pstk_logger_->log_transaction_success($trxref);
250+
251+
252+
//-------------------------------------
253+
183254
}
184255
$success = true;
185256
} else {

modules/gateways/paystack.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ function paystack_link($params)
184184
amount: '.$amountinkobo.',
185185
currency: \''.addslashes(trim($currency)).'\',
186186
ref:\''.$txnref.'\',
187+
metadata:{
188+
"custom_fields":[
189+
{
190+
"display_name":"Plugin",
191+
"variable_name":"plugin",
192+
"value":"whmcs"
193+
}
194+
]
195+
},
187196
callback: function(response){
188197
$(\'div.alert.alert-info.text-center\').hide();
189198
$(\'.payment-btn-container2\').hide();

0 commit comments

Comments
 (0)