|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Getnet. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bruno Elisei <[email protected]> |
|
6
|
|
|
* See LICENSE for license details. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Getnet\PaymentMagento\Block\Sales\Form; |
|
10
|
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
|
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigWallet; |
|
13
|
|
|
use Magento\Backend\Model\Session\Quote; |
|
14
|
|
|
use Magento\Framework\Pricing\Helper\Data as PriceHelper; |
|
15
|
|
|
use Magento\Framework\View\Element\Template\Context; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Wallet - Form for payment by Wallet. |
|
19
|
|
|
*/ |
|
20
|
|
|
class Wallet extends \Magento\Payment\Block\Form |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Wallet template. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $_template = 'Getnet_PaymentMagento::form/wallet.phtml'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Quote |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $session; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ConfigCc |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $configCc; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ConfigWallet |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $configWallet; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var PriceHelper |
|
46
|
|
|
*/ |
|
47
|
|
|
private $priceHelper; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param Context $context |
|
51
|
|
|
* @param Quote $session |
|
52
|
|
|
* @param ConfigCc $configCc |
|
53
|
|
|
* @param ConfigWallet $configWallet |
|
54
|
|
|
* @param PriceHelper $priceHelper |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct( |
|
57
|
|
|
Context $context, |
|
58
|
|
|
Quote $session, |
|
59
|
|
|
ConfigCc $configCc, |
|
60
|
|
|
ConfigWallet $configWallet, |
|
61
|
|
|
PriceHelper $priceHelper |
|
62
|
|
|
) { |
|
63
|
|
|
parent::__construct($context); |
|
64
|
|
|
$this->session = $session; |
|
65
|
|
|
$this->configCc = $configCc; |
|
66
|
|
|
$this->configWallet = $configWallet; |
|
67
|
|
|
$this->priceHelper = $priceHelper; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Title - Wallet. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getTitle() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->configWallet->getTitle(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Instruction - Wallet. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getInstruction() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->configWallet->getInstructionCheckout(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Select Installment - Cc. |
|
92
|
|
|
* |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getSelectInstallments(): array |
|
96
|
|
|
{ |
|
97
|
|
|
$total = $this->session->getQuote()->getGrandTotal(); |
|
98
|
|
|
$installments = $this->getInstallments($total); |
|
99
|
|
|
|
|
100
|
|
|
return $installments; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Installments - Cc. |
|
105
|
|
|
* |
|
106
|
|
|
* @param float $amount |
|
107
|
|
|
* |
|
108
|
|
|
* @return array |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getInstallments($amount): array |
|
111
|
|
|
{ |
|
112
|
|
|
$interestByInst = $this->configCc->getInfoInterest(); |
|
113
|
|
|
$plotlist = []; |
|
114
|
|
|
foreach ($interestByInst as $key => $interest) { |
|
115
|
|
|
if ($key > 0) { |
|
116
|
|
|
$plotValue = $this->getInterestSimple($amount, $interest, $key); |
|
117
|
|
|
$plotValue = number_format((float) $plotValue, 2, '.', ''); |
|
118
|
|
|
$installmentPrice = $this->priceHelper->currency($plotValue, true, false); |
|
|
|
|
|
|
119
|
|
|
$plotlist[$key] = $key.__('x of ').$installmentPrice; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $plotlist; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Interest Simple - Cc. |
|
128
|
|
|
* |
|
129
|
|
|
* @param float $total |
|
130
|
|
|
* @param float $interest |
|
131
|
|
|
* @param int $portion |
|
132
|
|
|
* |
|
133
|
|
|
* @return float |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getInterestSimple($total, $interest, $portion): float |
|
136
|
|
|
{ |
|
137
|
|
|
if ($interest) { |
|
138
|
|
|
$taxa = $interest / 100; |
|
139
|
|
|
$valinterest = $total * $taxa; |
|
140
|
|
|
|
|
141
|
|
|
return ($total + $valinterest) / $portion; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $total / $portion; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|