forked from PrestaShopCorp/payplug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallPayplug.php
More file actions
executable file
·312 lines (282 loc) · 9.72 KB
/
installPayplug.php
File metadata and controls
executable file
·312 lines (282 loc) · 9.72 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
/**
* 2013 - 2014 PayPlug SAS
*
* 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.prestashop.com for more information.
*
* @author PayPlug SAS
* @copyright 2013 - 2014 PayPlug SAS
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PayPlug SAS
*/
if (!defined('_PS_VERSION_'))
exit;
class InstallPayplug
{
/**
* Available types
* @var array
*/
private static $available_types = array(
'waiting',
'paid',
'refund',
'paid_test',
'refund_test',
'waiting_test'
);
public function createConfig()
{
Configuration::updateValue('PAYPLUG_MODULE_KEY', '');
Configuration::updateValue('PAYPLUG_MODULE_PUBLIC_KEY', '');
Configuration::updateValue('PAYPLUG_MODULE_URL', '');
Configuration::updateValue('PAYPLUG_MODULE_MIN_AMOUNT', '');
Configuration::updateValue('PAYPLUG_MODULE_MAX_AMOUNT', '');
Configuration::updateValue('PAYPLUG_MODULE_CURRENCIES', '');
Payplug::updateConfiguration('PAYPLUG_SANDBOX', '');
Payplug::updateConfiguration('PAYPLUG_DEBUG', '');
}
/**
* Update configuration
* @param string $private_key Private key
* @param string $public_key Public key
* @param string $url Url
* @param string $min_amount Min amount
* @param string $max_amount Max amount
* @param string $currencies Available currencies
* @param boolean $debug Mod sandbox or not
*/
public function updateConfig($private_key = '', $public_key = '', $url = '', $min_amount = '', $max_amount = '', $currencies = '', $sandbox = null)
{
Configuration::updateValue('PAYPLUG_MODULE_KEY', ''.$private_key.'');
Configuration::updateValue('PAYPLUG_MODULE_PUBLIC_KEY', ''.$public_key.'');
Configuration::updateValue('PAYPLUG_MODULE_URL', ''.$url.'');
Configuration::updateValue('PAYPLUG_MODULE_MIN_AMOUNT', $min_amount);
Configuration::updateValue('PAYPLUG_MODULE_MAX_AMOUNT', $max_amount);
Configuration::updateValue('PAYPLUG_MODULE_CURRENCIES', $currencies);
Payplug::updateConfiguration('PAYPLUG_SANDBOX', $sandbox);
}
public function deleteConfig()
{
Configuration::deleteByName('PAYPLUG_MODULE_KEY');
Configuration::deleteByName('PAYPLUG_MODULE_PUBLIC_KEY');
Configuration::deleteByName('PAYPLUG_MODULE_URL');
Configuration::deleteByName('PAYPLUG_MODULE_MIN_AMOUNT', '');
Configuration::deleteByName('PAYPLUG_MODULE_MAX_AMOUNT', '');
Configuration::deleteByName('PAYPLUG_MODULE_CURRENCIES', '');
Configuration::deleteByName('PAYPLUG_SANDBOX', '');
Configuration::deleteByName('PAYPLUG_DEBUG', '');
}
/**
* Create PayPlug order states waiting and paid and save their id in Configuration
*/
public function createOrderState()
{
// Key => status type, value => Prestashop Default Configuration
$state_key = array(
'paid' => 'PS_OS_PAYMENT',
'refund' => 'PS_OS_REFUND',
'waiting' => null,
);
// Loop keys
foreach ($state_key as $key => $cfg)
{
// Configuration key
$key_config = 'PAYPLUG_ORDER_STATE_'.Tools::strtoupper($key);
// If config is not null
if ($cfg != null)
{
// Update OS PayPlug payment
if (defined('_'.$cfg.'_') || Payplug::getConfiguration($cfg))
{
// If is in configuration (since 1.5)
if (!($os = Configuration::get($cfg)))
$os = constant('_'.$cfg.'_');
// Update configuration
Payplug::updateConfiguration($key_config, (int)$os);
}
}
// Create Order State if "Prestashop Default Configuration" is null
else
$this->createOrderStateSpecifc($key);
// Create os tests
$this->createOrderStateSpecifc($key, true);
}
}
/**
* Create order
* @param string $key OS Key
* @param boolean $test if os test
*/
private function createOrderStateSpecifc($key, $test = false)
{
// Logo source
$source = dirname(__FILE__).'/logo.gif';
// If is an OS test
if ($test == true)
$key .= '_test';
// Configuration key
$key_config = 'PAYPLUG_ORDER_STATE_'.Tools::strtoupper($key);
// If configuration not exists
if (!($os = Payplug::getConfiguration($key_config)))
{
// New state
$order_state = new OrderState();
// Init state
$this->initOrderState($order_state, Tools::strtolower($key));
// Add state
if ($order_state->add())
{
// Change
$destination = _PS_IMG_DIR_.'os/'.(int)$order_state->id.'.gif';
copy($source, $destination);
}
// Update configuration
Payplug::updateConfiguration($key_config, (int)$order_state->id);
}
// if configuration exists update status
else
{
// Get status
$order_state = new OrderState($os);
// Init status
$this->initOrderState($order_state, Tools::strtolower($key));
// Update status
$order_state->update();
}
}
/**
* Init parameters of PayPlug order states
*/
private function initOrderState(&$order_state = null, $type = null)
{
// Check if parameters is not null & if $type is an available type
if (is_null($order_state) || is_null($type) || !in_array($type, self::$available_types))
return;
$order_state->name = $this->getOrderStateName($type);
$order_state->send_email = false;
// OS Waiting or Waiting test
if ($type == 'waiting' || $type == 'waiting_test')
{
$order_state->color = '#a1f8a1';
$order_state->logable = false;
}
// OS Refund or Refund test
else if ($type == 'refund' || $type == 'refund_test')
{
$order_state->color = '#EA3737';
$order_state->logable = false;
}
// OS Paid or Paid test
else if ($type == 'paid' || $type == 'paid_test')
{
$order_state->color = '#04B404';
$order_state->send_email = true;
if (version_compare(_PS_VERSION_, '1.5', '<'))
{
$template = array();
foreach (Language::getLanguages() as $language)
$template[$language['id_lang']] = 'payment';
$order_state->template = $template;
}
else
{
$order_state->template = 'payment';
$order_state->paid = true;
}
$order_state->logable = true;
}
$order_state->module_name = 'payplug';
$order_state->hidden = false;
$order_state->delivery = false;
$order_state->invoice = true;
}
/**
* Get names in different languages for PayPlug order states waiting and paid
*/
private function getOrderStateName($type = null)
{
// Check if parameters is not null & if $type is an available type
if (is_null($type) || !in_array($type, self::$available_types))
return;
$order_state_name = array();
foreach (Language::getLanguages() as $language)
{
if (Tools::strtolower($language['iso_code']) == 'fr')
{
if ($type == 'waiting')
$order_state_name[$language['id_lang']] = 'Paiement en cours [PayPlug]';
else if ($type == 'waiting_test')
$order_state_name[$language['id_lang']] = 'Paiement en cours [TEST]';
else if ($type == 'refund_test')
$order_state_name[$language['id_lang']] = 'Remboursé [TEST]';
elseif ($type == 'paid_test')
$order_state_name[$language['id_lang']] = 'Paiement effectué [TEST]';
}
else if (Tools::strtolower($language['iso_code']) == 'es')
{
if ($type == 'waiting')
$order_state_name[$language['id_lang']] = 'Pago en curso [PayPlug]';
else if ($type == 'waiting_test')
$order_state_name[$language['id_lang']] = 'Pago en curso [TEST]';
else if ($type == 'refund_test')
$order_state_name[$language['id_lang']] = 'Reembolsado [TEST]';
elseif ($type == 'paid_test')
$order_state_name[$language['id_lang']] = 'Pago efectuado [TEST]';
}
else if (Tools::strtolower($language['iso_code']) == 'it')
{
if ($type == 'waiting')
$order_state_name[$language['id_lang']] = 'Pagamento in corso [PayPlug]';
else if ($type == 'waiting_test')
$order_state_name[$language['id_lang']] = 'Pagamento in corso [TEST]';
else if ($type == 'refund_test')
$order_state_name[$language['id_lang']] = 'Rimborsato [TEST]';
elseif ($type == 'paid_test')
$order_state_name[$language['id_lang']] = 'Pagamento effettuato [TEST]';
}
else
{
if ($type == 'waiting')
$order_state_name[$language['id_lang']] = 'Payment in progress [PayPlug]';
if ($type == 'waiting_test')
$order_state_name[$language['id_lang']] = 'Payment in progress [TEST]';
else if ($type == 'refund_test')
$order_state_name[$language['id_lang']] = 'Refunded [TEST]';
elseif ($type == 'paid_test')
$order_state_name[$language['id_lang']] = 'Payment successful [TEST]';
}
}
return $order_state_name;
}
public function installPayplugLock()
{
$SQL = "
CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."payplug_lock` (
`id_payplug_lock` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_cart` INT NOT NULL,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL
) ENGINE="._MYSQL_ENGINE_." ";
$return = DB::getInstance()->Execute($SQL);
}
public function uninstallPayplugLock()
{
$SQL = " DROP TABLE IF EXISTS `"._DB_PREFIX_."payplug_lock` ";
$return = DB::getInstance()->Execute($SQL);
}
}