1- <?php
2-
3- declare (strict_types=1 );
1+ <?php declare (strict_types=1 );
42
53namespace Afterpay \Afterpay \Model ;
64
5+ use Magento \Framework \App \Config \ScopeConfigInterface ;
6+ use Magento \Framework \App \Config \Storage \WriterInterface ;
7+ use Magento \Framework \App \ResourceConnection ;
8+ use Magento \Framework \Serialize \SerializerInterface ;
79use Magento \Store \Model \ScopeInterface ;
810
911class Config
@@ -21,27 +23,31 @@ class Config
2123 const XML_PATH_MERCHANT_KEY = 'payment/afterpay/merchant_key ' ;
2224 const XML_PATH_PAYMENT_FLOW = 'payment/afterpay/payment_flow ' ;
2325 const XML_PATH_MIN_LIMIT = 'payment/afterpay/min_order_total ' ;
24- const XML_PATH_MAX_LIMIT = 'payment/afterpay/max_order_total ' ;
25- const XML_PATH_CBT_CURRENCY_LIMITS = 'payment/afterpay/cbt_currency_limits ' ;
26- const XML_PATH_EXCLUDE_CATEGORIES = 'payment/afterpay/exclude_categories ' ;
27- const XML_PATH_ALLOW_SPECIFIC_COUNTRIES = 'payment/afterpay/allowspecific ' ;
28- const XML_PATH_SPECIFIC_COUNTRIES = 'payment/afterpay/specificcountry ' ;
29- const XML_PATH_ALLOWED_MERCHANT_COUNTRIES = 'payment/afterpay/allowed_merchant_countries ' ;
30- const XML_PATH_ALLOWED_MERCHANT_CURRENCIES = 'payment/afterpay/allowed_merchant_currencies ' ;
31- const XML_PATH_PAYPAL_MERCHANT_COUNTRY = 'paypal/general/merchant_country ' ;
32-
33- private \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ;
34- private \Magento \Framework \App \Config \Storage \WriterInterface $ writer ;
35- private \Magento \Framework \App \ResourceConnection $ resourceConnection ;
26+ const XML_PATH_MAX_LIMIT = 'payment/afterpay/max_order_total ' ;
27+ const XML_PATH_CBT_CURRENCY_LIMITS = 'payment/afterpay/cbt_currency_limits ' ;
28+ const XML_PATH_EXCLUDE_CATEGORIES = 'payment/afterpay/exclude_categories ' ;
29+ const XML_PATH_ALLOW_SPECIFIC_COUNTRIES = 'payment/afterpay/allowspecific ' ;
30+ const XML_PATH_SPECIFIC_COUNTRIES = 'payment/afterpay/specificcountry ' ;
31+ const XML_PATH_ALLOWED_MERCHANT_COUNTRIES = 'payment/afterpay/allowed_merchant_countries ' ;
32+ const XML_PATH_ALLOWED_MERCHANT_CURRENCIES = 'payment/afterpay/allowed_merchant_currencies ' ;
33+ const XML_PATH_PAYPAL_MERCHANT_COUNTRY = 'paypal/general/merchant_country ' ;
34+ const XML_PATH_ENABLE_REVERSAL = 'payment/afterpay/enable_reversal ' ;
35+
36+ private ScopeConfigInterface $ scopeConfig ;
37+ private WriterInterface $ writer ;
38+ private ResourceConnection $ resourceConnection ;
39+ private SerializerInterface $ serializer ;
3640
3741 public function __construct (
38- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
39- \Magento \Framework \App \Config \Storage \WriterInterface $ writer ,
40- \Magento \Framework \App \ResourceConnection $ resourceConnection
42+ ScopeConfigInterface $ scopeConfig ,
43+ WriterInterface $ writer ,
44+ ResourceConnection $ resourceConnection ,
45+ SerializerInterface $ serializer
4146 ) {
4247 $ this ->scopeConfig = $ scopeConfig ;
4348 $ this ->writer = $ writer ;
4449 $ this ->resourceConnection = $ resourceConnection ;
50+ $ this ->serializer = $ serializer ;
4551 }
4652
4753 public function getIsPaymentActive (?int $ scopeCode = null ): bool
@@ -172,7 +178,6 @@ public function getMinOrderTotal(?int $scopeCode = null): ?string
172178
173179 public function getCbtCurrencyLimits (?int $ scopeCode = null ): array
174180 {
175- $ data = [];
176181 $ value = $ this ->scopeConfig ->getValue (
177182 self ::XML_PATH_CBT_CURRENCY_LIMITS ,
178183 ScopeInterface::SCOPE_WEBSITE ,
@@ -183,15 +188,7 @@ public function getCbtCurrencyLimits(?int $scopeCode = null): array
183188 return [];
184189 }
185190
186- $ list = explode (', ' , $ value );
187- foreach ($ list as $ item ) {
188- $ currencyLimit = explode (': ' , $ item );
189- if (isset ($ currencyLimit [0 ]) && isset ($ currencyLimit [1 ])) {
190- $ data [$ currencyLimit [0 ]] = (float ) $ currencyLimit [1 ];
191- }
192- }
193-
194- return $ data ;
191+ return $ this ->serializer ->unserialize ($ value );
195192 }
196193
197194 public function getExcludeCategories (?int $ scopeCode = null ): array
@@ -205,6 +202,15 @@ public function getExcludeCategories(?int $scopeCode = null): array
205202 return $ excludeCategories ? explode (', ' , $ excludeCategories ) : [];
206203 }
207204
205+ public function getIsReversalEnabled (?int $ scopeCode = null ): bool
206+ {
207+ return $ this ->scopeConfig ->isSetFlag (
208+ self ::XML_PATH_ENABLE_REVERSAL ,
209+ ScopeInterface::SCOPE_WEBSITE ,
210+ $ scopeCode
211+ );
212+ }
213+
208214 public function setMaxOrderTotal (string $ value , int $ scopeId = 0 ): self
209215 {
210216 if ($ scopeId ) {
@@ -347,7 +353,7 @@ public function setSpecificCountries(string $value, int $scopeId = 0): self
347353
348354 public function getMerchantCountry (
349355 string $ scope = ScopeInterface::SCOPE_WEBSITES ,
350- ?int $ scopeCode = null
356+ ?int $ scopeCode = null
351357 ): ?string {
352358 if ($ countryCode = $ this ->scopeConfig ->getValue (
353359 self ::XML_PATH_PAYPAL_MERCHANT_COUNTRY ,
@@ -368,7 +374,7 @@ public function getMerchantCountry(
368374
369375 public function getMerchantCurrency (
370376 string $ scope = ScopeInterface::SCOPE_WEBSITES ,
371- ?int $ scopeCode = null
377+ ?int $ scopeCode = null
372378 ): ?string {
373379 return $ this ->scopeConfig ->getValue (
374380 \Magento \Directory \Model \Currency::XML_PATH_CURRENCY_BASE ,
@@ -401,7 +407,7 @@ public function websiteHasOwnConfig(int $websiteId): bool
401407 \Afterpay \Afterpay \Observer \Adminhtml \ConfigSaveAfter::AFTERPAY_CONFIGS ,
402408 \Afterpay \Afterpay \Observer \Adminhtml \ConfigSaveAfter::CONFIGS_PATHS_TO_TRACK
403409 );
404- $ selectQuery = $ connection ->select ()->from ($ coreConfigData , ['path ' ,'value ' ])
410+ $ selectQuery = $ connection ->select ()->from ($ coreConfigData , ['path ' , 'value ' ])
405411 ->where ("scope = ? " , \Magento \Store \Model \ScopeInterface::SCOPE_WEBSITES )
406412 ->where ("scope_id = ? " , $ websiteId )
407413 ->where ("path in (?) " , $ configsExistToCheck );
0 commit comments