|
5 | 5 | / ********************************************************************* \ |
6 | 6 | * * |
7 | 7 | * Paystack Payment Gateway * |
8 | | - * Version: 1.0.1 * |
| 8 | + * Version: 1.0.1 * |
9 | 9 | * Build Date: 18 May 2017 * |
10 | 10 | * * |
11 | 11 | ************************************************************************ |
|
16 | 16 | \ ********************************************************************* / |
17 | 17 | **/ |
18 | 18 |
|
| 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 | + |
19 | 59 | // Require libraries needed for gateway module functions. |
20 | 60 | require_once __DIR__ . '/../../../init.php'; |
21 | 61 | require_once __DIR__ . '/../../../includes/gatewayfunctions.php'; |
|
142 | 182 | case 'subscription.disable': |
143 | 183 | break; |
144 | 184 | case 'charge.success': |
| 185 | + |
145 | 186 | $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 | + |
146 | 202 | $order_details = explode( '_', $trxref); |
147 | 203 | $invoiceId = (int) $order_details[0]; |
148 | 204 |
|
|
180 | 236 | . "\r\nInvoice ID: " . $invoiceId |
181 | 237 | . "\r\nStatus: succeeded"; |
182 | 238 | 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 | + |
183 | 254 | } |
184 | 255 | $success = true; |
185 | 256 | } else { |
|
0 commit comments