-
Notifications
You must be signed in to change notification settings - Fork 6
/
WireTransfer.php
118 lines (98 loc) · 3.69 KB
/
WireTransfer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* web : http://www.thelia.net */
/* This program 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 */
/* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
namespace WireTransfer;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
use Thelia\Log\Tlog;
use Thelia\Model\MessageQuery;
use Thelia\Model\Order;
use Thelia\Module\AbstractPaymentModule;
/**
* Class WireTransfer.
*/
class WireTransfer extends AbstractPaymentModule
{
public const MESSAGE_DOMAIN = 'wiretransfer';
public function pay(Order $order): void
{
// Nothing special to do.
}
/**
* @return bool true if all parameters have been entered
*/
public function isValidPayment(): bool
{
// Check that all parameters have been entered.
$valid =
self::getConfigValue('name', '') !== ''
&&
self::getConfigValue('bic', '') !== ''
&&
self::getConfigValue('iban', '') !== ''
;
if (!$valid) {
Tlog::getInstance()->addError(
Translator::getInstance()->trans(
'Bank information parameters have not been defined.', [], self::MESSAGE_DOMAIN
)
);
}
return $valid && $this->getCurrentOrderTotalAmount() > 0;
}
public function install(ConnectionInterface $con = null): void
{
$database = new Database($con->getWrappedConnection());
// Insert email message
$database->insertSql(null, [__DIR__.'/Config/setup.sql']);
/* insert the images from image folder if not already done */
$moduleModel = $this->getModuleModel();
if (!$moduleModel->isModuleImageDeployed($con)) {
$this->deployImageFolder($moduleModel, sprintf('%s/images', __DIR__), $con);
}
}
public function destroy(ConnectionInterface $con = null, $deleteModuleData = false): void
{
// Delete our message
if (null !== $message = MessageQuery::create()->findOneByName('order_confirmation_wiretransfer')) {
$message->delete($con);
}
parent::destroy($con, $deleteModuleData);
}
/**
* if you want, you can manage stock in your module instead of order process.
* Return false to decrease the stock when order status switch to pay.
*/
public function manageStockOnCreation(): bool
{
return false;
}
public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR.ucfirst(self::getModuleCode()).'/I18n/*'])
->autowire(true)
->autoconfigure(true);
}
}