|
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\Vault; |
|
10
|
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
|
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCcVault; |
|
13
|
|
|
use Magento\Checkout\Model\ConfigProviderInterface; |
|
14
|
|
|
use Magento\Framework\Exception\InputException; |
|
15
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
|
16
|
|
|
use Magento\Framework\View\Asset\Source; |
|
17
|
|
|
use Magento\Payment\Model\CcConfig; |
|
18
|
|
|
use Magento\Quote\Api\Data\CartInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class ConfigProvider - Defines properties of the payment form. |
|
22
|
|
|
*/ |
|
23
|
|
|
class ConfigProvider implements ConfigProviderInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public const CODE = 'getnet_paymentmagento_cc_vault'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Config |
|
29
|
|
|
*/ |
|
30
|
|
|
private $configCcVault; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var CartInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $cart; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var array |
|
39
|
|
|
*/ |
|
40
|
|
|
private $icons = []; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var CcConfig |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $ccConfig; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var CcConfig |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $configCc; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var Source |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $assetSource; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* ConfigProvider constructor. |
|
59
|
|
|
* |
|
60
|
|
|
* @param CartInterface $cart |
|
61
|
|
|
* @param ConfigCc $configCc |
|
62
|
|
|
* @param ConfigCcVault $configCcVault |
|
63
|
|
|
* @param CcConfig $ccConfig |
|
64
|
|
|
* @param Source $assetSource |
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct( |
|
67
|
|
|
CartInterface $cart, |
|
68
|
|
|
ConfigCc $configCc, |
|
69
|
|
|
ConfigCcVault $configCcVault, |
|
70
|
|
|
CcConfig $ccConfig, |
|
71
|
|
|
Source $assetSource |
|
72
|
|
|
) { |
|
73
|
|
|
$this->cart = $cart; |
|
74
|
|
|
$this->configCc = $configCc; |
|
|
|
|
|
|
75
|
|
|
$this->assetSource = $assetSource; |
|
76
|
|
|
$this->ccConfig = $ccConfig; |
|
77
|
|
|
$this->configCcVault = $configCcVault; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Retrieve assoc array of checkout configuration. |
|
82
|
|
|
* |
|
83
|
|
|
* @throws InputException |
|
84
|
|
|
* @throws NoSuchEntityException |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getConfig() |
|
89
|
|
|
{ |
|
90
|
|
|
$storeId = $this->cart->getStoreId(); |
|
91
|
|
|
|
|
92
|
|
|
return [ |
|
93
|
|
|
'payment' => [ |
|
94
|
|
|
self::CODE => [ |
|
95
|
|
|
'useCvv' => $this->configCcVault->useCvv($storeId), |
|
96
|
|
|
'icons' => $this->getIcons(), |
|
97
|
|
|
], |
|
98
|
|
|
], |
|
99
|
|
|
]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get icons for available payment methods. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getIcons() |
|
108
|
|
|
{ |
|
109
|
|
|
if (!empty($this->icons)) { |
|
110
|
|
|
return $this->icons; |
|
111
|
|
|
} |
|
112
|
|
|
$storeId = $this->cart->getStoreId(); |
|
113
|
|
|
$ccTypes = $this->configCc->getCcAvailableTypes($storeId); |
|
|
|
|
|
|
114
|
|
|
$types = explode(',', $ccTypes); |
|
|
|
|
|
|
115
|
|
|
foreach ($types as $code => $label) { |
|
116
|
|
|
if (!array_key_exists($code, $this->icons)) { |
|
117
|
|
|
$asset = $this->ccConfig->createAsset('Getnet_PaymentMagento::images/cc/'.strtolower($label).'.svg'); |
|
118
|
|
|
$placeholder = $this->assetSource->findSource($asset); |
|
119
|
|
|
if ($placeholder) { |
|
120
|
|
|
list($width, $height) = getimagesizefromstring($asset->getSourceFile()); |
|
121
|
|
|
$this->icons[$label] = [ |
|
122
|
|
|
'url' => $asset->getUrl(), |
|
123
|
|
|
'width' => $width, |
|
124
|
|
|
'height' => $height, |
|
125
|
|
|
'title' => __($label), |
|
126
|
|
|
]; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $this->icons; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..