├── .gitignore
├── logo.png
├── logos
├── clic.jpg
├── download.jpg
├── loading.gif
├── payments.png
└── index.php
├── translations
├── en.php
├── index.php
└── fr.php
├── views
├── templates
│ ├── hook
│ │ ├── infos.tpl
│ │ ├── payment.tpl
│ │ └── index.php
│ └── index.php
└── index.php
├── payment.php
├── controllers
├── front
│ ├── echec.php
│ ├── succes.php
│ ├── index.php
│ ├── order.php
│ ├── validation.php
│ └── smtcontrol.php
└── index.php
├── config.xml
├── config_fr.xml
├── index.php
├── LICENSE
├── README.md
└── clictopay.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
3 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nayzo/Clictopay/HEAD/logo.png
--------------------------------------------------------------------------------
/logos/clic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nayzo/Clictopay/HEAD/logos/clic.jpg
--------------------------------------------------------------------------------
/translations/en.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
{l s="This module allows you to accept online payments by SPS Clictopay SMT." mod='clictopay'}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/views/templates/hook/payment.tpl:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 | {l s='Payment by credit card' mod='clictopay'}
7 |
8 |
9 |
--------------------------------------------------------------------------------
/payment.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | $useSSL = true;
11 |
12 | require('../../config/config.inc.php');
13 | Tools::displayFileAsDeprecated();
14 |
15 | $controller = new FrontController();
16 | $controller->init();
17 |
18 | Tools::redirect(Context::getContext()->link->getModuleLink('clictopay', 'payment'));
19 |
--------------------------------------------------------------------------------
/controllers/front/echec.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | class ClictopayEchecModuleFrontController extends ModuleFrontController
11 | {
12 | public $ssl = true;
13 |
14 | public function initContent()
15 | {
16 | parent::initContent();
17 | Tools::redirect('index.php?controller=order');
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | clictopay
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | 1
12 | 1
13 |
14 |
15 |
--------------------------------------------------------------------------------
/config_fr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | clictopay
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | 1
12 | 1
13 |
14 |
15 |
--------------------------------------------------------------------------------
/controllers/front/succes.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | include(dirname(__FILE__) . '../../clictopay.php');
11 |
12 | class ClictopaySuccesModuleFrontController extends ModuleFrontController
13 | {
14 | public $ssl = true;
15 |
16 | public function initContent()
17 | {
18 | parent::initContent();
19 |
20 | $context = Context::getContext();
21 | $cart = $context->cart;
22 | $clictopay = new Clictopay();
23 | $customer = new Customer($cart->id_customer);
24 | Tools::redirect('index.php?controller=order-confirmation&id_cart='
25 | . (int)($cart->id)
26 | . '&id_module='
27 | . (int)($clictopay->id)
28 | . '&id_order='
29 | . $clictopay->currentOrder
30 | . '&key='
31 | . $customer->secure_key
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/logos/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
--------------------------------------------------------------------------------
/views/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/controllers/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/translations/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/views/templates/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/controllers/front/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/views/templates/hook/index.php:
--------------------------------------------------------------------------------
1 |
22 | * @copyright 2007-2014 PrestaShop SA
23 | * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24 | * International Registered Trademark & Property of PrestaShop SA
25 | */
26 |
27 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
28 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
29 |
30 | header("Cache-Control: no-store, no-cache, must-revalidate");
31 | header("Cache-Control: post-check=0, pre-check=0", false);
32 | header("Pragma: no-cache");
33 |
34 | header("Location: ../");
35 | exit;
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The BSD License (BSD)
2 |
3 | Copyright (c) 2014 Ala Eddine khefifi
4 |
5 | All rights reserved.
6 | Redistribution and use in source and binary forms, without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | * Redistributions of the module must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other source codes provided with the distribution.
14 | * The name of Ala Eddine khefifi may be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/controllers/front/order.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | session_start();
11 | ?>
12 |
13 |
14 |
15 |
28 |
29 |
30 |
31 |

32 |
33 |
Opération en cours d'éxécution, Veuillez patienter
34 |
35 |
36 |
43 |
47 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/translations/fr.php:
--------------------------------------------------------------------------------
1 | clictopay_5c2f72c4b97d8417e71d052bcd50cf28'] = 'Ce module vous permet d\'accepter des paiements en ligne basé sur le SPS Clictopay SMT, Développé par Ala Eddine Khefifi. Email: alakhefifi@gmail.com';
6 | $_MODULE['<{clictopay}prestashop>clictopay_fa214007826415a21a8456e3e09f999d'] = 'Etes-vous sûr que vous voulez supprimer vos informations?';
7 | $_MODULE['<{clictopay}prestashop>clictopay_b624b2f854c0d5ec3977679b8acf8598'] = 'les champs URL et Affilie doivent être configurés pour utiliser ce module correctement.';
8 | $_MODULE['<{clictopay}prestashop>clictopay_4402acab1c8f90dcf4a31dc96833bd86'] = 'Aucun devise activé pour ce module';
9 | $_MODULE['<{clictopay}prestashop>clictopay_3fa2d0ca65dc0f704e02a182fea7b213'] = 'Le paiement ne peut être exécuté sur le serveur local';
10 | $_MODULE['<{clictopay}prestashop>clictopay_0371266fa38bd7f39045b4ecb19a7b0d'] = 'Le champ URL est vide!';
11 | $_MODULE['<{clictopay}prestashop>clictopay_94e32577b0ae42bf51d062cb481c23af'] = 'Le champ Affilie est vide!';
12 | $_MODULE['<{clictopay}prestashop>clictopay_c888438d14855d7d96a2724ee9c306bd'] = 'Paramètres mis à jour';
13 | $_MODULE['<{clictopay}prestashop>clictopay_302d0da25bb09306324845f25c166c3c'] = 'Info Clictopay SMT';
14 | $_MODULE['<{clictopay}prestashop>clictopay_d7e63a2cbdd3cc510c4e7080fffc7c77'] = 'Entrez les informations de configuration pour Clictopay SMT';
15 | $_MODULE['<{clictopay}prestashop>clictopay_48c904e96f4d349e0b1abb8e9f10767b'] = 'Lien vers le site de paiement Clictopay SMT';
16 | $_MODULE['<{clictopay}prestashop>clictopay_bb166feff34b74fef81127259160c93a'] = 'Affilie';
17 | $_MODULE['<{clictopay}prestashop>clictopay_b17f3f4dcf653a5776792498a9b44d6a'] = 'Mettre à jour';
18 | $_MODULE['<{clictopay}prestashop>validation_e2b7dec8fa4b498156dfee6e4c84b156'] = 'Ce mode de paiement n\'est pas disponible.';
19 | $_MODULE['<{clictopay}prestashop>infos_03981556323dde9b096933c54c721594'] = 'Ce module vous permet d\'accepter les paiements en ligne par SPS Clictopay SMT.';
20 | $_MODULE['<{clictopay}prestashop>payment_d7e11762e2b2c2255bc37dcb039b9dcd'] = 'Paiement par carte bancaire';
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Clictopay SMT
2 | =====================
3 |
4 | **Clictopay SMT** est un module **Prestashop** de paiement en ligne pour **SPS Monétique Tunisie**.
5 |
6 |
7 | **Caractéristiques et fonctionnalités du module Clictopay SMT** :
8 |
9 | - Rapide, performant et totalement sécurisé
10 |
11 | - Bilingue ``FR`` et ``EN``
12 |
13 | - Compatible avec la version **v1.5.0** et **ultérieur** de **Prestashop** (v1.5 / v1.6 / ...)
14 |
15 | - Accepte les paiements de différentes devises (TND, €, $).
16 |
17 | - Accepte les paiements de différents cartes (locale et internationale).
18 |
19 | - Enregistré sous la licence ``BSD``. Développé par **Ala Eddine Khefifi**
20 |
21 |
22 |
23 | Installation
24 | ------------
25 |
26 | 1. Téléchargez le .zip du module depuis Github
27 |
28 | 2. Lien: https://github.com/nayzo/Clictopay/archive/refs/tags/1.0.0.zip
29 |
30 | 3. Décompressez le module ``Clictopay-x.x.x.zip``
31 |
32 | 4. Renommez le dossier ``Clictopay-x.x.x`` à ``clictopay`` (**Attention tout est en minuscule!**).
33 |
34 | 5. Compressez (.zip) le dossier renommé ``clictopay`` (Résultat: clictopay.zip).
35 |
36 | 6. Chargez le module ``clictopay.zip`` depuis le back office de Prestashop, menu ``Modules``.
37 |
38 | 7. Installez le module ``Clictopay SMT`` depuis le back office de Prestashop, menu ``Modules``.
39 |
40 |
41 |
42 | Configuration
43 | -------------
44 |
45 | 1. Cliquez sur le bouton ``Configurer`` du module ``Clictopay SMT``.
46 |
47 | 2. Remplissez le champ ``URL`` avec le lien de page de paiement de SPS Monétique Tunisie : (i.e: https://www.smt-sps.com.tn/clicktopay).
48 |
49 | 3. Remplissez le champ ``Affilie`` avec le code d'adhésion à la plateforme SPS.
50 |
51 | 4. Mettez à jour la configuration.
52 |
53 |
54 | ### Liens de Configuration:
55 |
56 | Les liens de Configuration qu'il faut fournir à SPS Monétique Tunisie.
57 |
58 | Changez ``www.domain.com`` par votre nom de domaine.
59 |
60 |
61 | ``` html
62 | // Controle et Notification:
63 |
64 | http://www.domain.com/index.php?fc=module&module=clictopay&controller=smtcontrol
65 |
66 | // Succes:
67 |
68 | http://www.domain.com/index.php?fc=module&module=clictopay&controller=succes
69 |
70 | // Echec:
71 |
72 | http://www.domain.com/index.php?fc=module&module=clictopay&controller=echec
73 |
74 | ```
75 |
76 |
77 | Licence
78 | -------
79 |
80 | Ce Module est sous la licence ``BSD``.
81 |
82 | Développé par **Ala Eddine Khefifi**
83 |
84 | Voir [LICENCE](https://github.com/NAYZO/Clictopay/blob/master/LICENSE)
85 |
--------------------------------------------------------------------------------
/controllers/front/validation.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | session_start();
11 |
12 | class ClictopayValidationModuleFrontController extends ModuleFrontController
13 | {
14 | public function postProcess()
15 | {
16 | $cart = $this->context->cart;
17 |
18 | if ($cart->id_customer == 0
19 | || $cart->id_address_delivery == 0
20 | || $cart->id_address_invoice == 0
21 | || !$this->module->active
22 | ) {
23 | Tools::redirect('index.php?controller=order&step=1');
24 | }
25 |
26 | $authorized = false;
27 | foreach (Module::getPaymentModules() as $module)
28 | if ($module['name'] == 'clictopay') {
29 | $authorized = true;
30 | break;
31 | }
32 |
33 | if (!$authorized)
34 | die($this->module->l('This payment method is not available.', 'validation'));
35 |
36 | $customer = new Customer($cart->id_customer);
37 |
38 | if (!Validate::isLoadedObject($customer))
39 | Tools::redirect('index.php?controller=order&step=1');
40 |
41 | $currency = $this->context->currency;
42 | $total = (float)$cart->getOrderTotal(true, Cart::BOTH);
43 | $total = sprintf('%.3f', $total);
44 |
45 | $cartid = (int)$cart->id;
46 | $name = $this->module->displayName;
47 | $currencyid = (int)$currency->id;
48 | $customerkey = $customer->secure_key;
49 | $reference = strtoupper(Tools::passwdGen(9, 'NO_NUMERIC')) . strtoupper(Tools::passwdGen(9, 'NO_NUMERIC'));
50 |
51 | $config = Configuration::getMultiple(array('URL', 'affilie'));
52 | $_SESSION['URL'] = $config['URL'];
53 | $_SESSION['sid'] = $customerkey;
54 | $_SESSION['Reference'] = $reference;
55 | $_SESSION['Montant'] = $total;
56 | $_SESSION['affilie'] = $config['affilie'];
57 | $_SESSION['Devise'] = $currency->iso_code;
58 |
59 | Db::getInstance()->execute("INSERT INTO " . _DB_PREFIX_ . "clictopay
60 | (reference,cart,total,module,currency,customer)
61 | VALUES ('$reference','$cartid','$total','$name','$currencyid','$customerkey')");
62 |
63 | Tools::redirect('index.php?fc=module&module=clictopay&controller=order');
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/controllers/front/smtcontrol.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | class ClictopaySmtcontrolModuleFrontController extends ModuleFrontController
11 | {
12 | public function postProcess()
13 | {
14 | if (empty($_GET['Reference']) || empty($_GET['Action'])) {
15 | exit;
16 | }
17 |
18 | $ref = $_GET['Reference'];
19 | $act = $_GET['Action'];
20 |
21 | if (!Db::getInstance()->getValue("
22 | SELECT `id_clictopay`
23 | FROM `" . _DB_PREFIX_ . "clictopay`
24 | WHERE `reference` = '$ref'")
25 | ) {
26 | exit;
27 | }
28 |
29 | switch (strtoupper($act)) {
30 |
31 | case "DETAIL":
32 | // access the database, and retrieve the amount
33 | $montant = Db::getInstance()->getValue("
34 | SELECT `total`
35 | FROM `" . _DB_PREFIX_ . "clictopay`
36 | WHERE `reference` = '$ref'");
37 | if (empty($montant)) {
38 | exit;
39 | }
40 |
41 | $montant = sprintf('%.3f', $montant);
42 | echo "Reference=$ref&Action=$act&Reponse=$montant";
43 | break;
44 |
45 | case "ACCORD":
46 | // access the database, register the authorization number (in param)
47 |
48 | $data = Db::getInstance()->executeS("
49 | SELECT *
50 | FROM `" . _DB_PREFIX_ . "clictopay`
51 | WHERE `reference` = '$ref'");
52 |
53 | foreach ($data as $row) {
54 | $mailVars = array();
55 | $this->module->validateOrder($row['cart'],
56 | Configuration::get('PS_OS_PAYMENT'),
57 | $row['total'],
58 | $row['module'],
59 | NULL,
60 | $mailVars,
61 | $row['currency'],
62 | false,
63 | $row['customer']
64 | );
65 | }
66 |
67 | $param = $_GET['Param'];
68 | if (isset($param)) {
69 | Db::getInstance()->execute("UPDATE `" . _DB_PREFIX_ . "clictopay`
70 | SET `param` = '$param'
71 | WHERE `reference` = '$ref'");
72 | }
73 |
74 | echo "Reference=$ref&Action=$act&Reponse=OK";
75 | break;
76 |
77 | case "ERREUR":
78 | case "REFUS":
79 | case "ANNULATION":
80 | // access the database and update the transaction state
81 | Db::getInstance()->execute("DELETE FROM `" . _DB_PREFIX_ . "clictopay`
82 | WHERE `reference` = '$ref'"
83 | );
84 |
85 | echo "Reference=$ref&Action=$act&Reponse=OK";
86 | break;
87 | }
88 |
89 | exit;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/clictopay.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | if (!defined('_PS_VERSION_')) {
11 | exit;
12 | }
13 |
14 | class Clictopay extends PaymentModule
15 | {
16 | private $_html = '';
17 | private $_postErrors = array();
18 |
19 | public $URL;
20 | public $affilie;
21 |
22 | function __construct()
23 | {
24 | $this->name = 'clictopay';
25 | $this->tab = 'payments_gateways';
26 | $this->version = '1.4.1';
27 | $this->author = 'Ala Eddine Khefifi';
28 |
29 | $this->currencies = true;
30 | $this->currencies_mode = 'checkbox';
31 |
32 | $config = Configuration::getMultiple(array('URL', 'affilie'));
33 |
34 | if (isset($config['URL'])) {
35 | $this->URL = $config['URL'];
36 | }
37 |
38 | if (isset($config['affilie'])) {
39 | $this->affilie = $config['affilie'];
40 | }
41 |
42 | parent::__construct();
43 |
44 | $this->displayName = 'Clictopay SMT';
45 | $this->description = $this->l('This module allows you to accept online payments based on the SPS Clictopay SMT. Developed by Ala Eddine Khefifi. Email: alakhefifi@gmail.com');
46 | $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
47 |
48 | if ((!isset($this->URL) || !isset($this->affilie) || empty($this->URL) || empty($this->affilie))) {
49 | $this->warning = $this->l('The URL and the Affiliate fields must be configured in order to use this module correctly.');
50 | }
51 |
52 | if (!count(Currency::checkPaymentCurrencies($this->id))) {
53 | $this->warning = $this->l('No currency set for this module');
54 | }
55 |
56 | if ('localhost' === $_SERVER['HTTP_HOST']) {
57 | $this->warning = $this->l('The payment cannot be executed on localhost');
58 | }
59 | }
60 |
61 | public function install()
62 | {
63 | if (!parent::install() || !$this->registerHook('payment'))
64 | return false;
65 |
66 | $sql = "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . "clictopay`(
67 | `id_clictopay` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
68 | `reference` VARCHAR(256) NOT NULL,
69 | `param` VARCHAR(256),
70 | `cart` INT(11) NOT NULL,
71 | `total` FLOAT(11) NOT NULL,
72 | `module` VARCHAR(256) NOT NULL,
73 | `currency` INT(11) NOT NULL,
74 | `customer` VARCHAR(256) NOT NULL
75 | )";
76 |
77 | if (!Db::getInstance()->Execute($sql)) {
78 | return false;
79 | }
80 |
81 | return true;
82 | }
83 |
84 | public function uninstall()
85 | {
86 | if (!Configuration::deleteByName('URL') || !Configuration::deleteByName('affilie') || !parent::uninstall()) {
87 | return false;
88 | }
89 |
90 | $sql = "DROP TABLE IF EXISTS `" . _DB_PREFIX_ . "clictopay`";
91 |
92 | if (!Db::getInstance()->Execute($sql)) {
93 | return false;
94 | }
95 |
96 | return true;
97 | }
98 |
99 | private function _postValidation()
100 | {
101 | if (Tools::isSubmit('btnSubmit')) {
102 | if (!Tools::getValue('URL')) {
103 | $this->_postErrors[] = $this->l('The URL field is empty!');
104 | } elseif (!Tools::getValue('affilie')) {
105 | $this->_postErrors[] = $this->l('The Affiliate field is empty!');
106 | }
107 | }
108 | }
109 |
110 | private function _postProcess()
111 | {
112 | if (Tools::isSubmit('btnSubmit')) {
113 | Configuration::updateValue('URL', Tools::getValue('URL'));
114 | Configuration::updateValue('affilie', Tools::getValue('affilie'));
115 | }
116 |
117 | $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
118 | }
119 |
120 | private function _displayCart()
121 | {
122 | return $this->display(__FILE__, 'infos.tpl');
123 | }
124 |
125 | private function renderForm()
126 | {
127 | $this->_html .=
128 | '';
142 | }
143 |
144 | public function getContent()
145 | {
146 | $this->_html .= '' . $this->displayName . '
';
147 |
148 | if (Tools::isSubmit('btnSubmit')) {
149 | $this->_postValidation();
150 |
151 | if (!count($this->_postErrors)) {
152 | $this->_postProcess();
153 | } else {
154 | foreach ($this->_postErrors as $err) {
155 | $this->_html .= $this->displayError($err);
156 | }
157 | }
158 | }
159 |
160 | $this->_html .= $this->_displayCart();
161 | $this->_html .= $this->renderForm();
162 |
163 | return $this->_html;
164 | }
165 |
166 | public function hookPayment($params)
167 | {
168 | if (!$this->active) {
169 | return;
170 | }
171 |
172 | if (!$this->checkCurrency($params['cart'])) {
173 | return;
174 | }
175 |
176 | $this->smarty->assign(array(
177 | 'this_path' => $this->_path,
178 | 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/'
179 | ));
180 |
181 | return $this->display(__FILE__, 'payment.tpl');
182 | }
183 |
184 | public function checkCurrency($cart)
185 | {
186 | $currency_order = new Currency((int)($cart->id_currency));
187 | $currencies_module = $this->getCurrency((int)$cart->id_currency);
188 |
189 | if (is_array($currencies_module)) {
190 | foreach ($currencies_module as $currency_module) {
191 | if ($currency_order->id == $currency_module['id_currency']) {
192 | return true;
193 | }
194 | }
195 | }
196 |
197 | return false;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------