|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Wirecard Brasil. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bruno Elisei <[email protected]> |
|
6
|
|
|
* See COPYING.txt for license details. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Moip\Magento2\Block; |
|
10
|
|
|
|
|
11
|
|
|
use Magento\Backend\Model\Session\Quote; |
|
|
|
|
|
|
12
|
|
|
use Magento\Framework\Pricing\Helper\Data as PriceHelper; |
|
|
|
|
|
|
13
|
|
|
use Magento\Framework\View\Element\Template\Context; |
|
|
|
|
|
|
14
|
|
|
use Magento\Payment\Block\Form\Cc; |
|
|
|
|
|
|
15
|
|
|
use Magento\Payment\Helper\Data; |
|
|
|
|
|
|
16
|
|
|
use Magento\Payment\Model\Config; |
|
|
|
|
|
|
17
|
|
|
use Moip\Magento2\Gateway\Config\Config as ConfigBase; |
|
18
|
|
|
use Moip\Magento2\Gateway\Config\ConfigCc; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class FormCc - Form for payment by cc. |
|
22
|
|
|
*/ |
|
23
|
|
|
class FormCc extends Cc |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Cc template. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $_template = 'Moip_Magento2::form/cc.phtml'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var Quote |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $session; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var configCc |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $configCc; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var configProvider |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
protected $configProvider; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var paymentDataHelper |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
|
|
private $paymentDataHelper; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var configBase |
|
54
|
|
|
*/ |
|
55
|
|
|
private $configBase; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var priceHelper |
|
59
|
|
|
*/ |
|
60
|
|
|
private $priceHelper; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param Context $context |
|
64
|
|
|
* @param Config $paymentConfig |
|
65
|
|
|
* @param Quote $session |
|
66
|
|
|
* @param ConfigCc $configCc |
|
67
|
|
|
* @param configBase $configBase |
|
68
|
|
|
* @param Data $paymentDataHelper |
|
69
|
|
|
* @param array $data |
|
70
|
|
|
*/ |
|
71
|
|
|
public function __construct( |
|
72
|
|
|
Context $context, |
|
73
|
|
|
Config $paymentConfig, |
|
74
|
|
|
Quote $session, |
|
75
|
|
|
ConfigCc $configCc, |
|
76
|
|
|
ConfigBase $configBase, |
|
77
|
|
|
Data $paymentDataHelper, |
|
78
|
|
|
PriceHelper $priceHelper, |
|
79
|
|
|
array $data = [] |
|
80
|
|
|
) { |
|
81
|
|
|
parent::__construct($context, $paymentConfig, $data); |
|
82
|
|
|
$this->session = $session; |
|
83
|
|
|
$this->configBase = $configBase; |
|
84
|
|
|
$this->configCc = $configCc; |
|
85
|
|
|
$this->priceHelper = $priceHelper; |
|
86
|
|
|
$this->paymentDataHelper = $paymentDataHelper; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Title - Cc. |
|
91
|
|
|
* |
|
92
|
|
|
* @var string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getTitle() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->configCc->getTitle(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Select Installment - Cc. |
|
101
|
|
|
* |
|
102
|
|
|
* @var string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getSelectInstallments() |
|
105
|
|
|
{ |
|
106
|
|
|
$total = $this->session->getQuote()->getGrandTotal(); |
|
107
|
|
|
$installments = $this->getInstallments($total); |
|
108
|
|
|
|
|
109
|
|
|
return $installments; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Key Public - Cc. |
|
114
|
|
|
* |
|
115
|
|
|
* @var string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getKeyPublic() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->configBase->getMerchantGatewayKeyPublic(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Installments - Cc. |
|
124
|
|
|
* |
|
125
|
|
|
* @var string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getInstallments($ammount) |
|
128
|
|
|
{ |
|
129
|
|
|
$typeInstallment = $this->configCc->getTypeInstallment(); |
|
130
|
|
|
$limitByInstallment = $this->configCc->getMaxInstallment(); |
|
131
|
|
|
$limitInstallmentValue = $this->configCc->getMinInstallment(); |
|
132
|
|
|
$interestByInstallment = $this->configCc->getInfoInterest(); |
|
133
|
|
|
|
|
134
|
|
|
foreach ($interestByInstallment as $key => $_interest) { |
|
135
|
|
|
if ($key > 1 && $key <= $limitByInstallment) { |
|
136
|
|
|
$plotValue = $this->getInterestCompound($ammount, $_interest, $key); |
|
137
|
|
|
|
|
138
|
|
|
if ($typeInstallment === 'simple') { |
|
139
|
|
|
$plotValue = $this->getInterestSimple($ammount, $_interest, $key); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
if ($plotValue < $limitInstallmentValue) { |
|
143
|
|
|
break; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$plotValue = number_format((float) $plotValue, 2, '.', ''); |
|
147
|
|
|
$installmentPrice = $this->priceHelper->currency($plotValue, true, false); |
|
148
|
|
|
$plotlist[$key] = $key.__('x of ').$installmentPrice; |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return $plotlist; |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Interest Simple - Cc. |
|
157
|
|
|
* |
|
158
|
|
|
* @var float |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getInterestSimple($total, $interest, $portion) |
|
161
|
|
|
{ |
|
162
|
|
|
if ($interest) { |
|
163
|
|
|
$taxa = $interest / 100; |
|
164
|
|
|
$valinterest = $total * $taxa; |
|
165
|
|
|
|
|
166
|
|
|
return ($total + $valinterest) / $portion; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
return 0; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Interest Compound - Cc. |
|
174
|
|
|
* |
|
175
|
|
|
* @var float |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getInterestCompound($total, $interest, $portion) |
|
178
|
|
|
{ |
|
179
|
|
|
if ($interest) { |
|
180
|
|
|
$taxa = $interest / 100; |
|
181
|
|
|
|
|
182
|
|
|
return (($total * $taxa) * 1) / (1 - (pow(1 / (1 + $taxa), $portion))); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
return 0; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Use birth date capture - Cc. |
|
190
|
|
|
* |
|
191
|
|
|
* @var bool |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getBirthDateCapture() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->configCc->getUseBirthDateCapture(); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Use tax document capture - Cc. |
|
200
|
|
|
* |
|
201
|
|
|
* @var bool |
|
202
|
|
|
*/ |
|
203
|
|
|
public function getTaxDocumentCapture() |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->configCc->getUseTaxDocumentCapture(); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Use phone capture - Cc. |
|
210
|
|
|
* |
|
211
|
|
|
* @var bool |
|
212
|
|
|
*/ |
|
213
|
|
|
public function getPhoneCapture() |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->configCc->getUsePhoneCapture(); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
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