1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* NOTICE OF LICENSE |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2019 B2BinPay |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
15
|
|
|
* copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
* |
25
|
|
|
* @author B2BINPAY <[email protected]> |
26
|
|
|
* @copyright 2019 B2BinPay |
27
|
|
|
* @license https://github.com/b2binpay/prestashop/blob/master/LICENSE The MIT License (MIT) |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
use B2Binpay\Exception\B2BinpayException; |
31
|
|
|
|
32
|
|
|
class B2binpayRedirectModuleFrontController extends ModuleFrontController |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
public function postProcess() |
35
|
|
|
{ |
36
|
|
|
$cart = $this->context->cart; |
37
|
|
|
|
38
|
|
|
if ($cart->id_customer == 0 |
39
|
|
|
|| $cart->id_address_delivery == 0 |
40
|
|
|
|| $cart->id_address_invoice == 0 |
41
|
|
|
|| !$this->module->active |
42
|
|
|
|| empty($_REQUEST['b2binpay-crypto']) |
43
|
|
|
) { |
44
|
|
|
Tools::redirect('index.php?controller=order&step=1'); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$authorized = false; |
48
|
|
|
|
49
|
|
|
foreach (Module::getPaymentModules() as $module) { |
|
|
|
|
50
|
|
|
if ($module['name'] == 'b2binpay') { |
51
|
|
|
$authorized = true; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (!$authorized) { |
57
|
|
|
die($this->module->l('This payment method is not available.', 'redirect')); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$customer = new Customer($cart->id_customer); |
|
|
|
|
61
|
|
|
|
62
|
|
|
if (!Validate::isLoadedObject($customer)) { |
|
|
|
|
63
|
|
|
Tools::redirect('index.php?controller=order&step=1'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$wallet_id = $_REQUEST['b2binpay-crypto']; |
67
|
|
|
$wallet_list = json_decode(Configuration::get('B2BINPAY_WALLETS'), true); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$wallet = array_reduce( |
70
|
|
|
$wallet_list, |
71
|
|
|
function ($carry, $item) use ($wallet_id) { |
72
|
|
|
if ($item['id'] === $wallet_id) { |
73
|
|
|
$carry = $item; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $carry; |
77
|
|
|
}, |
78
|
|
|
array() |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$currency = $this->context->currency; |
82
|
|
|
$total = (string)$cart->getOrderTotal(true, Cart::BOTH); |
|
|
|
|
83
|
|
|
|
84
|
|
|
$amount = $this->module->provider->convertCurrency( |
85
|
|
|
(string)$total, |
86
|
|
|
$currency->iso_code, |
87
|
|
|
$wallet['alpha'] |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
if (!empty(Configuration::get('B2BINPAY_MARKUP'))) { |
91
|
|
|
$amount = $this->module->provider->addMarkup( |
92
|
|
|
$amount, |
93
|
|
|
$wallet['alpha'], |
94
|
|
|
Configuration::get('B2BINPAY_MARKUP') |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
try { |
99
|
|
|
$bill = $this->module->provider->createBill( |
100
|
|
|
$wallet['id'], |
101
|
|
|
$amount, |
102
|
|
|
$wallet['alpha'], |
103
|
|
|
Configuration::get('B2BINPAY_LIFETIME'), |
104
|
|
|
$cart->id, |
105
|
|
|
$this->context->link->getModuleLink($this->module->name, 'callback', array(), true) |
106
|
|
|
); |
107
|
|
|
} catch (B2BinpayException $e) { |
108
|
|
|
die($this->module->l('Payment error: '.$e->getMessage(), 'redirect')); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if (empty($bill) || empty($bill->url)) { |
112
|
|
|
die($this->module->l('Payment gateway error.', 'redirect')); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$message = "B2BinPay created new invoice for $amount ETH. Bill ID: $bill->id"; |
116
|
|
|
|
117
|
|
|
$this->module->validateOrder( |
118
|
|
|
$cart->id, |
119
|
|
|
Configuration::get('PS_OS_BANKWIRE'), |
120
|
|
|
$total, |
121
|
|
|
Configuration::get('B2BINPAY_TITLE'), |
122
|
|
|
$message, |
123
|
|
|
array(), |
124
|
|
|
(int)$currency->id, |
125
|
|
|
false, |
126
|
|
|
$customer->secure_key |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
Tools::redirect($bill->url); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths