-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoin.php
248 lines (212 loc) · 9.11 KB
/
bitcoin.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
<?php
/**
* 2013-2015 ZL Development
*
* 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 Bitcoin module to newer
* versions in the future. If you wish to customize Bitcoin module for your
* needs please refer to http://www.prestashop.com for more information.
*
* @package Bitcoin
* @author Zakaria Lounes <[email protected]>
* @copyright 2013-2015 ZL Development
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* @note Property of ZL Development
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once(_PS_MODULE_DIR_.'bitcoin/classes/BitcoinInstall.php');
/**
* Description of Bitcoin
*
* @author Zakaria Lounes <[email protected]>
*/
class Bitcoin extends PaymentModule {
public function __construct() {
$this->name = 'bitcoin';
$this->tab = 'payments_gateways';
$this->version = '1.0.0';
$this->author = 'Zakaria Lounes';
$this->need_instance = 1;
$this->ps_versions_compliancy = array('min' => '1.5');
$this->currencies = true;
$this->currencies_mode = 'checkbox';
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Bitcoin');
$this->description = $this->l('Ce module vous permet d\'accepter des paiements par bitcoin.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}
public function install() {
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!parent::install() || !$this->registerHook('displayHeader') ||
!$this->registerHook('displayPayment') || !$this->registerHook('displayPaymentReturn')) {
return false;
}
BitcoinInstall::install('1K3BvpG8DwL[]/û4MirbtCHF3udrdwmS', '', 25);
return true;
}
public function uninstall() {
if (!parent::uninstall() ||
!Configuration::deleteByName(BitcoinInstall::$psBitcoinAddr) ||
!Configuration::deleteByName(BitcoinInstall::$psBitcoinSecret) ||
!Configuration::deleteByName(BitcoinInstall::$psBitcoinCallLimit)) {
return false;
}
BitcoinInstall::uninstall();
return true;
}
public function getContent() {
if (!$this->active) {
return;
}
$output = null;
if (Tools::isSubmit('submit' . $this->name)) {
$inputs = array(
BitcoinInstall::$psBitcoinAddr,
BitcoinInstall::$psBitcoinSecret,
BitcoinInstall::$psBitcoinCallLimit
);
$errors_msg = null;
foreach ($inputs as $input) {
$setting = (string)Tools::getValue($input);
if (!$setting || empty($setting) || !Validate::isGenericName($setting)) {
$errors_msg .= $this->l($input.': Invalid Configuration value').'<br />';
} else {
Configuration::updateValue($input, $setting);
}
}
if (empty($errors_msg)) {
$output = $this->displayConfirmation($this->l('Bitcoin settings updated.'));
} else {
$output = $this->displayError($errors_msg);
}
}
return $output . $this->displayForm();
}
public function displayForm() {
if (!$this->active) {
return;
}
// Get default Language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
// Init Fields form array
$fields_form = array(
array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Bitcoin Address'),
'name' => BitcoinInstall::$psBitcoinAddr,
'required' => true,
'placeholder' => $this->l('Your Receiving Bitcoin Address (Where you would like the payment to be sent)')
),
array(
'type' => 'text',
'label' => $this->l('Secret Key'),
'name' => BitcoinInstall::$psBitcoinSecret,
'required' => true,
'placeholder' => $this->l('Your secret key')
),
array(
'type' => 'text',
'label' => $this->l('Blockchain API call limit'),
'name' => BitcoinInstall::$psBitcoinCallLimit,
'required' => true,
'placeholder' => $this->l('Maximum API call')
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
)
)
);
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true;
$helper->submit_action = 'submit' . $this->name;
$helper->toolbar_btn = array(
'save' => array(
'desc' => $this->l('Save'),
'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name .
'&token=' . Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
// Load current value
$helper->fields_value[BitcoinInstall::$psBitcoinAddr] = Configuration::get(BitcoinInstall::$psBitcoinAddr);
$helper->fields_value[BitcoinInstall::$psBitcoinSecret] = Configuration::get(BitcoinInstall::$psBitcoinSecret);
$helper->fields_value[BitcoinInstall::$psBitcoinCallLimit] = Configuration::get(BitcoinInstall::$psBitcoinCallLimit);
return $helper->generateForm($fields_form);
}
public function hookDisplayHeader() {
if (!$this->active) {
return;
}
if (get_class($this->context->controller) === "OrderController" && $this->context->controller->step === 3) {
$this->context->controller->addCSS($this->_path . 'css/bitcoin.css', 'all');
} else if (get_class($this->context->controller) === "BitcoinValidationModuleFrontController") {
$this->context->controller->addCSS($this->_path . 'css/bitcoin.css', 'all');
}
}
public function hookDisplayPayment() {
if (!$this->active) {
return;
}
$this->smarty->assign(array(
'this_path' => $this->_path, // keep for retro compatatibility
'this_path_cod' => $this->_path,
'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}
public function hookDisplayPaymentReturn($params) {
if (!$this->active) {
return;
}
return $this->display(__FILE__, 'confirmation.tpl');
}
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $transaction = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) {
if (!$this->active) {
return;
}
if (version_compare(_PS_VERSION_, '1.5', '<')) {
parent::validateOrder((int)$id_cart, (int)$id_order_state, (float)$amount_paid, $payment_method, $message, $transaction, $currency_special, $dont_touch_amount, $secure_key);
} else {
parent::validateOrder((int)$id_cart, (int)$id_order_state, (float)$amount_paid, $payment_method, $message, $transaction, $currency_special, $dont_touch_amount, $secure_key, $shop);
}
}
}