Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #57 chore: Improve codebase and add webhooks support #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion code/plugins/payumoney/en-GB/en-GB.plg_payment_payumoney.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ PAYUMONEY_PINFO="Payment For Order %s"
PAYUMONEY_NO="No"
PAYUMONEY_YES="Yes"
PAYUMONEY_KEY="Merchant Key"
PAYUMONEY_KEY_DESC="You can get this Merchant Key from your Payu account"
PAYUMONEY_KEY_DESC="You can get this Merchant Key from your PayU account"
; store log
PLG_PAYUMONEY_NO="No"
PLG_PAYUMONEY_YES="Yes"
PLG_PAYUMONEY_WRITE_LOG="Log payment gateway responses"
PLG_PAYUMONEY_WRITE_LOG_DESC="Turn this on only if payment not working correctly & you want do debug it."
PAYUMONEY_LAYOUT="Checkout Layout"
PAYUMONEY_LAYOUT_DESC="Plugin layout for the payment. Bolt checkout will bring on-site payment experience."
PAYUMONEY_LAYOUT_REDIRECTION="Redirection (Off-site)"
PAYUMONEY_LAYOUT_BOLT="Bolt (On-site)"
120 changes: 67 additions & 53 deletions code/plugins/payumoney/payumoney.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<?php
/**
* @copyright Copyright (c) 2009 - 2013 TechJoomla. All rights reserved.
* @license GNU General Public License version 2, or later
* @package Joomla_Payments
* @subpackage PayuMoney
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

// No direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\String\StringHelper;
use Joomla\CMS\HTML\HTMLHelper;

require_once JPATH_SITE . '/plugins/payment/payumoney/payumoney/helper.php';

$lang = JFactory::getLanguage();
$lang = Factory::getLanguage();
$lang->load('plg_payment_payumoney', JPATH_ADMINISTRATOR);

/**
Expand All @@ -20,29 +28,19 @@
* @subpackage site
* @since 2.2
*/
class PlgPaymentPayuMoney extends JPlugin
class PlgPaymentPayuMoney extends CMSPlugin
{
/**
* Constructor
* Supported payumoney payment statuses
*
* @param string &$subject subject
*
* @param string $config config
* @var array
* @since 1.0.0
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);

// Set the language in the class
$config = JFactory::getConfig();

// Define Payment Status codes in payu And Respective Alias in Framework
$this->responseStatus = array(
private $responseStatus = array(
'success' => 'C',
'pending' => 'P',
'failure' => 'E'
);
}
);

/**
* Build Layout path
Expand All @@ -55,20 +53,21 @@ public function __construct(&$subject, $config)
*/
public function buildLayoutPath($layout)
{
$app = JFactory::getApplication();
$core_file = dirname(__FILE__) . '/' . $this->_name . '/tmpl/default.php';
$app = Factory::getApplication();

$coreFile = dirname(__FILE__) . '/' . $this->_name . '/tmpl/' . $layout . '.php';

$override = JPATH_BASE . '/' . 'templates' . '/' . $app->getTemplate() . '/html/plugins/' .
$this->_type . '/' . $this->_name . '/' . $layout . '.php';
$this->_type . '/' . $this->_name . '/' . $layout . '.php';

if (JFile::exists($override))
{
return $override;
}
else
{
return $core_file;
}
if (File::exists($override))
{
return $override;
}
else
{
return $coreFile;
}
}

/**
Expand All @@ -84,6 +83,8 @@ public function buildLayoutPath($layout)
public function buildLayout($vars, $layout = 'default')
{
// Load the layout & push variables
$layout = $this->params->get('layout', 'default');

ob_start();
$layout = $this->buildLayoutPath($layout);

Expand Down Expand Up @@ -160,16 +161,16 @@ public function onTP_Processpayment($data, $vars = array())
$error['desc'] = '';

// Compare response order id and send order id in notify URL
$res_orderid = '';
$resOrderid = '';

if ($isValid)
{
$res_orderid = $data['udf1'];
$resOrderid = $data['udf1'];

if (!empty($vars) && $res_orderid != $vars->order_id)
if (!empty($vars) && $resOrderid != $vars->order_id)
{
$isValid = false;
$error['desc'] = "ORDER_MISMATCH" . "Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $res_orderid;
$error['desc'] = "ORDER_MISMATCH" . "Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $resOrderid;
}
}

Expand All @@ -179,16 +180,16 @@ public function onTP_Processpayment($data, $vars = array())
if (!empty($vars))
{
// Check that the amount is correct
$order_amount = (float) $vars->amount;
$orderAmount = (float) $vars->amount;
$retrunamount = (float) $data['amount'];
$epsilon = 0.01;

if (($order_amount - $retrunamount) > $epsilon)
if (($orderAmount - $retrunamount) > $epsilon)
{
// Change response status to ERROR FOR AMOUNT ONLY
$data['status'] = 'failure';
$isValid = false;
$error['desc'] = "ORDER_AMOUNT_MISTMATCH - order amount= " . $order_amount . ' response order amount = ' . $retrunamount;
$error['desc'] = "ORDER_AMOUNT_MISTMATCH - order amount= " . $orderAmount . ' response order amount = ' . $retrunamount;
}
}
}
Expand All @@ -203,14 +204,14 @@ public function onTP_Processpayment($data, $vars = array())
$error['desc'] = (isset($data['field9']) ? $data['field9'] : '');

$result = array(
'order_id' => $data['udf1'],
'transaction_id' => $data['mihpayid'],
'buyer_email' => $data['email'],
'status' => $data['status'],
'txn_type' => $data['mode'],
'total_paid_amt' => $data['amount'],
'raw_data' => $data,
'error' => $error
'order_id' => $data['udf1'],
'transaction_id' => $data['mihpayid'],
'buyer_email' => $data['email'],
'status' => $data['status'],
'txn_type' => $data['mode'],
'total_paid_amt' => $data['amount'],
'raw_data' => $data,
'error' => $error
);

return $result;
Expand All @@ -219,17 +220,17 @@ public function onTP_Processpayment($data, $vars = array())
/**
* This function transalate the response got from payment getway
*
* @param object $payment_status payment_status
* @param object $paymentStatus payment_status
*
* @since 2.2
*
* @return string value
*/
public function translateResponse($payment_status)
public function translateResponse($paymentStatus)
{
foreach ($this->responseStatus as $key => $value)
{
if ($key == $payment_status)
if ($key == StringHelper::strtolower($paymentStatus))
{
return $value;
}
Expand All @@ -246,12 +247,12 @@ public function translateResponse($payment_status)
*/
public function onTP_Storelog($data)
{
$log_write = $this->params->get('log_write', '0');
$logWrite = $this->params->get('log_write', '0');

if ($log_write == 1)
if ($logWrite == 1)
{
$plgPaymentPayuMoneyHelper = new plgPaymentPayuMoneyHelper;
$log = $plgPaymentPayuMoneyHelper->Storelog($this->_name, $data);
$plgPaymentPayuMoneyHelper->Storelog($this->_name, $data);
}
}

Expand All @@ -277,4 +278,17 @@ public function preFormatingData($vars)
}
}
}

/**
* Process Webhooks data and return the array
*
* @return array formatted webhooks data
*/
public function onTP_ProcessInputData()
{
$data = Factory::getApplication()->input->json->getArray();
$data['order_id'] = $data['udf1'];

return $data;
}
}
54 changes: 28 additions & 26 deletions code/plugins/payumoney/payumoney.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<extension version="3.0" type="plugin" group="payment" method="upgrade">
<name>Payment - PayU Biz</name>
<author>Techjoomla</author>
<creationDate>28th Aug 2016</creationDate>
<copyright></copyright>
<copyright />
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<authorEmail />
<authorUrl />
<version>1.0</version>
<description>PayU payment plugin</description>
<files>
Expand All @@ -16,34 +16,36 @@
<languages>
<language tag="en-GB">en-GB/en-GB.plg_payment_payumoney.ini</language>
</languages>


<params>
<params>
<param name="plugin_name" type="text" default="Payu Credit Card/Debit Card/Net Banking" label="PAYUMONEY_PLG_NAME" description="" />
<param name="key" type="text" default="" label="PAYUMONEY_EMAIL" description="PAYUMONEY_EMAIL_DESC"/>
<param name="salt" type="text" default="" label="PAYUMONEY_SALT" description="PAYUMONEY_SALT_DESC"/>
<param type="spacer" />
<param name="key" type="text" default="" label="PAYUMONEY_EMAIL" description="PAYUMONEY_EMAIL_DESC" />
<param name="salt" type="text" default="" label="PAYUMONEY_SALT" description="PAYUMONEY_SALT_DESC" />
<param type="spacer" />
<param name="sandbox" type="radio" default="0" label="PAYUMONEY_SANDBOX" description="PAYUMONEY_SANDBOX_DESC">
<option value="0">PAYUMONEY_NO</option>
<option value="1">PAYUMONEY_YES</option>
<option value="0">PAYUMONEY_NO</option>
<option value="1">PAYUMONEY_YES</option>
</param>
</params>

<config>
<config>
<fields name="params">
<fieldset name="basic">
<field name="plugin_name" type="text" default="Payu Credit Card/Debit Card/Net Banking" label="PAYUMONEY_PLG_NAME" description="" />
<field name="key" type="text" default="" label="PAYUMONEY_KEY" description="PAYUMONEY_KEY_DESC"/>
<field name="salt" type="text" default="" label="PAYUMONEY_SALT" description="PAYUMONEY_SALT_DESC"/>
<field name="sandbox" type="radio" default="0" label="PAYUMONEY_SANDBOX" description="PAYUMONEY_SANDBOX_DESC">
<option value="0">PAYUMONEY_NO</option>
<option value="1">PAYUMONEY_YES</option>
</field>
<field name="log_write" type="radio" default="0" label="PLG_PAYUMONEY_WRITE_LOG" description="PLG_PAYUMONEY_WRITE_LOG_DESC">
<option value="0">PLG_PAYUMONEY_NO</option>
<option value="1">PLG_PAYUMONEY_YES</option>
</field>
</fieldset>
<field name="plugin_name" type="text" default="Payu Credit Card/Debit Card/Net Banking" label="PAYUMONEY_PLG_NAME" description="" />
<field name="key" type="text" default="" label="PAYUMONEY_KEY" description="PAYUMONEY_KEY_DESC" />
<field name="salt" type="text" default="" label="PAYUMONEY_SALT" description="PAYUMONEY_SALT_DESC" />
<field name="sandbox" type="radio" default="0" label="PAYUMONEY_SANDBOX" description="PAYUMONEY_SANDBOX_DESC">
<option value="0">PAYUMONEY_NO</option>
<option value="1">PAYUMONEY_YES</option>
</field>
<field name="log_write" type="radio" default="0" label="PLG_PAYUMONEY_WRITE_LOG" description="PLG_PAYUMONEY_WRITE_LOG_DESC">
<option value="0">PLG_PAYUMONEY_NO</option>
<option value="1">PLG_PAYUMONEY_YES</option>
</field>
<field name="layout" type="list" default="bolt" label="PAYUMONEY_LAYOUT" description="PAYUMONEY_LAYOUT_DESC">
<option value="default">PAYUMONEY_LAYOUT_REDIRECTION</option>
<option value="bolt">PAYUMONEY_LAYOUT_BOLT</option>
</field>
</fieldset>
</fields>
</config>
</extension>

35 changes: 20 additions & 15 deletions code/plugins/payumoney/payumoney/helper.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php
/**
* @copyright Copyright (c) 2009-2013 TechJoomla. All rights reserved.
* @license GNU General Public License version 2, or later
* @package Joomla_Payments
* @subpackage PayuMoney
*
* @author Techjoomla <[email protected]>
* @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.html.html');
jimport('joomla.plugin.helper');
jimport('joomla.html.parameter');
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Log\LogEntry;
use Joomla\CMS\Plugin\PluginHelper;

/**
* PlgPaymentBycheckHelper
Expand All @@ -30,9 +35,9 @@ class PlgPaymentPayuMoneyHelper
*/
public function buildPayuMoneyUrl($secure = true)
{
$plugin = JPluginHelper::getPlugin('payment', 'payumoney');
$plugin = PluginHelper::getPlugin('payment', 'payumoney');
$params = json_decode($plugin->params);
$url = $params->sandbox? 'test.payu.in/_payment' : 'secure.payu.in/_payment';
$url = $params->sandbox? 'sandboxsecure.payu.in/_payment' : 'secure.payu.in/_payment';

if ($secure)
{
Expand All @@ -49,28 +54,28 @@ public function buildPayuMoneyUrl($secure = true)
*
* @param array $logdata data.
*
* @since 1.0
* @return list.
* @since 1.0.0
*
* @return void
*/
public function Storelog($name, $logdata)
{
jimport('joomla.error.log');
$options = "{DATE}\t{TIME}\t{USER}\t{DESC}";
$my = JFactory::getUser();
$my = Factory::getUser();

JLog::addLogger(
Log::addLogger(
array(
'text_file' => $logdata['JT_CLIENT'] . '_' . $name . '.php',
'text_entry_format' => $options
),
JLog::INFO,
Log::INFO,
$logdata['JT_CLIENT']
);

$logEntry = new JLogEntry('Transaction added', JLog::INFO, $logdata['JT_CLIENT']);
$logEntry = new LogEntry('Transaction added', Log::INFO, $logdata['JT_CLIENT']);
$logEntry->user = $my->name . '(' . $my->id . ')';
$logEntry->desc = json_encode($logdata['raw_data']);

JLog::add($logEntry);
Log::add($logEntry);
}
}
Loading