/
Config.php
237 lines (214 loc) · 5.99 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Config;
/**
* Class Config
*/
class Config extends \Magento\Payment\Gateway\Config\Config
{
const KEY_ENVIRONMENT = 'environment';
const KEY_ACTIVE = 'active';
const KEY_MERCHANT_ID = 'merchant_id';
const KEY_MERCHANT_ACCOUNT_ID = 'merchant_account_id';
const KEY_PUBLIC_KEY = 'public_key';
const KEY_PRIVATE_KEY = 'private_key';
const KEY_COUNTRY_CREDIT_CARD = 'countrycreditcard';
const KEY_CC_TYPES = 'cctypes';
const KEY_CC_TYPES_BRAINTREE_MAPPER = 'cctypes_braintree_mapper';
const KEY_SDK_URL = 'sdk_url';
const KEY_USE_CVV = 'useccv';
const KEY_VERIFY_3DSECURE = 'verify_3dsecure';
const KEY_THRESHOLD_AMOUNT = 'threshold_amount';
const KEY_VERIFY_ALLOW_SPECIFIC = 'verify_all_countries';
const KEY_VERIFY_SPECIFIC = 'verify_specific_countries';
const VALUE_3DSECURE_ALL = 0;
const CODE_3DSECURE = 'three_d_secure';
const KEY_KOUNT_MERCHANT_ID = 'kount_id';
const FRAUD_PROTECTION = 'fraudprotection';
/**
* Get list of available dynamic descriptors keys
* @var array
*/
private static $dynamicDescriptorKeys = [
'name', 'phone', 'url'
];
/**
* Return the country specific card type config
*
* @param int|null $storeId
* @return array
*/
public function getCountrySpecificCardTypeConfig($storeId = null)
{
$countriesCardTypes = unserialize($this->getValue(self::KEY_COUNTRY_CREDIT_CARD, $storeId));
return is_array($countriesCardTypes) ? $countriesCardTypes : [];
}
/**
* Retrieve available credit card types
*
* @param int|null $storeId
* @return array
*/
public function getAvailableCardTypes($storeId = null)
{
$ccTypes = $this->getValue(self::KEY_CC_TYPES, $storeId);
return !empty($ccTypes) ? explode(',', $ccTypes) : [];
}
/**
* Retrieve mapper between Magento and Braintree card types
*
* @return array
*/
public function getCcTypesMapper()
{
$result = json_decode(
$this->getValue(self::KEY_CC_TYPES_BRAINTREE_MAPPER),
true
);
return is_array($result) ? $result : [];
}
/**
* Gets list of card types available for country.
*
* @param string $country
* @param int|null $storeId
* @return array
*/
public function getCountryAvailableCardTypes($country, $storeId = null)
{
$types = $this->getCountrySpecificCardTypeConfig($storeId);
return (!empty($types[$country])) ? $types[$country] : [];
}
/**
* Checks if cvv field is enabled.
*
* @param int|null $storeId
* @return bool
*/
public function isCvvEnabled($storeId = null)
{
return (bool) $this->getValue(self::KEY_USE_CVV, $storeId);
}
/**
* Checks if 3d secure verification enabled.
*
* @param int|null $storeId
* @return bool
*/
public function isVerify3DSecure($storeId = null)
{
return (bool) $this->getValue(self::KEY_VERIFY_3DSECURE, $storeId);
}
/**
* Gets threshold amount for 3d secure.
*
* @param int|null $storeId
* @return float
*/
public function getThresholdAmount($storeId = null)
{
return (double) $this->getValue(self::KEY_THRESHOLD_AMOUNT, $storeId);
}
/**
* Gets list of specific countries for 3d secure.
*
* @param int|null $storeId
* @return array
*/
public function get3DSecureSpecificCountries($storeId = null)
{
if ((int) $this->getValue(self::KEY_VERIFY_ALLOW_SPECIFIC, $storeId) == self::VALUE_3DSECURE_ALL) {
return [];
}
return explode(',', $this->getValue(self::KEY_VERIFY_SPECIFIC, $storeId));
}
/**
* Gets value of configured environment.
* Possible values: production or sandbox.
*
* @param int|null $storeId
* @return string
*/
public function getEnvironment($storeId = null)
{
return $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
}
/**
* Gets Kount merchant ID.
*
* @param int|null $storeId
* @return string
* @internal param null $storeId
*/
public function getKountMerchantId($storeId = null)
{
return $this->getValue(Config::KEY_KOUNT_MERCHANT_ID, $storeId);
}
/**
* Gets merchant ID.
*
* @param int|null $storeId
* @return string
*/
public function getMerchantId($storeId = null)
{
return $this->getValue(Config::KEY_MERCHANT_ID, $storeId);
}
/**
* Gets Merchant account ID.
*
* @param int|null $storeId
* @return string
*/
public function getMerchantAccountId($storeId = null)
{
return $this->getValue(self::KEY_MERCHANT_ACCOUNT_ID, $storeId);
}
/**
* @return string
*/
public function getSdkUrl()
{
return $this->getValue(Config::KEY_SDK_URL);
}
/**
* Checks if fraud protection is enabled.
*
* @param int|null $storeId
* @return bool
*/
public function hasFraudProtection($storeId = null)
{
return (bool) $this->getValue(Config::FRAUD_PROTECTION, $storeId);
}
/**
* Gets Payment configuration status.
*
* @param int|null $storeId
* @return bool
*/
public function isActive($storeId = null)
{
return (bool) $this->getValue(self::KEY_ACTIVE, $storeId);
}
/**
* Gets list of configured dynamic descriptors.
*
* @param int|null $storeId
* @return array
*/
public function getDynamicDescriptors($storeId = null)
{
$values = [];
foreach (self::$dynamicDescriptorKeys as $key) {
$value = $this->getValue('descriptor_' . $key, $storeId);
if (!empty($value)) {
$values[$key] = $value;
}
}
return $values;
}
}