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\Model\Ui; |
10
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\Config as ConfigBase; |
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
13
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigTwoCc; |
14
|
|
|
use Magento\Checkout\Model\ConfigProviderInterface; |
15
|
|
|
use Magento\Framework\Session\SessionManager; |
16
|
|
|
use Magento\Framework\View\Asset\Source; |
17
|
|
|
use Magento\Payment\Model\CcConfig; |
18
|
|
|
use Magento\Quote\Api\Data\CartInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class ConfigProviderTwoCc - Defines properties of the payment form. |
22
|
|
|
* |
23
|
|
|
* @SuppressWarnings(PHPCPD) |
24
|
|
|
*/ |
25
|
|
|
class ConfigProviderTwoCc implements ConfigProviderInterface |
26
|
|
|
{ |
27
|
|
|
/* |
28
|
|
|
* @const string |
29
|
|
|
*/ |
30
|
|
|
public const CODE = 'getnet_paymentmagento_two_cc'; |
31
|
|
|
|
32
|
|
|
/* |
33
|
|
|
* @const string |
34
|
|
|
*/ |
35
|
|
|
public const VAULT_CODE = 'getnet_paymentmagento_cc_vault'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ConfigBase |
39
|
|
|
*/ |
40
|
|
|
protected $configBase; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ConfigCc |
44
|
|
|
*/ |
45
|
|
|
protected $configCc; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var configTwoCc |
49
|
|
|
*/ |
50
|
|
|
protected $configTwoCc; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var CartInterface |
54
|
|
|
*/ |
55
|
|
|
protected $cart; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected $icons = []; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var CcConfig |
64
|
|
|
*/ |
65
|
|
|
protected $ccConfig; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var Source |
69
|
|
|
*/ |
70
|
|
|
protected $assetSource; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var SessionManager |
74
|
|
|
*/ |
75
|
|
|
protected $session; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param ConfigBase $configBase |
79
|
|
|
* @param ConfigCc $configCc |
80
|
|
|
* @param ConfigTwoCc $configTwoCc |
81
|
|
|
* @param CartInterface $cart |
82
|
|
|
* @param CcConfig $ccConfig |
83
|
|
|
* @param Source $assetSource |
84
|
|
|
* @param SessionManager $session |
85
|
|
|
*/ |
86
|
|
|
public function __construct( |
87
|
|
|
ConfigBase $configBase, |
88
|
|
|
ConfigCc $configCc, |
89
|
|
|
ConfigTwoCc $configTwoCc, |
90
|
|
|
CartInterface $cart, |
91
|
|
|
CcConfig $ccConfig, |
92
|
|
|
Source $assetSource, |
93
|
|
|
SessionManager $session |
94
|
|
|
) { |
95
|
|
|
$this->configBase = $configBase; |
96
|
|
|
$this->configCc = $configCc; |
97
|
|
|
$this->configTwoCc = $configTwoCc; |
98
|
|
|
$this->cart = $cart; |
99
|
|
|
$this->ccConfig = $ccConfig; |
100
|
|
|
$this->assetSource = $assetSource; |
101
|
|
|
$this->session = $session; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Retrieve assoc array of checkout configuration. |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
public function getConfig() |
110
|
|
|
{ |
111
|
|
|
$storeId = $this->cart->getStoreId(); |
112
|
|
|
|
113
|
|
|
return [ |
114
|
|
|
'payment' => [ |
115
|
|
|
ConfigTwoCc::METHOD => [ |
116
|
|
|
'isActive' => $this->configTwoCc->isActive($storeId), |
117
|
|
|
'title' => $this->configTwoCc->getTitle($storeId), |
118
|
|
|
'useCvv' => $this->configCc->isCvvEnabled($storeId), |
119
|
|
|
'ccTypesMapper' => $this->configCc->getCcTypesMapper($storeId), |
120
|
|
|
'logo' => $this->getLogo(), |
121
|
|
|
'icons' => $this->getIcons(), |
122
|
|
|
'tax_document_capture' => $this->configCc->hasUseTaxDocumentCapture($storeId), |
123
|
|
|
'phone_capture' => $this->configCc->hasUsePhoneCapture($storeId), |
124
|
|
|
'fraud_manager' => $this->configCc->hasUseFraudManager($storeId), |
125
|
|
|
'info_interest' => $this->configCc->getInfoInterest($storeId), |
126
|
|
|
'min_installment' => $this->configCc->getMinInstallment($storeId), |
127
|
|
|
'max_installment' => $this->configCc->getMaxInstallment($storeId), |
128
|
|
|
'fingerPrintSessionId' => $this->session->getSessionId(), |
129
|
|
|
'fingerPrintCode' => $this->configBase->getMerchantGatewayOnlineMetrixCode($storeId), |
130
|
|
|
], |
131
|
|
|
], |
132
|
|
|
]; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get icons for available payment methods. |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function getIcons() |
141
|
|
|
{ |
142
|
|
|
if (!empty($this->icons)) { |
143
|
|
|
return $this->icons; |
144
|
|
|
} |
145
|
|
|
$storeId = $this->cart->getStoreId(); |
146
|
|
|
$ccTypes = $this->configCc->getCcAvailableTypes($storeId); |
147
|
|
|
$types = explode(',', $ccTypes); |
148
|
|
|
foreach ($types as $code => $label) { |
149
|
|
|
if (!array_key_exists($code, $this->icons)) { |
150
|
|
|
$asset = $this->ccConfig->createAsset('Getnet_PaymentMagento::images/cc/'.strtolower($label).'.svg'); |
151
|
|
|
$placeholder = $this->assetSource->findSource($asset); |
152
|
|
|
if ($placeholder) { |
153
|
|
|
list($width, $height) = getimagesizefromstring($asset->getSourceFile()); |
154
|
|
|
$this->icons[$label] = [ |
155
|
|
|
'url' => $asset->getUrl(), |
156
|
|
|
'width' => $width, |
157
|
|
|
'height' => $height, |
158
|
|
|
'title' => __($label), |
159
|
|
|
]; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $this->icons; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Get icons for available payment methods. |
169
|
|
|
* |
170
|
|
|
* @return array |
171
|
|
|
*/ |
172
|
|
|
public function getLogo() |
173
|
|
|
{ |
174
|
|
|
$logo = []; |
175
|
|
|
$asset = $this->ccConfig->createAsset('Getnet_PaymentMagento::images/cc/logo.svg'); |
176
|
|
|
$placeholder = $this->assetSource->findSource($asset); |
177
|
|
|
if ($placeholder) { |
178
|
|
|
list($width, $height) = getimagesizefromstring($asset->getSourceFile()); |
179
|
|
|
$logo = [ |
180
|
|
|
'url' => $asset->getUrl(), |
181
|
|
|
'width' => $width, |
182
|
|
|
'height' => $height, |
183
|
|
|
'title' => __('Getnet'), |
184
|
|
|
]; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return $logo; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|