diff --git a/Gateway/Transaction/CreditCard/Config/Config.php b/Gateway/Transaction/CreditCard/Config/Config.php index a21c02bf..cd9a9982 100755 --- a/Gateway/Transaction/CreditCard/Config/Config.php +++ b/Gateway/Transaction/CreditCard/Config/Config.php @@ -61,7 +61,15 @@ public function getOrderWithTdsRefused() { return (bool) $this->getConfig(static::PATH_ORDER_WITH_TDS_REFUSED); } - + + /** + * @return string + */ + public function getTdsMinAmount() + { + return $this->getConfig(static::PATH_TDS_MIN_AMOUNT); + } + /** * {@inheritdoc} */ diff --git a/Gateway/Transaction/CreditCard/Config/ConfigInterface.php b/Gateway/Transaction/CreditCard/Config/ConfigInterface.php index c7763ecc..9721a136 100755 --- a/Gateway/Transaction/CreditCard/Config/ConfigInterface.php +++ b/Gateway/Transaction/CreditCard/Config/ConfigInterface.php @@ -18,6 +18,7 @@ interface ConfigInterface const PATH_ENABLED_SAVED_CARDS = 'payment/pagarme_creditcard/enabled_saved_cards'; const PATH_TDS_ACTIVE = 'payment/pagarme_creditcard/tds_active'; const PATH_ORDER_WITH_TDS_REFUSED = 'payment/pagarme_creditcard/order_with_tds_refused'; + const PATH_TDS_MIN_AMOUNT = 'payment/pagarme_creditcard/tds_min_amount'; const PATH_PAYMENT_ACTION = 'payment/pagarme_creditcard/payment_action'; const PATH_ANTIFRAUD_ACTIVE = 'payment/pagarme_creditcard/antifraud_active'; const PATH_ANTIFRAUD_MIN_AMOUNT = 'payment/pagarme_creditcard/antifraud_min_amount'; diff --git a/Model/Ui/CreditCard/ConfigProvider.php b/Model/Ui/CreditCard/ConfigProvider.php index f8e458d5..5ad7c6b1 100755 --- a/Model/Ui/CreditCard/ConfigProvider.php +++ b/Model/Ui/CreditCard/ConfigProvider.php @@ -98,11 +98,10 @@ public function getConfig() 'active' => $this->getCreditCardConfig()->getActive(), 'title' => $this->getCreditCardConfig()->getTitle(), 'is_saved_card' => $is_saved_card, - 'enabled_saved_cards' => $this->getCreditCardConfig() - ->getEnabledSavedCards(), + 'enabled_saved_cards' => $this->getCreditCardConfig()->getEnabledSavedCards(), 'tds_active' => $this->getCreditCardConfig()->getTdsActive(), - 'order_with_tds_refused' => $this->getCreditCardConfig()->getOrderWithTdsRefused(), + 'tds_min_amount' => $this->getCreditCardConfig()->getTdsMinAmount(), 'cards' => $cards, 'selected_card' => $selectedCard, 'size_credit_card' => '18', diff --git a/etc/adminhtml/system/transaction/creditcard/tds.xml b/etc/adminhtml/system/transaction/creditcard/tds.xml index 6a72f422..ee50a935 100644 --- a/etc/adminhtml/system/transaction/creditcard/tds.xml +++ b/etc/adminhtml/system/transaction/creditcard/tds.xml @@ -9,7 +9,7 @@ Pagarme\Pagarme\Block\Adminhtml\Form\Fieldset\CreditCardGatewayFieldset - + Magento\Config\Model\Config\Source\Yesno payment/pagarme_creditcard/tds_active @@ -24,6 +24,16 @@ 1 + + Pagarme\Pagarme\Model\Validation\GenericValidation + + + payment/pagarme_creditcard/tds_min_amount + validate-currency-dollar + + 1 + + 1 diff --git a/etc/config.xml b/etc/config.xml index d807ce9b..7e7867cc 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -114,6 +114,7 @@ 1 0 1 + 0.00 diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 2af308fa..49335d9c 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -534,6 +534,7 @@ "Proceed with payment without confirmed 3DS authentication","Prosseguir com pagamento sem autenticação 3DS confirmada" "If the issuing bank/brand does not approve 3DS authentication, we will continue with the transaction in the common flow (without 3DS)","Caso o banco emissor/bandeira não aprove a autenticação 3DS, seguiremos com a transação no fluxo comum (sem 3DS)" "If the Issuing Bank rejects 3DS authentication, you may receive a fraud chargeback","Caso o Banco Emissor rejeite a autenticação 3DS, você poderá receber chargerback por fraude" +"Minimum value for 3DS authentication","Valor mínimo para autenticação 3DS" "Order declined, do not try again.","Pedido recusado, não tente novamente." "Can't create payment. Please review the information and try again.","Não foi possível realizar o pagamento. Por favor revise os dados e tente novamente." "Order # %1 : %2","Pedido # %1 : %2" diff --git a/view/frontend/web/js/core/models/CreditCardModel.js b/view/frontend/web/js/core/models/CreditCardModel.js index 8253ea43..593e757c 100644 --- a/view/frontend/web/js/core/models/CreditCardModel.js +++ b/view/frontend/web/js/core/models/CreditCardModel.js @@ -3,7 +3,8 @@ define([ 'Pagarme_Pagarme/js/core/validators/MultibuyerValidator', 'Pagarme_Pagarme/js/core/checkout/CreditCardToken', 'Pagarme_Pagarme/js/core/checkout/Tds', -], (CreditCardValidator, MultibuyerValidator, CreditCardToken, Tds) => { + 'Magento_Checkout/js/model/quote', +], (CreditCardValidator, MultibuyerValidator, CreditCardToken, Tds, quote) => { return class CreditCardModel { constructor(formObject, publicKey) { this.formObject = formObject; @@ -24,9 +25,7 @@ define([ return; } - const configCard = window.checkoutConfig.payment.pagarme_creditcard; - - if(configCard['tds_active'] === true && this.brandIsVisaOrMaster()) { + if(this.canTdsRun()) { const tds = new Tds(this.formObject) tds.addTdsAttributeData(); jQuery('body').trigger('processStart'); @@ -83,9 +82,16 @@ define([ .done(success) .fail(error); } + canTdsRun() { + const configCard = window.checkoutConfig.payment.pagarme_creditcard; + + return configCard['tds_active'] === true + && quote.totals().grand_total * 100 >= configCard['tds_min_amount'] * 100 + && this.brandIsVisaOrMaster() + } brandIsVisaOrMaster() { - return this.formObject.creditCardBrand.val() === "visa" || - this.formObject.creditCardBrand.val() === "mastercard" + return this.formObject.creditCardBrand.val() === "visa" + || this.formObject.creditCardBrand.val() === "mastercard" } initTds(tdsToken) { const modelTds = new Tds(this.formObject) @@ -107,7 +113,7 @@ define([ if(data?.trans_status === '' || data?.trans_status === undefined){ return; } - + this.formObject.authentication = JSON.stringify(data); this.getCreditCardToken( function (data) {