| 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/paylane/ |
Upload File : |
<?php
/**
* @version $Id: payu.php 391 2015-03-30 12:37:34Z michal $
* @package DJ-Catalog2
* @copyright Copyright (C) 2012 DJ-Extensions.com LTD, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email contact@dj-extensions.com
* @developer Michal Olczyk - michal.olczyk@design-joomla.eu
*
* DJ-Catalog2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DJ-Catalog2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DJ-Catalog2. If not, see <http://www.gnu.org/licenses/>.
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//jimport('joomla.plugin.plugin');
class plgDjcatalog2paymentPayLane extends JPlugin {
public function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
protected function isAllowed($plgInfo, $type = 'djcatalog2payment') {
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;
}
if ($form->loadFile(dirname(__FILE__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'configuration.xml', false)) {
$jinput = JFactory::getApplication()->input;
if ($jinput->getCmd('option') == 'com_djcatalog2' && $jinput->get('view') == 'payment' && ($pluginId = $jinput->getInt('id'))) {
$form->setValue('notifications_url', 'params', JURI::root(false).'index.php?option=com_djcatalog2&task=paymentResponse&plg='.$this->_name.'&plgid='.$pluginId);
} else {
$form->removeField('notifications_url', 'params');
}
}
}
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();
$status = $app->input->getString('status');
$error_code = $app->input->getString('error_code');
$hasErrors = (bool)($status == 'ERROR' || !empty($error_code));
$message = '';
if ($app->input->get('view') == 'order' && $hasErrors) {
$message = JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_ERROR_TEXT');
} else if ($app->input->get('success') == '1') {
$message = JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_RETURN_TEXT');
}
if ($order->status != 'A' && $order->status != 'N') {
return;
}
$html = '<div class="paylaneinfo">';
if ($message) {
$html .= '<p class="paylanealert alert '.($hasErrors ? '' : 'alert-success').'">'.$message.'</p>';
}
if ($app->input->get('success') != '1' || $hasErrors) {
$html .= '<p class="paylanemessage">';
$html .= JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_INFO_TEXT');
$html .= '</p>';
$html .= '<div class="btn-toolbar paylanebuttons">';
$paymentUrl = JRoute::_('index.php?option=com_djcatalog2&task=paymentProcess&oid='.$order->id.'&plg='.$plgInfo->plugin.'&plgid='.$plgInfo->id);
$html .= '<a href="'.$paymentUrl.'" class="button btn paylanebtn">'.JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_BTN').'</a>';
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
public function onDJC2PaymentProcess($context, $order, $plgInfo) {
if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
return;
}
$app = JFactory::getApplication();
$merchantId = $plgInfo->params->get('merchant_id');
$salt = $plgInfo->params->get('salt');
if (!$merchantId || !$salt) {
throw new Exception(JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_ERROR_MISSING_PARAMS'), 400);
}
if (!$order->currency) {
throw new Exception(JText::_('PLG_DJCATALOG2PAYMENT_ERROR_MISSING_ORDER_CURRENCY'), 400);
}
$app = JFactory::getApplication();
$websiteName = $app->get('sitename', JURI::base());
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('*')->from('#__djc2_countries')->where('id=' . (int)$order->country_id);
$db->setQuery($query);
$country = $db->loadObject();
$langCode = explode('-', JFactory::getLanguage()->getTag())[0];
if(!in_array($langCode, array('en','pl','de','es','fr','nl','it'))) {
$langCode = 'en';
}
$vars = array();
$vars['merchant_id'] = $merchantId;
$vars['description'] = ($order->id < 10 ? '0':'').$order->id;
$vars['transaction_description'] = JText::sprintf('PLG_DJCATALOG2PAYMENT_PAYLANE_ORDER_DESCRIPTION', $order->order_number, $websiteName);
$vars['amount'] = number_format(round($order->grand_total,2), 2, '.', '');
$vars['currency'] = $order->currency;
$vars['transaction_type'] = 'S';
$vars['back_url'] = JRoute::_(JUri::root(false).DJCatalogHelperRoute::getOrderRoute($order->id).'&success=1', false);
$vars['language'] = $langCode;
$vars['customer_name'] = substr(stripslashes($order->firstname.' '.$order->lastname), 0, 50);
$vars['customer_email'] = substr($order->email, 0, 80);
$vars['customer_address'] = substr($order->address, 0, 46);
$vars['customer_zip'] = substr($order->postcode, 0, 9);
$vars['customer_city'] = substr($order->city, 0, 40);
if ($country) {
$vars['customer_country'] = substr($country->country_2_code, 0, 2);
}
$hash = sha1($salt . '|'. $vars['description'] . '|' . $vars['amount'] . '|' . $vars['currency'] . '|' . $vars['transaction_type']);
$vars['hash'] = $hash;
$htmlFormFields = "";
foreach ($vars as $key => $value) {
if (!is_array($value)) {
$htmlFormFields .= sprintf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n", $key, ($value));
}
}
$formUrl = 'https://secure.paylane.com/order/cart.html';
$html = '<!doctype html><html lang="en-US"><head><meta charset="UTF-8"><title>'.JText::_('COM_DJCATALOG2_PAYMENT_REDIRECTION').'</title></head>';
$html .= '<body><div style="margin: auto; text-align: center;">';
$html .= '<p>'.JText::_('COM_DJCATALOG2_PAYMENT_REDIRECTION').'</p>';
$html .= '<form method="POST" action="'.$formUrl.'" name="paylaneform">';
$html .= '<noscript><input type="submit" value="' . JText::_('COM_DJCATALOG2_PAYMENT_REDIRECTION_BUTTON') . '" /></noscript>';
$html .= '<input type="submit" value="' . JText::_('COM_DJCATALOG2_PAYMENT_REDIRECTION_BUTTON') . '" />';
$html .= $htmlFormFields;
$html .= '</form></div>';
//$html .= "<pre>";
//$html .= print_r($vars, true);
//$html .= "</pre>";
$html.= ' <script type="text/javascript">';
$html.= ' document.paylaneform.submit();';
$html.= ' </script></body></html>';
echo $html;
$app->close();
}
public function onDJC2PaymentDiscover($context, $plgInfo) {
if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
return;
}
$app = JFactory::getApplication();
$communication_id = (isset($_REQUEST['communication_id'])) ? $_REQUEST['communication_id'] : false;
$content = (isset($_POST['content'])) ? $_POST['content'] : false;
$size = isset($_POST['content_size']) ? $_POST['content_size'] : 0;
if (!$communication_id || !$content || !$size) {
return false;
}
//$this->_debug($content, 'discover');
for ($i = 0; $i < $size; $i++) {
$data = $content[$i];
$this->internalNotification($data, $plgInfo);
}
echo $communication_id;
$app->close();
}
protected function internalNotification($transaction, $plgInfo) {
$app = JFactory::getApplication();
require_once JPath::clean(dirname(__FILE__).'/lib/PayLaneRestClient.php');
if (empty($transaction) || empty($transaction['type']) || empty($transaction['id_sale'])) {
return false;
}
if ($transaction['type'] != 'S') {
return false;
}
$apiLogin = $plgInfo->params->get('api_login');
$apiPass = $plgInfo->params->get('api_pass');
if (!$apiLogin || !$apiPass) {
return false;
}
$client = new PayLaneRestClient($apiLogin, $apiPass);
try {
$info = $client->getSaleInfo(array('id_sale' => $transaction['id_sale']));
}
catch (Exception $e) {
// handle exceptions here
return false;
}
if (!$client->isSuccess()) {
return false;
}
return $this->validateNotification($info, $plgInfo);
}
protected function validateNotification($info, $plgInfo) {
//$this->_debug($info, 'validate');
$orderId = isset($info['description']) ? (int)$info['description'] : false;
$amountPaid = isset($info['amount']) ? floatval($info['amount']) : false;
$currency = isset($info['currency']) ? $info['currency'] : false;
$status = isset($info['status']) ? $info['status'] : false;
if (!$orderId || !$amountPaid || !$currency || !$status) {
return false;
}
$model = JModelLegacy::getInstance('Order', 'DJCatalog2Model', array('ignore_request' => true));
$order = $model->getItem($orderId);
// Order not found
if ($order == false || empty($order)) {
return false;
}
// Status doesn't change anything
if ($status != 'CLEARED' && $status != 'PERFORMED') {
return false;
}
$isValid = false;
if ($currency == $order->currency) {
if (round($amountPaid,2) == round($order->grand_total,2)) {
$isValid = true;
} else {
// Wrong amount
}
}
if ($isValid) {
if ($order->status == 'A' || $order->status == 'N') {
$model->changeStatus($order, 'P', true, true, JText::_('PLG_DJCATALOG2PAYMENT_PAYLANE_PAYMENT_COMPLETED'));
}
}
return $isValid;
}
public function onDJC2PaymentResponse($context, $order, $model, $plgInfo) {
if ($context != 'com_djcatalog2.order.payment' || !$this->isAllowed($plgInfo)) {
return;
}
return;
}
function _debug($data, $fn){
$t = date('Y-m-d-H-i-s', time());
$tt = date('Y-m-d', time());
$handle = fopen(dirname(__FILE__).'/logs/log_'.$fn.'-'.$tt.'.php', 'a');
fwrite($handle, $t.' :: '.@$_SERVER['REMOTE_ADDR'].' :: '.@$_SERVER['REQUEST_URI']."\n\n".print_r($data, true)."\n\n");
fclose($handle);
}
}