-
Notifications
You must be signed in to change notification settings - Fork 8
/
prestapay.php
143 lines (127 loc) · 3.8 KB
/
prestapay.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
<?php
/**
* PrestaPay - A Sample Payment Module for PrestaShop 1.7
*
* This file is the declaration of the module.
*
* @author Andresa Martins <contact@andresa.dev>
* @license http://opensource.org/licenses/afl-3.0.php
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class PrestaPay extends PaymentModule
{
private $_html = '';
private $_postErrors = array();
public $address;
/**
* PrestaPay constructor.
*
* Set the information about this module
*/
public function __construct()
{
$this->name = 'prestapay';
$this->tab = 'payments_gateways';
$this->version = '1.0';
$this->author = 'Andresa Martins';
$this->controllers = array('payment', 'validation');
$this->currencies = true;
$this->currencies_mode = 'checkbox';
$this->bootstrap = true;
$this->displayName = 'PrestaPay';
$this->description = 'Sample Payment module developed for learning purposes.';
$this->confirmUninstall = 'Are you sure you want to uninstall this module?';
$this->ps_versions_compliancy = array('min' => '1.7.0', 'max' => _PS_VERSION_);
parent::__construct();
}
/**
* Install this module and register the following Hooks:
*
* @return bool
*/
public function install()
{
return parent::install()
&& $this->registerHook('paymentOptions')
&& $this->registerHook('paymentReturn');
}
/**
* Uninstall this module and remove it from all hooks
*
* @return bool
*/
public function uninstall()
{
return parent::uninstall();
}
/**
* Returns a string containing the HTML necessary to
* generate a configuration screen on the admin
*
* @return string
*/
public function getContent()
{
return $this->_html;
}
/**
* Display this module as a payment option during the checkout
*
* @param array $params
* @return array|void
*/
public function hookPaymentOptions($params)
{
/*
* Verify if this module is active
*/
if (!$this->active) {
return;
}
/**
* Form action URL. The form data will be sent to the
* validation controller when the user finishes
* the order process.
*/
$formAction = $this->context->link->getModuleLink($this->name, 'validation', array(), true);
/**
* Assign the url form action to the template var $action
*/
$this->smarty->assign(['action' => $formAction]);
/**
* Load form template to be displayed in the checkout step
*/
$paymentForm = $this->fetch('module:prestapay/views/templates/hook/payment_options.tpl');
/**
* Create a PaymentOption object containing the necessary data
* to display this module in the checkout
*/
$newOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption;
$newOption->setModuleName($this->displayName)
->setCallToActionText($this->displayName)
->setAction($formAction)
->setForm($paymentForm);
$payment_options = array(
$newOption
);
return $payment_options;
}
/**
* Display a message in the paymentReturn hook
*
* @param array $params
* @return string
*/
public function hookPaymentReturn($params)
{
/**
* Verify if this module is enabled
*/
if (!$this->active) {
return;
}
return $this->fetch('module:prestapay/views/templates/hook/payment_return.tpl');
}
}