Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrzelak committed Oct 14, 2019
1 parent f641018 commit dc389b6
Show file tree
Hide file tree
Showing 14 changed files with 1,092 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>simpay</name>
<displayName><![CDATA[SimPay]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[Płatności DirectCarrierBilling SMS+ dla twojego sklepu]]></description>
<author><![CDATA[Payments Soultion sp. z o.o.]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
</module>
34 changes: 34 additions & 0 deletions controllers/front/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* 2007-2019 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;
80 changes: 80 additions & 0 deletions controllers/front/notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* 2007-2019 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

class SimPayNotificationModuleFrontController extends ModuleFrontController {

private $simPay;

public function postProcess() {

if ($this->module->active == false) {
exit();
}

$simPay = new SimPayDB();

$simPay->setApiKey(Configuration::get('SIMPAY_API_KEY'));

if (!$simPay->checkIp($simPay->getRemoteAddr())) {
$simPay->okTransaction();
exit();
}

if ($simPay->parse($_POST)) {

if ($simPay->isError()) {
$simPay->okTransaction();
exit();
}

if (!$simPay->isTransactionPaid()) {
$simPay->okTransaction();
exit();
}
} else {
error_log($simPay->getErrorText());
$simPay->okTransaction();
exit();
}

$history = new OrderHistory();
$history->id_order = $simPay->getControl();

$order = new Order($simPay->getControl());
if ($simPay->getValueGross() < $order->total_products_wt) {
$simPay->okTransaction();
exit();
}

$history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), $simPay->getControl());
$history->addWithemail(true);

$simPay->okTransaction();
exit();

}

}
99 changes: 99 additions & 0 deletions controllers/front/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* 2007-2019 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

class SimPayValidationModuleFrontController extends ModuleFrontController {

public function postProcess() {

if ($this->module->active == false) {
exit();
}

$cart = $this->context->cart;

$payMethod = Tools::getValue('payMethod');
if (!$payMethod) {
$this->_errors[] = $this->module->l('Prosimy wybrać metodę płatności!', 'validation');
}

if (!$cart->id_customer || !$cart->id_address_delivery || !$cart->id_address_invoice || !$this->module->active) {
Tools::redirect('index.php?controller=order&step=1');
exit();
}

$customer = new Customer($cart->id_customer);
if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
}

$authorized = false;
foreach (Module::getPaymentModules() as $module) {
if ($module['name'] == 'simpay') {
$authorized = true;
break;
}
}

if (!$authorized) {
die($this->module->l('Prosimy wybrać metodę płatności!', 'validation'));
}

$this->context->smarty->assign([
'params' => $_REQUEST,
]);

$amount = number_format(round((float)$cart->getOrderTotal(true, Cart::BOTH), 2), 2, '.', '');
$currency = $this->context->currency;

$this->module->validateOrder($cart->id, '10', $amount, $this->module->displayName, null, null, (int)$currency->id, false, $customer->secure_key);

$returnUrl = Context::getContext()->shop->getBaseURL(true) . 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $this->module->id . '&id_order=' . $this->module->currentOrder.'&key='.$customer->secure_key;

$simpayTransaction = new SimPayDBTransaction();
$simpayTransaction->setDebugMode(FALSE);
$simpayTransaction->setServiceID(Configuration::get('SIMPAY_SERVICE_ID'));
$simpayTransaction->setApiKey(Configuration::get('SIMPAY_API_KEY'));
$simpayTransaction->setControl($this->module->currentOrder);
$simpayTransaction->setCompleteLink($returnUrl);
$simpayTransaction->setFailureLink($returnUrl);
if (Configuration::get('SIMPAY_PAYMENT_TYPE') == "amount") {
$simpayTransaction->setAmount($amount);
} elseif (Configuration::get('SIMPAY_PAYMENT_TYPE') == "amount_gross") {
$simpayTransaction->setAmountGross($amount);
} else {
$simpayTransaction->setAmountRequired($amount);
}

$simpayTransaction->generateTransaction();
if ($simpayTransaction->getResults()->status == "success") {
Tools::redirect($simpayTransaction->getResults()->link);
} else {
$this->module->l('Nie udało się przejść do płatności!', 'validation');
}

}

}
35 changes: 35 additions & 0 deletions controllers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

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();
Loading

0 comments on commit dc389b6

Please sign in to comment.