From b5eddd15fa8e2b8ec305f8c45065e38db80d469d Mon Sep 17 00:00:00 2001 From: Elisei Date: Wed, 2 Aug 2023 11:02:59 -0300 Subject: [PATCH] =?UTF-8?q?PagBank=20=F0=9F=98=8D=20Magento=20-=20Adciona?= =?UTF-8?q?=20recurso=20para=20controlar=20valor=20m=C3=ADnimo=20de=20parc?= =?UTF-8?q?elas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gateway/Config/ConfigCc.php | 36 +++++++++++++--------------- Model/Api/ConsultPSInstallments.php | 32 +++++++++++++++++++++---- etc/adminhtml/system/credit_card.xml | 10 ++++++-- etc/config.xml | 1 + i18n/en_US.csv | 2 ++ i18n/pt_BR.csv | 2 ++ 6 files changed, 57 insertions(+), 26 deletions(-) diff --git a/Gateway/Config/ConfigCc.php b/Gateway/Config/ConfigCc.php index a6f57b7..320e0cc 100644 --- a/Gateway/Config/ConfigCc.php +++ b/Gateway/Config/ConfigCc.php @@ -63,26 +63,6 @@ class ConfigCc extends PaymentConfig */ public const GET_PHONE = 'get_phone'; - /** - * @const string - */ - public const USE_FRAUD_MANAGER = 'fraud_manager'; - - /** - * @const string - */ - public const INSTALL_WITH_INTEREST = 'INSTALL_WITH_INTEREST'; - - /** - * @const string - */ - public const INSTALL_NO_INTEREST = 'INSTALL_NO_INTEREST'; - - /** - * @const string - */ - public const INSTALL_FULL = 'FULL'; - /** * @const string */ @@ -302,4 +282,20 @@ public function getInterestFree($storeId = null): int return $free; } + + /** + * Get Min Value Installments. + * + * @param int|null $storeId + * + * @return int + */ + public function getMinValuelInstallment($storeId = null): int + { + return (int) $this->scopeConfig->getValue( + 'payment/pagbank_paymentmagento_cc/min_value_installment', + ScopeInterface::SCOPE_STORE, + $storeId + ); + } } diff --git a/Model/Api/ConsultPSInstallments.php b/Model/Api/ConsultPSInstallments.php index fd33bb1..52bad75 100644 --- a/Model/Api/ConsultPSInstallments.php +++ b/Model/Api/ConsultPSInstallments.php @@ -74,9 +74,9 @@ public function __construct( /** * Get PagBank Installments. * - * @param int $storeId - * @param string $creditCardBin - * @param string $amount + * @param int|null $storeId + * @param string $creditCardBin + * @param string $amount * * @return array */ @@ -116,7 +116,9 @@ public function getPagBankInstallments($storeId, $creditCardBin, $amount) $list = $brand; } - $response = $list['installment_plans']; + $list = $this->getAvailableInstallments($list['installment_plans'], $storeId); + + $response = $list; } if (!$client->send()->getStatusCode()) { @@ -137,4 +139,26 @@ public function getPagBankInstallments($storeId, $creditCardBin, $amount) return $response; } + + /** + * Get Available Installments. + * + * @param array $list + * @param int|null $storeId + * @return array + */ + public function getAvailableInstallments($list, $storeId) + { + $minInstallment = $this->configCc->getMinValuelInstallment($storeId) * 100; + + foreach ($list as $key => $allInstallments) { + if ($key >= 1) { + if ($allInstallments['installment_value'] <= $minInstallment) { + unset($list[$key]); + } + } + } + + return $list; + } } diff --git a/etc/adminhtml/system/credit_card.xml b/etc/adminhtml/system/credit_card.xml index ac5fe73..4d751ff 100644 --- a/etc/adminhtml/system/credit_card.xml +++ b/etc/adminhtml/system/credit_card.xml @@ -82,20 +82,26 @@ - + PagBank\PaymentMagento\Model\Adminhtml\Source\Installments Maximum number of installments accepted required-entry validate-number payment/pagbank_paymentmagento_cc/max_installment - + PagBank\PaymentMagento\Model\Adminhtml\Source\Installments Number of installments you want to accept without applying interest required-entry validate-number payment/pagbank_paymentmagento_cc/interest_free + + + It is the minimum value that the installment can have + required-entry validate-number validate-number-range validate-date-range number-range-5-9999 + payment/pagbank_paymentmagento_cc/min_value_installment + \ No newline at end of file diff --git a/etc/config.xml b/etc/config.xml index 35efd05..6654a7b 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -81,6 +81,7 @@ HC,ELO,AE,VI,MC,DN,AU 18 1 + 5.00 0 0 1 diff --git a/i18n/en_US.csv b/i18n/en_US.csv index ca1cc04..aabdf96 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -166,6 +166,8 @@ Title,Title "Maximum number of installments accepted","Maximum number of installments accepted" "Number of interest-free installments","Number of interest-free installments" "Number of installments you want to accept without applying interest","Number of installments you want to accept without applying interest" +"The minimum installment price","The minimum installment price" +"It is the minimum value that the installment can have,"It is the minimum value that the installment can have" Developers,Developers "Meet our Wiki.","Meet our Wiki." Debug,Debug diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 1fd6ded..6271517 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -166,6 +166,8 @@ Title,Título "Maximum number of installments accepted","Número máximo de parcelas aceitas" "Number of interest-free installments","Número de parcelas sem juros" "Number of installments you want to accept without applying interest","Número de parcelas que pretende aceitar sem aplicar juros" +"The minimum installment price","O preço mínimo da parcela" +"It is the minimum value that the installment can have","É o valor mínimo que a parcela pode ter" Developers,Desenvolvedores "Meet our Wiki.","Conheça a nossa Wiki." Debug,Debug