AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.94
Web Server : Apache
System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/voscatalogues/plugins/djcatalog2payment/paynow/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/voscatalogues/plugins/djcatalog2payment/paynow/paynow.php
<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

use Paynow\Client;
use Paynow\Environment;
use Paynow\Exception\PaynowException;
use Paynow\Service\Payment;
use Paynow\Notification;

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class plgDjcatalog2paymentPaynow extends JPlugin {
	
	public function __construct(&$subject, $config = array())
	{
		parent::__construct($subject, $config);
		require_once dirname(__FILE__).'/lib/sdk/vendor/autoload.php';
		
		$this->loadLanguage();
	}
	
	protected function isAllowed($plgInfo, $type = 'djcatalog2payment') {
		if (empty($plgInfo)) return  false;
		return (bool)($plgInfo->plugin == $this->_name && $this->_type == $type);
	}
	
	public function onContentPrepareForm($form, $data) {
		if ($form->getName() != 'com_djcatalog2.payment') {
			return ;
		}
		
		$plugin = '';
		
		if (!empty($data) && !empty($data->plugin)) {
			$plugin = $data->plugin;
		} else {
			$jform = JFactory::getApplication()->input->get('jform', array(), 'array');
			if (!empty($jform) && isset($jform['plugin'])) {
				$plugin = $jform['plugin'];
			}
		}
		
		if ($plugin != $this->_name) {
			return true;
		}
		
		return $form->loadFile(dirname(__FILE__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'configuration.xml', false);
	}
	
	public function onDJC2BeforeSaveOrder($context, $table, $isNew, $plgInfo) {
		if ($context != 'com_djcatalog2.checkout.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}
	}
	
	public function onDJC2AfterSaveOrder($context, $table, $isNew, $plgInfo) {
		if ($context != 'com_djcatalog2.checkout.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}
	}
	
	public function onDJC2CheckoutDetailsDisplay($context, $plgInfo) {
		if ($context != 'com_djcatalog2.checkout.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$html = '';
		if (trim(strip_tags($plgInfo->description)) != '' ) {
			$html = '<h4>'.$plgInfo->name.'</h4>';
			$html .= $plgInfo->description;
		}
		return $html;
	}
	
	public function onDJC2OrderDetailsDisplay($context, $order, $plgInfo) {
        if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
            return;
        }
        $app = JFactory::getApplication();
        $debug = $plgInfo->params->get('debug', false);
        
        // handling response when customer returns from Paynow
        if ($app->input->getString('paymentStatus') && $app->input->getString('paymentId')) {
        	$db = JFactory::getDbo();
        	$query = $db->getQuery(true);
        	$query->select('*');
        	$query->from('#__djc2_transactions');
        	$query->where('description='. $db->quote($app->input->getString('paymentId')));
        	$db->setQuery($query);
        	
        	$transOrder=$db->loadObject();
        	
        	if ($transOrder && $transOrder->order_id == $order->id) {
        		$status = $this->getPaymentStatus($plgInfo->params->get('apiKey'), $plgInfo->params->get('signatureKey'), $app->input->getString('paymentId'), $debug);
        		if ($status && $status->status == 'CONFIRMED') {
        			$model = JModelLegacy::getInstance('Order', 'DJCatalog2Model');
        			if ($order->status == 'A' || $order->status == 'N') {
        				
        				$transOrder->paid = 1;
        				$db->updateObject('#__djc2_transactions', $transOrder, 'id', false);
        				
        				$model->changeStatus($order, 'P', true, true, JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_PAYMENT_COMPLETED'));
        				$app->redirect(JRoute::_(DJCatalog2HelperRoute::getOrderRoute($order->id).'&token=' . $order->token));
        			}
        		}
        	}
        }
        
        $message = '';
        if ($app->input->get('view') == 'order' && $app->input->get('error')) {
            $message = JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_ERROR_TEXT');
        } else if ($app->input->get('success') == '1') {
            $message = JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_RETURN_TEXT');
        }
        
        if ($order->status != 'A' && $order->status != 'N') {
            return;
        }
        
        $html = '<div class="paynowinfo">';
        
        if ($message) {
            $html .= '<p class="paynowalert">'.$message.'</p>';
        }
        
        $html .= '<p class="payumessage">';
        $html .= JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_INFO_TEXT');
        $html .= '</p>';
        $paymentUrl = JRoute::_('index.php?option=com_djcatalog2&task=paymentProcess&oid='.$order->id.'&plg='.$plgInfo->plugin.'&plgid='.$plgInfo->id.'&Itemid=');
        $html .= '<p class="payubutton">';
        $html .= '<a href="'.$paymentUrl.'" class="button btn btn-primary payubtn">'.JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_BTN').'</a>';
        $html .= '</p>';
        $html .= '</div>';
        return $html;
    }
	
	public function onDJC2PaymentProcess($context, $order, $plgInfo) {
		if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$apiKey = $plgInfo->params->get('apiKey');
		$signatureKey = $plgInfo->params->get('signatureKey');
		$env = $plgInfo->params->get('debug', false) ? Environment::SANDBOX : Environment::PRODUCTION;
		
		if (!$apiKey || !$signatureKey) {
			throw new Exception(JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_ERROR_MISSING_PARAMS'), 400);
		}
		
		$app = JFactory::getApplication();
		$websiteName = $app->get('sitename', JURI::base());
		
		$client = new Client($apiKey, $signatureKey, $env);
		$orderReference = $order->id;
		$idempotencyKey = uniqid($orderReference . '_');
		
		$paymentData = [
			"amount" => round(100* $order->grand_total),
			"currency" => $order->currency,
			"externalId" => $orderReference,
			"description" => JText::sprintf('PLG_DJCATALOG2PAYMENT_PAYNOW_ORDER_DESCRIPTION', $order->order_number, $websiteName),
			"buyer" => [
				"email" => $order->email
			],
			"continueUrl" => JRoute::_(DJCatalogHelperRoute::getOrderRoute($order->id).'&token='.$order->token.'&success=1', false, (JUri::getInstance()->isSSL() ? 1 : -1)),
			//"notificationUrl" => JRoute::_('index.php?option=com_djcatalog2&task=paymentResponse&plg='.$plgInfo->plugin.'&plgid='.$plgInfo->id.'&oid='.$order->id.'&Itemid=', false, (JUri::getInstance()->isSSL() ? 1 : -1))
		
		];
		
		try {
			$payment = new Payment($client);
			$result = $payment->authorize($paymentData, $idempotencyKey);
		} catch (PaynowException $exception) {
			throw new Exception($exception->getMessage(), 403);
		}
		
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__djc2_transactions');
		$query->where('order_id='. $order->id);
		$query->order('id DESC');
		$db->setQuery($query, 0, 1);
		$rows = $db->loadObjectList();
		if (!empty($rows)) {
			$row = $rows[0];
			$row->description = $result->paymentId;
			$db->updateObject('#__djc2_transactions', $row, 'id', false);
		}
		
		if (!empty($result->redirectUrl)) {
			$app->redirect($result->redirectUrl);
		}
		$app->close();
		
	}
	
	public function onDJC2PaymentDiscover($context, $plgInfo) {
		if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}
		
		$signatureKey = $plgInfo->params->get('signatureKey');
		
		$payload = trim(file_get_contents('php://input'));
		$headers = getallheaders();
		$notificationData = json_decode($payload, true);
		
		try {
			new Notification($signatureKey, $payload, $headers);
		} catch (Exception $exception) {
			header('HTTP/1.1 400 Bad Request', true, 400);
		}
		
		$extOrderId = $notificationData['externalId'];
		if ($extOrderId ) {
			return (int)$extOrderId;
		}
	}
	
	public function onDJC2PaymentResponse($context, $order, $model, $plgInfo) {
		if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
			return;
		}

		$app = JFactory::getApplication();
		
		$apiKey = $plgInfo->params->get('apiKey');
		$signatureKey = $plgInfo->params->get('signatureKey');
		$debug = $plgInfo->params->get('debug', false);
		
		if (!$apiKey || !$signatureKey) {
			throw new Exception(JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_ERROR_MISSING_PARAMS'), 400);
		}
		
		$payload = trim(file_get_contents('php://input'));
		$headers = getallheaders();
		$notificationData = json_decode($payload, true);
		
		try {
			new Notification($signatureKey, $payload, $headers);
		} catch (Exception $exception) {
			header('HTTP/1.1 400 Bad Request', true, 400);
		}
		
		$paymentId = $notificationData['paymentId'];
		$status = $this->getPaymentStatus($apiKey, $signatureKey, $paymentId, $debug);
		
		if ($status && $status->status == 'CONFIRMED') {
			if ($order->status == 'A' || $order->status == 'N') {
				$model->changeStatus($order, 'P', true, true, JText::_('PLG_DJCATALOG2PAYMENT_PAYNOW_PAYMENT_COMPLETED'));
			}
		}
		
		header("HTTP/1.1 200 OK");
		$app->close();
	}
	
	protected function getPaymentStatus($apiKey, $signatureKey, $paymentId, $debug = true) {
		try{
			$client = new Client($apiKey, $signatureKey, ($debug ? Environment::SANDBOX : Environment::PRODUCTION));
			$payment = new Payment($client);
			$status = $payment->status($paymentId);
		} catch (PaynowException $exception) {
			return false;
		}
		
		return $status;
	}
	
	protected function log($data, $lbl = '') {
		if (!is_string($data) && !is_numeric($data)) {
			$data = print_r($data,true);
		}
		
		$str = ($lbl) ? $lbl . PHP_EOL  : '';
		$str .= PHP_EOL . $data . PHP_EOL;
		
		$h = fopen(dirname(__FILE__).'/log.txt', 'a');
		fwrite($h, $str);
		fclose($h);
	}
}



Anon7 - 2022
AnonSec Team