From 7febef48f20c49f3c4b4a4f48969b46f95a212bc Mon Sep 17 00:00:00 2001 From: Mateus Picoloto Date: Mon, 28 Aug 2023 16:22:28 -0300 Subject: [PATCH] refactor: admin creditCard block and template --- Block/Form/CreditCard.php | 78 ++++++ etc/di.xml | 2 +- i18n/en_US.csv | 7 + i18n/pt_BR.csv | 7 + .../layout/sales_order_create_index.xml | 1 + view/adminhtml/requirejs-config.js | 3 +- .../adminhtml/templates/form/creditcard.phtml | 232 ++++++++---------- .../web/css/pagarme_order_create.css | 15 ++ .../web/js/core/models/creditCardModel.js | 2 +- view/adminhtml/web/js/view/form/creditCard.js | 22 ++ 10 files changed, 237 insertions(+), 132 deletions(-) create mode 100644 Block/Form/CreditCard.php create mode 100644 view/adminhtml/web/css/pagarme_order_create.css create mode 100644 view/adminhtml/web/js/view/form/creditCard.js diff --git a/Block/Form/CreditCard.php b/Block/Form/CreditCard.php new file mode 100644 index 00000000..59fbf4aa --- /dev/null +++ b/Block/Form/CreditCard.php @@ -0,0 +1,78 @@ +checkoutHelper = $checkoutHelper; + } + + public function getMethodCode() + { + return $this->escapeHtml(parent::getMethodCode()); + } + + /** + * @return string|null + */ + public function getPublicKey() + { + return $this->checkoutHelper->getPublicKey(); + } + + /** + * @param Quote $quote + * @return string + */ + public function getGrandTotal($quote) + { + return $this->checkoutHelper->formatGrandTotal($quote->getBaseGrandTotal()); + } + + /** + * @return string[] + */ + public function getMonths() + { + return $this->checkoutHelper->getMonths(); + } + + /** + * @return string[] + */ + public function getYears() + { + return $this->checkoutHelper->getYears(); + } + + /** + * @return array + */ + public function getAvailableBrands() + { + return $this->checkoutHelper->getBrandsAvailables( + $this->escapeHtml($this->getMethodCode()) + ); + } + + public function getInstallmentsUrl() + { + return $this->checkoutHelper->getInstallmentsUrl($this->getBaseUrl()); + } +} diff --git a/etc/di.xml b/etc/di.xml index 6a70e44c..7ca5cd7e 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -487,7 +487,7 @@ Pagarme\Pagarme\Model\Ui\CreditCard\ConfigProvider::CODE PagarmeCreditCardValueHandlerPool PagarmeCreditCardCommandPool - Magento\Payment\Block\Form + Pagarme\Pagarme\Block\Form\CreditCard Pagarme\Pagarme\Block\Payment\Info\CreditCard diff --git a/i18n/en_US.csv b/i18n/en_US.csv index bc41059f..e1a07c3a 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -310,3 +310,10 @@ "View Billet","View Billet" "Error updating cycles options for product with id %s. Error message: %s","Error updating cycles options for product with id %s. Error message: %s" "Subscription product with id %s not founded","Subscription product with id %s not founded" +"Brands","Brands" +"Select a brand","Select a brand" +"Please, select a brand","Please, select a brand" +"Please, enter valid Credit Card Number","Please, enter valid Credit Card Number" +"Please, enter valid Name on Card","Please, enter valid Name on Card" +"Please, enter valid Expiration Date","Please, enter valid Expiration Date" +"The cvv field must be a minimum length of 3 and a maximum length of 4.","The cvv field must be a minimum length of 3 and a maximum length of 4." diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 83467a42..ff0d0ce0 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -489,3 +489,10 @@ "View Billet","Visualizar Boleto" "Error updating cycles options for product with id %s. Error message: %s","Erro ao atualizar as opções de ciclos para o produto com o id %s. Mensagem de erro: %s" "Subscription product with id %s not founded","Produto de assinatura com id %s não encontrado" +"Brands","Bandeiras" +"Select a brand","Selecione uma bandeira" +"Please, select a brand","Por favor, selecione uma bandeira" +"Please, enter valid Credit Card Number","Por favor, digite um Número de Cartão de Crédito válido" +"Please, enter valid Name on Card","Por favor, digite um Nome no Cartão válido" +"Please, enter valid Expiration Date","Por favor, digite um Data de Validade válida" +"The cvv field must be a minimum length of 3 and a maximum length of 4.","O campo de cvv deve ter um tamanho mínimo de 3 e um tamanho máximo de 4." diff --git a/view/adminhtml/layout/sales_order_create_index.xml b/view/adminhtml/layout/sales_order_create_index.xml index 9bfc2734..123f63e3 100644 --- a/view/adminhtml/layout/sales_order_create_index.xml +++ b/view/adminhtml/layout/sales_order_create_index.xml @@ -8,6 +8,7 @@ + + + diff --git a/view/adminhtml/web/css/pagarme_order_create.css b/view/adminhtml/web/css/pagarme_order_create.css new file mode 100644 index 00000000..b2b5370d --- /dev/null +++ b/view/adminhtml/web/css/pagarme_order_create.css @@ -0,0 +1,15 @@ +.fieldset-credit-card-pagarme { + margin-top:15px; +} + +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_type, +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_number, +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_owner, +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_installments { + width: 335px; +} + +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_exp_month, +.fieldset-credit-card-pagarme .admin__field .admin__field-control .cc_exp_year { + width: auto; +} diff --git a/view/adminhtml/web/js/core/models/creditCardModel.js b/view/adminhtml/web/js/core/models/creditCardModel.js index 704edc3f..8f9acf0c 100644 --- a/view/adminhtml/web/js/core/models/creditCardModel.js +++ b/view/adminhtml/web/js/core/models/creditCardModel.js @@ -56,7 +56,7 @@ define([ CreditCardModel.addListeners = function(config) { Listeners.addCreditCardNumberListener(this.formObject); Listeners.addCreditCardHolderNameListener(this.formObject); - Listeners.addCreditCardBrandListener(this.formObject, config.installmenUrl); + Listeners.addCreditCardBrandListener(this.formObject, config.installmentUrl); Listeners.addCreditCardInstallmentsListener(this.formObject); }; diff --git a/view/adminhtml/web/js/view/form/creditCard.js b/view/adminhtml/web/js/view/form/creditCard.js new file mode 100644 index 00000000..d5f898a6 --- /dev/null +++ b/view/adminhtml/web/js/view/form/creditCard.js @@ -0,0 +1,22 @@ +define([ + "jquery", + 'Pagarme_Pagarme/js/core/models/creditCardModel', + "jquery/ui" +], function ( + $, + CreditCardModel +) { + 'use strict'; + return (initializationConfig) => { + $(document).ready(function(){ + const config = { + isMultibuyerEnabled: false, + order : window.order, + payment : window.payment, + installmentUrl: initializationConfig.installmentUrl + }; + + CreditCardModel.init(initializationConfig.code, config); + }); + }; +});