download all files

This commit is contained in:
Roman Pyrih
2025-06-24 14:14:35 +02:00
parent ebed09c00b
commit 4c71b5d9c2
72007 changed files with 10407727 additions and 40029 deletions

View File

@@ -0,0 +1,22 @@
<?php
/**
* PayU
*
* @author PayU
* @copyright Copyright (c) 2014 PayU
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
*
* http://www.payu.com
* http://openpayu.com
* http://twitter.com/openpayu
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -0,0 +1,64 @@
<?php
/**
* PayU notification
*
* @author PayU
* @copyright Copyright (c) 2014-2018 PayU
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
*
* http://www.payu.com
*/
include_once(_PS_MODULE_DIR_ . '/payu/tools/SimplePayuLogger/SimplePayuLogger.php');
class PayUNotificationModuleFrontController extends ModuleFrontController
{
public function process()
{
$body = Tools::file_get_contents('php://input');
$data = trim($body);
$payu = new PayU();
$payu->initializeOpenPayU($this->extractCurrencyCode($data));
try {
$result = OpenPayU_Order::consumeNotification($data);
} catch (OpenPayU_Exception $e) {
header('HTTP/1.1 400 Bad Request', true, 400);
die($e->getMessage());
}
$response = $result->getResponse();
if (property_exists($response, 'refund')) {
die('Refund notification - ignore');
}
SimplePayuLogger::addLog('notification', __FUNCTION__, print_r($result, true), $response->order->orderId, 'Incoming notification: ');
if (isset($response->order->orderId)) {
$payu->payu_order_id = $response->order->orderId;
$order_payment = $payu->getOrderPaymentBySessionId($payu->payu_order_id);
if ($order_payment) {
$payu->id_order = (int)$order_payment['id_order'];
$payu->updateOrderData($response);
}
//the response should be status 200
header("HTTP/1.1 200 OK");
exit;
}
}
/**
* @param string $data
* @return string
*/
private function extractCurrencyCode($data)
{
$decodeData = json_decode($data);
return $decodeData->order->currencyCode;
}
}

View File

@@ -0,0 +1,271 @@
<?php
/**
* OpenPayU
*
* @author PayU
* @copyright Copyright (c) 2016 PayU
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
*
* http://www.payu.com
*/
class PayUPaymentModuleFrontController extends ModuleFrontController
{
/** @var PayU */
private $payu;
public $display_column_left = false;
private $hasRetryPayment;
private $order = null;
public function postProcess()
{
$this->checkHasModuleActive();
$this->checkHasRetryPayment();
$this->payu = new PayU();
if ($this->hasRetryPayment) {
$this->postProcessRetryPayment();
} else {
$this->postProcessPayment();
}
}
public function initContent()
{
parent::initContent();
SimplePayuLogger::addLog('order', __FUNCTION__, 'payment.php entrance. PHP version: ' . phpversion(), '');
$payMethod = Tools::getValue('payMethod');
if (Configuration::get('PAYU_RETRIEVE')) {
if (Tools::getValue('payuPay')) {
$payuConditions = Tools::getValue('payuConditions');
$cardToken = Tools::getValue('cardToken');
$errors = [];
$payError = [];
if (!$payMethod) {
$errors[] = $this->module->l('Please select a method of payment', 'payment');
}
if (!$payuConditions) {
$errors[] = $this->module->l('Please accept "Terms of single PayU payment transaction"', 'payment');
}
if ($payMethod === 'card' && !$cardToken) {
$errors[] = $this->module->l('Card token is empty', 'payment');
}
if (count($errors) == 0) {
$payError = $this->pay($payMethod, ['cardToken' => $cardToken]);
if (!array_key_exists('firstPayment', $payError)) {
$errors[] = $payError['message'];
}
}
if (array_key_exists('firstPayment', $payError)) {
$this->showPaymentError();
} else {
if ($payMethod === 'card') {
$this->showSecureForm($payuConditions, $errors);
} else {
$this->showPayMethod($payMethod, $payuConditions, $errors);
}
}
} else {
if ($payMethod === 'card') {
$this->showSecureForm();
} else {
$this->showPayMethod();
}
}
} else {
$this->pay($payMethod === 'card' ? 'c' : null);
$this->showPaymentError();
}
}
private function showPayMethod($payMethod = '', $payuConditions = 1, $errors = array())
{
$this->context->smarty->assign(array(
'conditionTemplate' => _PS_MODULE_DIR_ . 'payu/views/templates/front/conditions17.tpl',
'payMethod' => $payMethod,
'image' => $this->payu->getPayuLogo(),
'conditionUrl' => $this->payu->getPayConditionUrl(),
'payuConditions' => $payuConditions,
'payByClick' => Configuration::get('PAYU_PAY_BY_ICON_CLICK') === '1',
'payuErrors' => $errors
));
$this->context->smarty->assign($this->getShowPayMethodsParameters());
$this->setTemplate($this->payu->buildTemplatePath('payMethods'));
}
private function showSecureForm($payuConditions = 1, $errors = array())
{
$this->context->smarty->assign(array(
'conditionTemplate' => _PS_MODULE_DIR_ . 'payu/views/templates/front/conditions17.tpl',
'secureFormJsTemplate' => _PS_MODULE_DIR_ . 'payu/views/templates/front/secureFormJs.tpl',
'payCardTemplate' => _PS_MODULE_DIR_ . 'payu/views/templates/front/payuCardForm.tpl',
'image' => $this->payu->getPayuLogo(),
'conditionUrl' => $this->payu->getPayConditionUrl(),
'payuConditions' => $payuConditions,
'payuErrors' => $errors,
'jsSdk' => $this->payu->getPayuUrl(Configuration::get('PAYU_SANDBOX') === '1') . 'javascript/sdk'
));
$this->context->smarty->assign($this->getShowPayMethodsParameters());
$this->setTemplate($this->payu->buildTemplatePath('secureForm'));
}
private function showPaymentError()
{
$this->context->smarty->assign(
array(
'image' => $this->payu->getPayuLogo(),
'total' => Tools::displayPrice($this->order->total_paid, (int)$this->order->id_currency),
'orderCurrency' => (int)$this->order->id_currency,
'buttonAction' => $this->context->link->getModuleLink('payu', 'payment', array('id_order' => $this->order->id, 'order_reference' => $this->order->reference)),
'payuOrderInfo' => $this->module->l('Pay for your order', 'payment') . ' ' . $this->order->reference,
'payuError' => $this->module->l('An error occurred while processing your payment.', 'payment')
)
);
$this->setTemplate($this->payu->buildTemplatePath('error'));
}
private function pay($payMethod = null, $parameters = [])
{
if (!$this->hasRetryPayment) {
$this->payu->validateOrder(
$this->context->cart->id, (int)Configuration::get('PAYU_PAYMENT_STATUS_PENDING'),
$this->context->cart->getOrderTotal(true, Cart::BOTH), $this->payu->displayName,
null, array(), (int)$this->context->cart->id_currency, false, $this->context->cart->secure_key,
Context::getContext()->shop->id ? new Shop((int)Context::getContext()->shop->id) : null
);
$this->order = new Order($this->payu->currentOrder);
}
$this->payu->generateExtOrderId($this->order->id);
$this->payu->order = $this->order;
try {
$result = $this->payu->orderCreateRequestByOrder($payMethod, $parameters);
$this->payu->payu_order_id = $result['orderId'];
$this->postOCR();
$redirectUrl = $result['redirectUri'] ? $result['redirectUri'] : $this->context->link->getModuleLink('payu', 'success', array('id' => $this->payu->getExtOrderId()));
SimplePayuLogger::addLog('order', __FUNCTION__, 'Process redirect to ' . $redirectUrl, $result['orderId']);
Tools::redirect($redirectUrl);
} catch (\Exception $e) {
SimplePayuLogger::addLog('order', __FUNCTION__, 'An error occurred while processing OCR - ' . $e->getMessage(), '');
if ($this->hasRetryPayment) {
return array('message' => $this->module->l('An error occurred while processing your payment. Please try again or contact the store.', 'payment') . ' ' . $result['error']);
}
return array(
'firstPayment' => true
);
}
}
private function postProcessPayment()
{
if ($this->context->cart->id_customer == 0 || $this->context->cart->id_address_delivery == 0 || $this->context->cart->id_address_invoice == 0 || !count($this->context->cart->getProducts())) {
Tools::redirectLink(__PS_BASE_URI__ . 'order.php?step=1');
}
$customer = new Customer($this->context->cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirectLink(__PS_BASE_URI__ . 'order.php?step=1');
}
}
private function postProcessRetryPayment()
{
$id_order = (int)Tools::getValue('id_order');
$order_reference = Tools::getValue('order_reference');
if (!$id_order || !Validate::isUnsignedId($id_order)) {
Tools::redirect('index.php?controller=history');
}
$this->order = new Order($id_order);
if (!Validate::isLoadedObject($this->order) || $this->order->reference !== $order_reference) {
Tools::redirect('index.php?controller=history');
}
if (!$this->payu->hasRetryPayment($this->order->id, $this->order->current_state)) {
Tools::redirect('index.php?controller=history');
}
}
private function checkHasModuleActive()
{
if (!Module::isEnabled($this->module->name)) {
die($this->module->l('This payment method is not available.', 'payment'));
}
if (!$this->module->active) {
die($this->module->l('PayU module isn\'t active.', 'payment'));
}
}
private function checkHasRetryPayment()
{
$this->hasRetryPayment = Tools::getValue('id_order') !== false && Tools::getValue('order_reference') !== false;
}
private function getShowPayMethodsParameters()
{
$currency = $this->hasRetryPayment ? (int)$this->order->id_currency : (int)$this->context->cart->id_currency;
$this->payu->initializeOpenPayU(Currency::getCurrency($currency)['iso_code']);
$parameters = [
'posId' => OpenPayU_Configuration::getMerchantPosId(),
'orderCurrency' => $currency,
'payMethods' => $this->payu->getPaymethods(Currency::getCurrency($currency)),
'retryPayment' => $this->hasRetryPayment,
'lang' => Language::getIsoById($this->context->language->id)
];
if ($this->hasRetryPayment) {
return $parameters + array(
'total' => Tools::displayPrice($this->order->total_paid, $currency),
'payuPayAction' => $this->context->link->getModuleLink('payu', 'payment', array('id_order' => $this->order->id, 'order_reference' => $this->order->reference)),
'payuOrderInfo' => $this->module->l('Retry pay for your order', 'payment') . ' ' . $this->order->reference
);
} else {
return $parameters + array(
'total' => Tools::displayPrice($this->context->cart->getOrderTotal(true, Cart::BOTH)),
'payuPayAction' => $this->context->link->getModuleLink('payu', 'payment'),
'payuOrderInfo' => $this->module->l('The total amount of your order is', 'payment')
);
}
}
private function postOCR()
{
if ($this->hasRetryPayment) {
$history = new OrderHistory();
$history->id_order = $this->order->id;
$history->changeIdOrderState(Configuration::get('PAYU_PAYMENT_STATUS_PENDING'), $this->order->id);
$history->addWithemail(true);
}
$this->payu->addOrderSessionId(OpenPayuOrderStatus::STATUS_NEW, $this->order->id, 0, $this->payu->payu_order_id, $this->payu->getExtOrderId());
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* PayU success
*
* @author PayU
* @copyright Copyright (c) PayU
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
*
* http://www.payu.com
* http://openpayu.com
* http://twitter.com/openpayu
*/
class PayUSuccessModuleFrontController extends ModuleFrontController
{
private $order;
public function initContent()
{
parent::initContent();
$payu = new PayU();
$order_payment = $payu->getOrderPaymentByExtOrderId(Tools::getValue('id'));
if (!$order_payment) {
Tools::redirect('index.php?controller=history', __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
}
$payu->id_order = $order_payment['id_order'];
$payu->id_cart = $order_payment['id_cart'];
$payu->payu_order_id = $order_payment['id_session'];
$payu->updateOrderData();
$this->order = new Order($payu->id_order);
$currentState = $this->order->getCurrentStateFull($this->context->language->id);
$this->context->smarty->assign(array(
'payuLogo' => $payu->getPayuLogo('payu_logo_small.png'),
'orderPublicId' => $this->order->getUniqReference(),
'redirectUrl' => $this->getRedirectLink(),
'orderStatus' => $currentState['name'],
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(),
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()
));
$this->setTemplate($payu->buildTemplatePath('status'));
}
private function getRedirectLink()
{
if (Cart::isGuestCartByCartId($this->order->id_cart)) {
$customer = new Customer((int)$this->order->id_customer);
return $this->context->link->getPageLink(
'guest-tracking',
null,
$this->context->language->id,
['order_reference' => $this->order->reference, 'email' => $customer->email]
);
}
return $this->context->link->getPageLink(
'order-detail',
null,
$this->context->language->id,
['id_order' => $this->order->id]
);
}
/**
* Execute the hook displayPaymentReturn
*/
private function displayPaymentReturn()
{
$params = $this->displayHook();
if ($params && is_array($params)) {
return Hook::exec('displayPaymentReturn', $params, $this->module->id);
}
return false;
}
/**
* Execute the hook displayOrderConfirmation
*/
private function displayOrderConfirmation()
{
$params = $this->displayHook();
if ($params && is_array($params)) {
return Hook::exec('displayOrderConfirmation', $params);
}
return false;
}
private function displayHook()
{
if (Validate::isLoadedObject($this->order)) {
$currency = new Currency((int) $this->order->id_currency);
return array(
'objOrder' => $this->order,
'order' => $this->order,
'currencyObj' => $currency,
'currency' => $currency->sign,
'total_to_pay' => $this->order->getOrdersTotalPaid()
);
}
return false;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* PayU
*
* @author PayU
* @copyright Copyright (c) 2014 PayU
* @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0)
*
* http://www.payu.com
* http://openpayu.com
* http://twitter.com/openpayu
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;