-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkkiapay.php
404 lines (339 loc) · 14.8 KB
/
kkiapay.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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?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
*/
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
if (!defined('_PS_VERSION_')) {
exit;
}
class Kkiapay extends PaymentModule
{
protected $config_form = false;
public function __construct()
{
$this->name = 'kkiapay';
$this->tab = 'payments_gateways';
$this->version = '1.0.0';
$this->author = 'kkiapay';
$this->need_instance = 0;
$this->module_key = 'eea9595b905b3279e130609bea3c0c9e';
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('kkiapay');
$this->description = $this->l('kkiaPay permet aux entreprises de recevoir des paiements en toute sécurité via de l\'argent mobile, une carte de crédit ou un compte bancaire.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
$this->limited_currencies = array('XOF');
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install()
{
Configuration::updateValue('KKIAPAY_LIVE_MODE', false);
return parent::install() &&
$this->registerHook('header') &&
$this->registerHook('paymentOptions');
}
public function uninstall()
{
Configuration::deleteByName('KKIAPAY_LIVE_MODE');
return parent::uninstall();
}
public function hookPaymentOptions($params)
{
$currency_id = $params['cart']->id_currency;
$currency = new Currency((int)$currency_id);
if (in_array($currency->iso_code, $this->limited_currencies ) == false ){
return false;
}
$key = Configuration::get('KKIAPAY_PUBLIC');
$color = Configuration::get('KKIAPAY_COLOR');
$test = Configuration::get('KKIAPAY_CHECKBOX');
$position= Configuration::get('KKIAPAY_POSITION');
$private_key= Configuration::get('KKIAPAY_PRIVATE');
$secret = Configuration::get('KKIAPAY_SECRET');
$firstname_customer=($params['cookie']->customer_firstname);
$lastname_customer=($params['cookie']->customer_lastname);
$price= $params['cart']->getOrderTotal();
//var_dump($this->module->currentOrder);
$mylink = $this->context->link->getModuleLink('kkiapay', 'api');
$mylink = $mylink.'?success=kkiapayojhsbbbes12345';
//var_dump($mylink);
$this->context->smarty->assign('firstname', $firstname_customer);
$this->context->smarty->assign('lastname', $lastname_customer);
$this->context->smarty->assign('api', $key);
$this->context->smarty->assign('price', $price);
$this->context->smarty->assign('color', $color);
$this->context->smarty->assign('position', $position);
$this->context->smarty->assign('url', $mylink);
$this->context->smarty->assign('secret', $secret);
$this->context->smarty->assign('test', $test);
$this->context->smarty->assign('private', $private_key);
$paymentForm = $this->fetch('module:kkiapay/views/templates/admin/hook/front/api/payment.tpl');
$cardPaymentOption = new PaymentOption();
$options = $cardPaymentOption->setCallToActionText('Payez par Mobile Money et par Carte Bancaire (Kkiapay)')
->setAdditionalInformation($paymentForm)
->setAction($this->context->link->getModuleLink($this->name, 'confirmation', array(), true))
->setLogo(Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/logo.svg'));
return [$options];
}
public function getOptions()
{
$options = array (
array (
'id_checkbox_options' => 1,
'checkbox_options_name' => '',
'checked' => 'checked' )
);
return $options;
}
public function hookPaymentReturn($params)
{
// die();
if (!$this->active) {
return;
}
if (!isset($params['order']) || ($params['order']->module != $this->name)) {
return false;
}
if (isset($params['order']) && Validate::isLoadedObject($params['order']) && isset($params['order']->valid)) {
$this->smarty->assign(array(
'id_order' => $params['order']->id,
'valid' => $params['order']->valid,
));
}
if (isset($params['order']->reference) && !empty($params['order']->reference)) {
$this->smarty->assign('reference', $params['order']->reference);
}
$this->smarty->assign(array(
'shop_name' => $this->context->shop->name,
'reference' => $params['order']->reference,
'contact_url' => $this->context->link->getPageLink('contact', true)
));
return $this->fetch('kkiapay/views/templates/admin/hook/front/api/payment_return.tpl');
}
public function hookActionValidateOrder($params){
var_dump($params);
die('');
}
public function getContent()
{
$output = null;
// $myModuleName = strval(Tools::getValue('password'));
// die($myModuleName);
if (Tools::isSubmit('submit'.$this->name)) {
$myModuleName = (string)Tools::getValue('KKIAPAY_PUBLIC');
$myModulePrivate = (string)Tools::getValue('KKIAPAY_PRIVATE');
$myModuleSecret = (string)Tools::getValue('KKIAPAY_SECRET');
$myModuleColor = (string)Tools::getValue('KKIAPAY_COLOR');
$myModuleCheckbox = (string)Tools::getValue('KKIAPAY_CHECKBOX');
$myModulePosition = (string)Tools::getValue('KKIAPAY_POSITION');
$v = (string)Tools::getValue('api');
// var_dump($myModuleCheckbox);die();
if (
!$myModuleName ||
empty($myModuleName) ||
!Validate::isGenericName($myModuleName)
) {
$output .= $this->displayError($this->l('Valeurs de configurations invalides'));
} else {
Configuration::updateValue('KKIAPAY_PUBLIC', $myModuleName);
Configuration::updateValue('KKIAPAY_PRIVATE', $myModulePrivate);
Configuration::updateValue('KKIAPAY_SECRET', $myModuleSecret);
Configuration::updateValue('KKIAPAY_COLOR', $myModuleColor);
Configuration::updateValue('KKIAPAY_CHECKBOX',$myModuleCheckbox );
Configuration::updateValue('KKIAPAY_POSITION',$myModulePosition );
$output .= $this->displayConfirmation($this->l('Paramètres mis à jour'));
}
}
return $output.$this->displayForm();
}
public function displayForm()
{
$password = (string)Tools::getValue('password');
// var_dump($password);die();
// if($password) {
// // only save if a value was entered
// Configuration::updateValue('passwordKey', $password);
// }
$options_test = array(
array(
'id_option' => '1',
'name' => $this->l('Oui')
),
array(
'id_option' => '0',
'name' => $this->l('Non')
)
);
$options = array(
array(
'id_option' => 'right',
'name' => $this->l('A droite de la page')
),
array(
'id_option' => 'center',
'name' => $this->l('Au Centre de la page')
),
array(
'id_option'=>'left',
'name'=>$this->l('A Gauche de la page')
)
);
// Get default language
$this->hookDisplayHeader();
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
$fieldsForm=array();
// Init Fields form array
$fieldsForm[0]['form'] = [
'legend' => [
'title' => $this->l('Paramètres'),
],
'input' => [
array(
'type' => 'switch',
'label' => $this->l('Activez le mode test'),
'desc'=> $this->l('Configurez sur oui pour mettre en environnement sandbox'),
'name' => 'KKIAPAY_CHECKBOX',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => "1",
'label' => $this->trans('Enabled', array(), 'Admin.Global'),
),
array(
'id' => 'active_off',
'value' => "0",
'label' => $this->trans('Disabled', array(), 'Admin.Global'),
)
),
)
,
[
'col' => '6',
'type' => 'text',
'label' => $this->l('Clé publique'),
'name' => 'KKIAPAY_PUBLIC',
'class'=>'form-control',
'desc'=> $this->l('Obtenez vos clés d\'API sur le dashboard kkiapay dans la section Développeurs'),
'required' => true
],
[
'col' => '6',
'type' => 'text',
'label' => $this->l('Clé privé'),
'name' => 'KKIAPAY_PRIVATE',
'class'=>'form-control',
'desc'=> $this->l('Obtenez vos clés d\'API sur le dashboard kkiapay dans la section Développeurs'),
],
[
'col' => '6',
'type' => 'text',
'label' => $this->l('Secret'),
'name' => 'KKIAPAY_SECRET',
'size' => 20,
'class'=>'form-control',
'desc'=> $this->l('Obtenez vos clés d\'API sur le dashboard kkiapay dans la section Développeurs'),
]
,
[
'col' => '6',
'type' => 'text',
'label' => $this->l('Couleur du widget kkiapay'),
'name' => 'KKIAPAY_COLOR',
'class'=>'form-control',
'desc'=> $this->l('Paramétrez la couleur de la fenêtre kkiapay. Pour une meilleure harmonisation, utilisez la couleur dominante de votre site ou laissez vide.'),
]
,
array(
'type' => 'select',
'lang' => true,
'label' => $this->l('Disposition du widget kkiapay'),
'name' => 'KKIAPAY_POSITION',
'class'=>'form-control',
'desc'=> $this->l('Utilisez cette option pour contrôler l\'endroit où la fenêtre kkiapay devrait s\'afficher sur votre site'),
'options' => array(
'query' => $options,
'id' => 'id_option',
'name' => 'name'
),
),
],
'submit' => [
'title' => $this->l('Sauvegarder'),
'class' => 'btn btn-default pull-right'
]
];
$helper = new HelperForm();
// $helper->fields_value["KKIAPAY_CHECKBOX_1"] = true;
// Module, token and currentIndex
$helper->module = $this->module;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $defaultLang;
$helper->allow_employee_form_lang = $defaultLang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true; // false -> remove toolbar
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'submit'.$this->name;
$helper->toolbar_btn = [
'save' => [
'desc' => $this->l('Sauvegarder'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
],
'back' => [
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Retour à la liste')
]
];
// Load current value
// die(Configuration::get('KKIAPAY_NAME'));
// var_dump(Configuration::get('KKIAPAY_CHECKBOX_1'));
// die();
$myModulePosition=Configuration::get('KKIAPAY_POSITION');
// var_dump($myModulePosition);
// die();
$helper->fields_value['KKIAPAY_PUBLIC'] = Configuration::get('KKIAPAY_PUBLIC');
$helper->fields_value['KKIAPAY_SECRET'] = Configuration::get('KKIAPAY_SECRET');
$helper->fields_value['KKIAPAY_PRIVATE'] = Configuration::get('KKIAPAY_PRIVATE');
$helper->fields_value['KKIAPAY_COLOR'] = Configuration::get('KKIAPAY_COLOR');
$helper->fields_value['KKIAPAY_CHECKBOX'] = Configuration::get('KKIAPAY_CHECKBOX');
$helper->fields_value['KKIAPAY_POSITION'] = Configuration::get('KKIAPAY_POSITION');
return $helper->generateForm($fieldsForm);
}
public function hookDisplayHeader()
{
// die();
$this->context->controller->addCSS($this->_path.'views/css/front.css', 'all');
}
}