227 lines
10 KiB
PHP
227 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* 2007-2017 Decanet
|
|
*
|
|
* 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 license@prestashop.com 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.decanet.fr for more information.
|
|
*
|
|
* @author Decanet SA <contact@decanet.fr>
|
|
* @copyright 2007-2017 Decanet SA
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
require_once(dirname(__FILE__).'/../../classes/PrevSepa.php');
|
|
|
|
class PrelevementSepaMandatSepaModuleFrontController extends ModuleFrontController
|
|
{
|
|
public $ssl = true;
|
|
public $display_column_left = false;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->context = Context::getContext();
|
|
include_once($this->module->getLocalPath().'prelevementsepa.php');
|
|
}
|
|
|
|
/**
|
|
* @see FrontController::initContent()
|
|
*/
|
|
public function initContent()
|
|
{
|
|
if (Tools::getIsset('downloadMandate')) {
|
|
require_once(dirname(__FILE__).'/../../classes/HTMLTemplatePrelevementSepaPdf.php');
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
$prev_obj = new PrevSepa((int)$id_sepa);
|
|
$prel_obj = new PrelevementSEPA();
|
|
$this->context->smarty->assign(array(
|
|
'sepa' => $prev_obj,
|
|
'conf' => $prel_obj->conf_keys,
|
|
'this_path_sepa' => $this->module->getPathUri(),
|
|
'shop_name' => $this->context->shop->name,
|
|
));
|
|
|
|
$template = $this->module->getLocalPath().'views/templates/front/pdf/'.$this->module->conf_keys['template'].'.tpl';
|
|
if (file_exists(_PS_THEME_DIR_.'modules/'.$this->module->name.'/views/templates/front/pdf/'.$this->module->conf_keys['template'].'.tpl')) {
|
|
$template = _PS_THEME_DIR_.'modules/'.$this->module->name.'/views/templates/front/pdf/'.$this->module->conf_keys['template'].'.tpl';
|
|
}
|
|
|
|
$prev_obj->html = $this->context->smarty->fetch($template);
|
|
$pdf = new PDF($prev_obj, 'PrelevementSepaPdf', Context::getContext()->smarty, 'P');
|
|
$pdf->render();
|
|
die();
|
|
}
|
|
$this->customProcess();
|
|
parent::initContent();
|
|
$this->assign();
|
|
}
|
|
|
|
/**
|
|
* Assign wishlist template
|
|
*/
|
|
public function assign()
|
|
{
|
|
if (!$this->context->customer->isLogged()) {
|
|
Tools::redirect('index.php?controller=authentication&back='
|
|
.urlencode($this->context->link->getModuleLink('prelevementsepa', 'mandatsepa')));
|
|
}
|
|
|
|
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
if (!is_null($id_sepa)) {
|
|
//$prev_obj->id_customer = (int)$this->context->customer->id;
|
|
// $prev_obj->etat = 0;
|
|
// $prev_obj->save();
|
|
// $id_sepa = $prev_obj->id;
|
|
// } else {
|
|
$prel_obj = new PrelevementSEPA();
|
|
if ($prel_obj->isConnected() && $prel_obj->sms_solde>0) {
|
|
$this->context->controller->addCSS($this->module->getLocalPath().'views/css/intlTelInput.css');
|
|
$this->context->controller->addCSS($this->module->getLocalPath().'views/css/sepamandate.css');
|
|
$this->context->controller->addJS($this->module->getLocalPath().'views/js/intlTelInput.js');
|
|
$this->context->controller->addJS($this->module->getLocalPath().'views/js/sepamandate.js');
|
|
$this->context->smarty->assign('smsvalidation', 1);
|
|
}
|
|
}
|
|
$sepa = new PrevSepa((int)$id_sepa);
|
|
$this->context->smarty->assign(array(
|
|
'id_customer' => (int)$this->context->customer->id,
|
|
'customer_country' => $this->context->country->iso_code,
|
|
'errors' => $this->errors,
|
|
'sepa' => $sepa,
|
|
));
|
|
if (version_compare(_PS_VERSION_, '1.7', '<')) {
|
|
$this->setTemplate('1.6/mandatsepa.tpl');
|
|
} else {
|
|
$this->setTemplate('module:prelevementsepa/views/templates/front/1.7/mandatsepa.tpl');
|
|
}
|
|
}
|
|
|
|
public function customProcess()
|
|
{
|
|
if (Tools::getIsset('submitSepa')) {
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
if (!is_null($id_sepa)) {
|
|
$prev_obj = new PrevSepa($id_sepa);
|
|
} else {
|
|
$prev_obj->etat = 0;
|
|
}
|
|
if (Tools::strlen($prev_obj->rum) < 3) {
|
|
$prev_obj->rum = 'UI'.date('Ymd').Tools::passwdGen(12, 'NUMERIC');
|
|
}
|
|
if (empty(Tools::getValue('sepa_name'))) {
|
|
$this->errors[] = $this->module->l("You must fill the account holder's name", 'mandatsepa');
|
|
} else {
|
|
$prev_obj->name = Tools::getValue('sepa_name');
|
|
}
|
|
if (empty(Tools::getValue('sepa_address'))) {
|
|
$this->errors[] = $this->module->l("You must fill the account holder's address", 'mandatsepa');
|
|
} else {
|
|
$prev_obj->address = Tools::getValue('sepa_address');
|
|
}
|
|
require($this->module->getLocalPath().'libs/oophp-iban.php');
|
|
$iban = str_replace(' ', '', Tools::strtoupper(Tools::getValue('sepa_iban')));
|
|
$bicbnc = str_replace(' ', '', Tools::strtoupper(Tools::getValue('sepa_bic')));
|
|
if (Tools::strlen($iban) > 3) {
|
|
$ibanObj = new IBAN($iban);
|
|
if ($ibanObj->Verify()) {
|
|
$prev_obj->iban = $iban;
|
|
} else {
|
|
$this->errors[] = $this->module->l("Your IBAN is incorrect");
|
|
}
|
|
} else {
|
|
$this->errors[] = $this->module->l("Your IBAN is incorrect");
|
|
}
|
|
if (preg_match('#^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$#', $bicbnc)) {
|
|
$prev_obj->bic = $bicbnc;
|
|
} else {
|
|
$this->errors[] = $this->module->l("Your BIC/BNC is incorrect", 'mandatsepa');
|
|
}
|
|
if (!$this->errors) {
|
|
$prev_obj->id_customer = (int)$this->context->customer->id;
|
|
$prev_obj->save();
|
|
}
|
|
// die(var_dump($this->errors));
|
|
}
|
|
|
|
if (Tools::getIsset('internationalphonenumber') && !Tools::getIsset('sepa_smscode')) {
|
|
$prel_obj = new PrelevementSEPA();
|
|
$code = rand(100000, 999999);
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
$prev_obj = new PrevSepa((int)$id_sepa);
|
|
$prev_obj->code = $code;
|
|
$prev_obj->phone = Tools::getValue('internationalphonenumber');
|
|
$prev_obj->save();
|
|
require_once($this->module->getLocalPath().'classes/SMSDecanet.php');
|
|
$sms_obj = new SMSDecanet();
|
|
$sms_obj->send(array(
|
|
'LOGIN' => $prel_obj->conf_keys['decanetlogin'],
|
|
'API_KEY' => $prel_obj->conf_keys['decanetapikey'],
|
|
'TO' => Tools::getValue('internationalphonenumber'),
|
|
'COUNTRY' => $this->context->country->iso_code,
|
|
'FROMNUM' => 'SEPA',
|
|
'SMS' => $this->module->l('Hello, your SEPA validation code is', 'mandatsepa').' : '.$code
|
|
));
|
|
$this->context->smarty->assign(array('smsvalidation' => 1, 'smscode' => 1));
|
|
} elseif (Tools::getIsset('sepa_smscode')) {
|
|
$prel_obj = new PrelevementSEPA();
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
$prev_obj = new PrevSepa((int)$id_sepa);
|
|
if ($prev_obj->code == Tools::getValue('sepa_smscode')) {
|
|
$prev_obj->datevalid = date('Y-m-d H:i:s');
|
|
$prev_obj->etat = 1;
|
|
$prev_obj->save();
|
|
|
|
$cust_orders = Order::getCustomerOrders($prev_obj->id_customer);
|
|
$listods = array();
|
|
if ($cust_orders) {
|
|
foreach ($cust_orders as $o) {
|
|
$listods[] = $o['id_order'];
|
|
}
|
|
PrevSepa::updateUnTraitSepaIDByOids($prev_obj->id, $listods);
|
|
}
|
|
|
|
require_once(dirname(__FILE__).'/../../classes/HTMLTemplatePrelevementSepaPdf.php');
|
|
$prev_obj = new PrevSepa();
|
|
$id_sepa = $prev_obj->existCustomer((int)$this->context->customer->id);
|
|
$prev_obj = new PrevSepa((int)$id_sepa);
|
|
$prel_obj = new PrelevementSEPA();
|
|
$this->context->smarty->assign(array(
|
|
'sepa' => $prev_obj,
|
|
'conf' => $prel_obj->conf_keys
|
|
));
|
|
$prev_obj->html = $this->context->smarty->fetch(
|
|
$this->module->getLocalPath().'views/templates/front/mandate.tpl'
|
|
);
|
|
$pdf = new PDFCore($prev_obj, 'PrelevementSepaPdf', Context::getContext()->smarty, 'P');
|
|
$pdf->filename = _PS_UPLOAD_DIR_.'sepa/'.sha1($prev_obj->rum.$prev_obj->id_customer).'.pdf';
|
|
$pdf->render('F');
|
|
} else {
|
|
$this->errors[] = $this->module->l(
|
|
'Your validation code is incorrect. Please try again.',
|
|
'mandatsepa'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|