Skip to content

Commit

Permalink
Merge pull request #1 from lukman008/master
Browse files Browse the repository at this point in the history
added plugin metrics tracker. done.
  • Loading branch information
Daydah authored Sep 13, 2019
2 parents ff9e085 + cf2bae5 commit b50d53f
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions paystackpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@
// import the JPlugin class
jimport('joomla.event.plugin');


// Add a prefix to this class name to avoid conflict with other plugins
class joomla_pp_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;
}
}


class plgPayperDownloadPlusPaystackPay extends JPlugin
{
public function __construct(&$subject, $config = array())
Expand Down Expand Up @@ -97,19 +130,14 @@ function payWithPaystack(){
$tosend .= 'metadata: {
"ecommerce_platform":"Joomla 3",
"payment_plugin": "Paystackpay for PayPerDownload",
"author": "Daydah",';
/* custom_fields: [
"author": "Daydah",
custom_fields: [
{
display_name: "Ecommerce Platform",
variable_name: "ecommerce_platform",
value: "Joomla 3"
}
{
display_name: "Payment plugin",
variable_name: "payment_plugin",
display_name: "Plugin",
variable_name: "plugin",
value: "Paystackpay for PayPerDownload"
}
] */
] ';
$tosend .=
' },
callback: function(response){
Expand Down Expand Up @@ -173,6 +201,7 @@ public function onPaymentReceived($gateway, &$dealt, &$payed,
$pmntinfo1 = $this->getPaystackPaymentInfo();

$secret_key = $pmntinfo1->secret_key;
$public_key = $pmntinfo1->public_key;
if($secret_key && $thetransactionid)
{
try
Expand All @@ -195,6 +224,14 @@ public function onPaymentReceived($gateway, &$dealt, &$payed,
(strpos($transData->reference, $thetransactionid) === 0)
)
{

//pstk-logger
$pstk_logger = new joomla_pp_paystack_plugin_tracker('Paystackpay for PayPerDownload', $public_key);
$pstk_logger->log_transaction_success($sentreference);
//-------------



// Update order status - From pending to complete
$amount = $amount;// / 100.0;
$payed = true;
Expand Down

0 comments on commit b50d53f

Please sign in to comment.