-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaymentexample.php
More file actions
383 lines (317 loc) · 11.2 KB
/
paymentexample.php
File metadata and controls
383 lines (317 loc) · 11.2 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
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
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* 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.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
$autoloadPath = __DIR__ . '/vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}
class PaymentExample extends PaymentModule
{
// >>>> Main settings <<<<
// const CONFIG_OS_OFFLINE = 'PAYMENTEXAMPLE_OS_OFFLINE';
// const CONFIG_PO_OFFLINE_ENABLED = 'PAYMENTEXAMPLE_PO_OFFLINE_ENABLED';
// const CONFIG_PO_EXTERNAL_ENABLED = 'PAYMENTEXAMPLE_PO_EXTERNAL_ENABLED';
// const CONFIG_PO_EMBEDDED_ENABLED = 'PAYMENTEXAMPLE_PO_EMBEDDED_ENABLED';
// const CONFIG_PO_BINARY_ENABLED = 'PAYMENTEXAMPLE_PO_BINARY_ENABLED';
// const MODULE_ADMIN_CONTROLLER = 'AdminConfigurePaymentExample';
const HOOKS = [
// 'actionPaymentCCAdd',
'actionObjectShopAddAfter',
'paymentOptions',
'displayAdminOrderLeft',
'displayAdminOrderMainBottom',
'displayCustomerAccount',
// 'displayOrderConfirmation',
// 'displayOrderDetail',
// 'displayPaymentByBinaries',
'displayPaymentReturn',
'displayPDFInvoice',
];
public function isUsingNewTranslationSystem() {
return true;
}
protected $_html = '';
protected $_postErrors = [];
public $details;
public $owner;
public $address;
public $extra_mail_vars;
public function __construct()
{
$this->name = 'paymentexample';
$this->tab = 'payments_gateways';
$this->version = '1.0.0';
$this->author = 'PrestaShop';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
$this->ps_versions_compliancy = [
'min' => '1.7.6',
'max' => '8.99.99'
];
$this->bootstrap = true;
$this->controllers = ['validation'];
parent::__construct();
$this->displayName = $this->trans('Payment Example', [], 'Modules.Paymentexample.Admin');
$this->description = $this->trans('Description of Payment Example', [], 'Modules.Paymentexample.Admin');
if (!count(Currency::checkPaymentCurrencies($this->id))) {
$this->warning = $this->trans('No currency has been set for this module.', [], 'Modules.Paymentexample.Admin');
}
}
/**
* @return bool
*/
public function install()
{
return (bool) parent::install()
&& (bool) $this->registerHook(static::HOOKS)
// && $this->installOrderState()
// && $this->installConfiguration()
// && $this->installTabs()
;
}
/**
* @return bool
*/
public function uninstall()
{
return (bool) parent::uninstall()
// && $this->deleteOrderState()
// && $this->uninstallConfiguration()
// && $this->uninstallTabs()
;
}
// public function getContent()
// {
// $p = new PaymentOptions();
// $p::test();
// }
// >>>> END Main settings <<<<
// >>>> Hooks <<<<
/**
* This hook called after a new Shop is created
*
* @param array $params
*/
public function hookActionObjectShopAddAfter(array $params)
{
if (empty($params['object'])) {
return;
}
/** @var Shop $shop */
$shop = $params['object'];
if (false === Validate::isLoadedObject($shop)) {
return;
}
$this->addCheckboxCarrierRestrictionsForModule([(int) $shop->id]);
$this->addCheckboxCountryRestrictionsForModule([(int) $shop->id]);
if ($this->currencies_mode === 'checkbox') {
$this->addCheckboxCurrencyRestrictionsForModule([(int) $shop->id]);
} elseif ($this->currencies_mode === 'radio') {
$this->addRadioCurrencyRestrictionsForModule([(int) $shop->id]);
}
}
/**
* @param array $params
*
* @return array Should always return an array
*/
public function hookPaymentOptions($params)
{
/** @var Cart $cart */
$cart = $params['cart'];
if (false === Validate::isLoadedObject($cart) || false === $this->checkCurrency($cart)) {
return [];
}
$payment = new PrestaShop\Module\PaymentExample\Payment($this);
$paymentOptions = [];
// if (Configuration::get(static::CONFIG_PO_OFFLINE_ENABLED)) {
$paymentOptions[] = $payment->getOfflinePaymentOption();
// }
/*
if (Configuration::get(static::CONFIG_PO_EXTERNAL_ENABLED)) {
$paymentOptions[] = $this->getExternalPaymentOption();
}
if (Configuration::get(static::CONFIG_PO_EMBEDDED_ENABLED)) {
$paymentOptions[] = $this->getEmbeddedPaymentOption();
}
if (Configuration::get(static::CONFIG_PO_BINARY_ENABLED)) {
$paymentOptions[] = $this->getBinaryPaymentOption();
}
*/
return $paymentOptions;
}
// public function hookPaymentReturn()
// {
// return $this->context->smarty->fetch('module:' . $this->name . '/views/templates/frontend/return.tpl');
// }
/**
* This hook is used to display additional information on BO Order View, under Payment block
*
* @since PrestaShop 1.7.7 This hook is replaced by displayAdminOrderMainBottom on migrated BO Order View
*
* @param array $params
*
* @return string
*/
public function hookDisplayAdminOrderLeft(array $params)
{
if (empty($params['id_order'])) {
return '';
}
$order = new Order((int) $params['id_order']);
if (false === Validate::isLoadedObject($order) || $order->module !== $this->name) {
return '';
}
$this->context->smarty->assign([
'moduleName' => $this->name,
'moduleDisplayName' => $this->displayName,
'moduleLogoSrc' => $this->getPathUri() . 'logo.png',
]);
return $this->context->smarty->fetch('module:paymentexample/views/templates/hook/displayAdminOrderLeft.tpl');
}
/**
* This hook is used to display additional information on BO Order View, under Payment block
*
* @since PrestaShop 1.7.7 This hook replace displayAdminOrderLeft on migrated BO Order View
*
* @param array $params
*
* @return string
*/
public function hookDisplayAdminOrderMainBottom(array $params)
{
if (empty($params['id_order'])) {
return '';
}
$order = new Order((int) $params['id_order']);
if (false === Validate::isLoadedObject($order) || $order->module !== $this->name) {
return '';
}
$this->context->smarty->assign([
'moduleName' => $this->name,
'moduleDisplayName' => $this->displayName,
'moduleLogoSrc' => $this->getPathUri() . 'logo.png',
]);
return $this->context->smarty->fetch('module:paymentexample/views/templates/hook/displayAdminOrderMainBottom.tpl');
}
/**
* This hook is used to display information in customer account
*
* @param array $params
*
* @return string
*/
public function hookDisplayCustomerAccount(array $params)
{
$this->context->smarty->assign([
'moduleDisplayName' => $this->displayName,
'moduleLogoSrc' => $this->getPathUri() . 'logo.png',
'transactionsLink' => $this->context->link->getModuleLink(
$this->name,
'account'
),
]);
return $this->context->smarty->fetch('module:paymentexample/views/templates/hook/displayCustomerAccount.tpl');
}
/**
* This hook is used to display additional information on bottom of order confirmation page
*
* @param array $params
*
* @return string
*/
public function hookDisplayPaymentReturn(array $params)
{
if (empty($params['order'])) {
return '';
}
/** @var Order $order */
$order = $params['order'];
if (false === Validate::isLoadedObject($order) || $order->module !== $this->name) {
return '';
}
$transaction = '';
if ($order->getOrderPaymentCollection()->count()) {
/** @var OrderPayment $orderPayment */
$orderPayment = $order->getOrderPaymentCollection()->getFirst();
$transaction = $orderPayment->transaction_id;
}
$this->context->smarty->assign([
'moduleName' => $this->name,
'transaction' => $transaction,
'transactionsLink' => $this->context->link->getModuleLink(
$this->name,
'account'
),
]);
return $this->context->smarty->fetch('module:paymentexample/views/templates/hook/displayPaymentReturn.tpl');
}
/**
* This hook is used to display additional information on Invoice PDF
*
* @param array $params
*
* @return string
*/
public function hookDisplayPDFInvoice(array $params)
{
if (empty($params['object'])) {
return '';
}
/** @var OrderInvoice $orderInvoice */
$orderInvoice = $params['object'];
if (false === Validate::isLoadedObject($orderInvoice)) {
return '';
}
$order = $orderInvoice->getOrder();
if (false === Validate::isLoadedObject($order) || $order->module !== $this->name) {
return '';
}
$transaction = '';
if ($order->getOrderPaymentCollection()->count()) {
/** @var OrderPayment $orderPayment */
$orderPayment = $order->getOrderPaymentCollection()->getFirst();
$transaction = $orderPayment->transaction_id;
}
$this->context->smarty->assign([
'moduleName' => $this->name,
'transaction' => $transaction,
]);
return $this->context->smarty->fetch('module:paymentexample/views/templates/hook/displayPDFInvoice.tpl');
}
// >>>> END Hooks <<<<
// >>>> Internal functionallity <<<<
public function checkCurrency($cart)
{
$currency_order = new Currency($cart->id_currency);
$currencies_module = $this->getCurrency($cart->id_currency);
if (is_array($currencies_module)) {
foreach ($currencies_module as $currency_module) {
if ($currency_order->id == $currency_module['id_currency']) {
return true;
}
}
}
return false;
}
// >>>> END Internal functionallity <<<<
}