-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaymentbasic.php
More file actions
246 lines (218 loc) · 7.86 KB
/
paymentbasic.php
File metadata and controls
246 lines (218 loc) · 7.86 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
<?php
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
if (!defined('_PS_VERSION_')) {
exit;
}
class PaymentBasic extends PaymentModule
{
protected $_html;
public function __construct()
{
$this->author = 'Delvis Tovar';
$this->name = 'paymentbasic';
$this->tab = 'payment_gateways';
$this->version = '1.0.0';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Payment Basic and API');
$this->description = $this->l('Payment default and api Delvis Tovar');
}
public function install()
{
if (!parent::install()
|| !$this->registerHook('paymentOptions')
|| !$this->registerHook('paymentReturn')
|| !$this->registerHook('actionFrontControllerSetMedia')
) {
return false;
}
return true;
}
/**
* PS 17
* @param type $params
* @return type
*/
public function hookPaymentOptions($params) {
if (!$this->active) {
return;
}
$standardPayment = new PaymentOption();
$inputs = [
[
'name' => 'custom_hidden_value',
'type' => 'hidden',
'value' => '30'
],
[
'name' => 'id_customer',
'type' => 'hidden',
'value' => $this->context->customer->id,
],
];
$standardPayment->setModuleName($this->name)
->setLogo($this->context->link->getBaseLink().'/modules/paymentbasic/views/img/logo.png')
->setInputs($inputs)
->setCallToActionText($this->l('Payment Default DT'))
->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true))
->setAdditionalInformation($this->fetch('module:paymentbasic/views/templates/hook/displayPayment.tpl'));
$this->smarty->assign(
$this->getPaymentApiVars()
);
$apiPayement = new PaymentOption();
$apiPayement->setModuleName($this->name)
->setCallToActionText($this->l('Payment Delvis Tovar (DT API)'))
//Définition d'un formulaire personnalisé
->setForm($this->fetch('module:paymentbasic/views/templates/hook/payment_api_form.tpl'))
->setAdditionalInformation($this->fetch('module:paymentbasic/views/templates/hook/displayPaymentApi.tpl'));
return [$standardPayment, $apiPayement];
}
/**
* payment api
* @return array
*/
public function getPaymentApiVars()
{
return [
'payment_url' => Configuration::get('PAYMENT_API_URL'),
'success_url' => Configuration::get('PAYMENT_API_URL_SUCESS'),
'error_url' => Configuration::get('PAYMENT_API_URL_ERROR'),
'id_cart' => $this->context->cart->id,
'cart_total' => $this->context->cart->getOrderTotal(true, Cart::BOTH),
'id_customer' => $this->context->cart->id_customer,
];
}
/**
* @param type $params
* @return type
*/
public function hookDisplayPaymentReturn($params)
{
if (!$this->active) {
return;
}
$this->smarty->assign(
$this->getTemplateVars()
);
return $this->fetch('module:paymentbasic/views/templates/hook/payment_return.tpl');
}
/**
* Configuration admin module
*/
public function getContent()
{
$this->_html .=$this->postProcess();
$this->_html .= $this->renderForm();
return $this->_html;
}
/**
* @return type
*/
public function postProcess()
{
if ( Tools::isSubmit('SubmitPaymentConfiguration'))
{
Configuration::updateValue('PAYMENT_API_URL', Tools::getValue('PAYMENT_API_URL'));
Configuration::updateValue('PAYMENT_API_URL_SUCESS', Tools::getValue('PAYMENT_API_URL_SUCESS'));
Configuration::updateValue('PAYMENT_API_URL_ERROR', Tools::getValue('PAYMENT_API_URL_ERROR'));
}
return $this->displayConfirmation($this->l('Configuration updated with success'));
}
/**
* Form configuration admin
*/
public function renderForm()
{
$fields_form = [
'form' => [
'legend' => [
'title' => $this->l('Payment Configuration'),
'icon' => 'icon-cogs'
],
'description' => $this->l('Sample configuration form'),
'input' => [
[
'type' => 'text',
'label' => $this->l('Payment api url'),
'name' => 'PAYMENT_API_URL',
'required' => true,
'empty_message' => $this->l('Please fill the payment api url'),
],
[
'type' => 'text',
'label' => $this->l('Payment api success url'),
'name' => 'PAYMENT_API_URL_SUCESS',
'required' => true,
'empty_message' => $this->l('Please fill the payment api success url'),
],
[
'type' => 'text',
'label' => $this->l('Payment api error url'),
'name' => 'PAYMENT_API_URL_ERROR',
'required' => true,
'empty_message' => $this->l('Please fill the payment api error url'),
],
],
'submit' => [
'title' => $this->l('Save'),
'class' => 'button btn btn-default pull-right',
],
],
];
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->id = 'crdspayment';
$helper->identifier = 'crdspayment';
$helper->submit_action = 'SubmitPaymentConfiguration';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = [
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
];
return $helper->generateForm(array($fields_form));
}
/**
*
*/
public function getConfigFieldsValues()
{
return [
'PAYMENT_API_URL' => Tools::getValue('PAYMENT_API_URL', Configuration::get('PAYMENT_API_URL')),
'PAYMENT_API_URL_SUCESS' => Tools::getValue('PAYMENT_API_URL_SUCESS', Configuration::get('PAYMENT_API_URL_SUCESS')),
'PAYMENT_API_URL_ERROR' => Tools::getValue('PAYMENT_API_URL_ERROR', Configuration::get('PAYMENT_API_URL_ERROR')),
];
}
/**
* @return array
*/
public function getTemplateVars()
{
return [
'shop_name' => $this->context->shop->name,
'custom_var' => $this->l('My custom var value'),
'payment_details' => $this->l('custom details'),
];
}
public function hookActionFrontControllerSetMedia(){
$this->context->controller->registerStylesheet(
'mymodule-style',
$this->_path.'views/css/paymentbasic.css',
[
'media' => 'all',
'priority' => 1000,
]
);
/*$this->context->controller->registerJavascript(
'mymodule-javascript',
$this->_path.'views/js/crdspayment.js',
[
'position' => 'bottom',
'priority' => 1000,
]
);*/
}
}