From 1d7c1b924f73891d89867159ec3e59050951b713 Mon Sep 17 00:00:00 2001 From: RafaMelazzo Date: Fri, 8 Mar 2024 15:59:23 -0300 Subject: [PATCH 01/63] adding new fields to recipients --- Block/Adminhtml/Marketplace/Recipient.php | 39 +- Setup/InstallSchema.php | 470 ++++----- Setup/UpgradeSchema.php | 4 - etc/csp_whitelist.xml | 3 + etc/db_schema.xml | 19 +- etc/db_schema_whitelist.json | 17 +- i18n/pt_BR.csv | 33 +- .../layout/pagarme_pagarme_plans_create.xml | 1 - .../pagarme_pagarme_recipients_create.xml | 1 - ...arme_pagarme_recurrenceproducts_create.xml | 1 - .../pagarme_pagarme_subscriptions_details.xml | 1 - view/adminhtml/requirejs-config.js | 3 +- .../marketplace/recipients/create.phtml | 947 +++++++++++++++--- .../templates/recurrence/plans/create.phtml | 2 +- .../recurrence/subscriptions/create.phtml | 2 +- view/adminhtml/web/css/jquery-ui.min.css | 7 - view/adminhtml/web/css/pagarme_style.css | 54 +- view/adminhtml/web/js/jquery.mask.min.js | 19 + view/adminhtml/web/js/recipients.js | 697 ++++++++----- 19 files changed, 1630 insertions(+), 690 deletions(-) delete mode 100644 view/adminhtml/web/css/jquery-ui.min.css create mode 100644 view/adminhtml/web/js/jquery.mask.min.js diff --git a/Block/Adminhtml/Marketplace/Recipient.php b/Block/Adminhtml/Marketplace/Recipient.php index 18b0b60f..259867f2 100644 --- a/Block/Adminhtml/Marketplace/Recipient.php +++ b/Block/Adminhtml/Marketplace/Recipient.php @@ -2,6 +2,9 @@ namespace Pagarme\Pagarme\Block\Adminhtml\Marketplace; +use Exception; +use Magento\Customer\Model\ResourceModel\Customer\Collection; +use Magento\Directory\Model\Country; use Magento\Framework\Registry; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; @@ -12,7 +15,9 @@ class Recipient extends Template { - + /** + * @var Collection + */ private $customerCollection; /** @@ -25,7 +30,6 @@ class Recipient extends Template */ private $coreRegistry; - /** * @var array */ @@ -36,19 +40,31 @@ class Recipient extends Template */ private $recipient = null; + /** + * @var Country + */ + private $country; + /** * Link constructor. * @param Context $context + * @param Registry $registry + * @param CustomerCollectionFactory $customerCollectionFactory + * @param Country $country + * @throws Exception */ public function __construct( - Context $context, - Registry $registry, - CustomerCollectionFactory $customerCollectionFactory - ) { + Context $context, + Registry $registry, + CustomerCollectionFactory $customerCollectionFactory, + Country $country + ) + { $this->coreRegistry = $registry; $this->customerCollection = $customerCollectionFactory->create(); $this->recipientRepository = new RecipientRepository(); + $this->country = $country; Magento2CoreSetup::bootstrap(); parent::__construct($context, []); @@ -127,4 +143,13 @@ public function getSellers() return $this->sellers; } -} \ No newline at end of file + + /** + * @param string $countryCode + * @return array + */ + public function getAllRegionsOfCountry($countryCode = 'BR') + { + return $this->country->loadByCode($countryCode)->getRegions()->getData(); + } +} diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 6812e249..098f2990 100755 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -15,9 +15,10 @@ class InstallSchema implements InstallSchemaInterface * {@inheritdoc} */ public function install( - SchemaSetupInterface $setup, + SchemaSetupInterface $setup, ModuleContextInterface $context - ) { + ) + { $installer = $setup; $installer->startSetup(); @@ -40,14 +41,14 @@ public function install( $this->installRecurrenceCharge($setup); $this->installSubProducts($setup); $this->installProductsPlan($setup); - $this->installRecipients($setup); $setup->endSetup(); } public function installConfig( SchemaSetupInterface $installer - ) { + ) + { $tableName = $installer->getTable('pagarme_module_core_configuration'); if (!$installer->getConnection()->isTableExists($tableName)) { $configTable = $installer->getConnection() @@ -92,7 +93,8 @@ public function installConfig( public function installWebhook( SchemaSetupInterface $installer - ) { + ) + { $tableName = $installer->getTable('pagarme_module_core_webhook'); if (!$installer->getConnection()->isTableExists($tableName)) { $webhookTable = $installer->getConnection() @@ -138,7 +140,8 @@ public function installWebhook( public function installOrder( SchemaSetupInterface $installer - ) { + ) + { $tableName = $installer->getTable('pagarme_module_core_order'); if (!$installer->getConnection()->isTableExists($tableName)) { $webhookTable = $installer->getConnection() @@ -193,7 +196,8 @@ public function installOrder( public function installCharge( SchemaSetupInterface $installer - ) { + ) + { $tableName = $installer->getTable('pagarme_module_core_charge'); if (!$installer->getConnection()->isTableExists($tableName)) { $webhookTable = $installer->getConnection() @@ -315,7 +319,8 @@ public function installCharge( public function installTransaction( SchemaSetupInterface $installer - ) { + ) + { $tableName = $installer->getTable('pagarme_module_core_transaction'); if (!$installer->getConnection()->isTableExists($tableName)) { $webhookTable = $installer->getConnection() @@ -549,7 +554,7 @@ public function installCard(SchemaSetupInterface $installer) 'brand', Table::TYPE_TEXT, 255, - ['nullable' => false, 'default' => ''], + ['nullable' => false, 'default' => ''], 'Card Brand' ) ->setComment('Pagar.me Card Tokens') @@ -857,9 +862,9 @@ public function installHubToken(SchemaSetupInterface $installer) return $installer; } - public function installProductsPlan(SchemaSetupInterface $installer) + public function installProductsSubscription(SchemaSetupInterface $installer) { - $tableName = $installer->getTable('pagarme_module_core_recurrence_products_plan'); + $tableName = $installer->getTable('pagarme_module_core_recurrence_products_subscription'); if (!$installer->getConnection()->isTableExists($tableName)) { $customer = $installer->getConnection() ->newTable($tableName) @@ -875,51 +880,6 @@ public function installProductsPlan(SchemaSetupInterface $installer) ], 'ID' ) - ->addColumn( - 'interval_type', - Table::TYPE_TEXT, - 15, - [ - 'nullable' => false - ], - 'Day, week, month ou year' - ) - ->addColumn( - 'interval_count', - Table::TYPE_SMALLINT, - 2, - [ - 'nullable' => false - ], - '1 - 12' - ) - ->addColumn( - 'name', - Table::TYPE_TEXT, - 255, - [ - 'nullable' => true - ], - "Product name" - ) - ->addColumn( - 'description', - Table::TYPE_TEXT, - 500, - [ - 'nullable' => true - ], - "Product description" - ) - ->addColumn( - 'plan_id', - Table::TYPE_TEXT, - 21, - [ - 'nullable' => true - ], - "Api's id" - ) ->addColumn( 'product_id', Table::TYPE_INTEGER, @@ -939,7 +899,7 @@ public function installProductsPlan(SchemaSetupInterface $installer) "Accepts credit card" ) ->addColumn( - 'installments', + 'allow_installments', Table::TYPE_TEXT, 1, [ @@ -957,46 +917,38 @@ public function installProductsPlan(SchemaSetupInterface $installer) "Accepts boleto" ) ->addColumn( - 'billing_type', + 'sell_as_normal_product', Table::TYPE_TEXT, - 11, + 1, [ 'nullable' => false ], - "Prepaid, postpaid ou exact_day" + "Allow sell as normal product" ) ->addColumn( - 'status', + 'billing_type', Table::TYPE_TEXT, 11, [ 'nullable' => false ], - "Active, inactive ou deleted" - ) - ->addColumn( - 'trial_period_days', - Table::TYPE_TEXT, - 11, - [ - 'nullable' => true - ], - "Trial period in days" + "Prepaid, postpaid ou exact_day" ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) + ->setComment('Product Plan Table') ->setOption('charset', 'utf8'); $installer->getConnection()->createTable($customer); @@ -1004,11 +956,14 @@ public function installProductsPlan(SchemaSetupInterface $installer) return $installer; } - public function installSubProducts(SchemaSetupInterface $installer) + public function installSubscriptionItems(SchemaSetupInterface $installer) { - $tableName = $installer->getTable('pagarme_module_core_recurrence_sub_products'); + $tableName = $installer->getTable( + 'pagarme_module_core_recurrence_subscription_items' + ); + if (!$installer->getConnection()->isTableExists($tableName)) { - $customer = $installer->getConnection() + $configTable = $installer->getConnection() ->newTable($tableName) ->addColumn( 'id', @@ -1023,177 +978,61 @@ public function installSubProducts(SchemaSetupInterface $installer) 'ID' ) ->addColumn( - 'product_id', - Table::TYPE_INTEGER, - 255, - [ - 'nullable' => false - ], - "Magento's product id" - ) - ->addColumn( - 'product_recurrence_id', - Table::TYPE_INTEGER, - 255, + 'pagarme_id', + Table::TYPE_TEXT, + null, [ 'nullable' => false ], - 'Id from table pagarme_module_core_products_(plan/subscription)' + 'format: si_xxxxxxxxxxxxxxxx' ) + ->setOption('charset', 'utf8') ->addColumn( - 'recurrence_type', + 'subscription_id', Table::TYPE_TEXT, - 255, + null, [ 'nullable' => false ], - 'Type of recurrence product (plan or subscription)' + 'format: sub_xxxxxxxxxxxxxxxx' ) + ->setOption('charset', 'utf8') ->addColumn( - 'cycles', - Table::TYPE_INTEGER, - 5, + 'code', + Table::TYPE_TEXT, + 100, [ - 'nullable' => true + 'nullable' => false, ], - 'Cycle' + 'Product code on platform' ) ->addColumn( 'quantity', Table::TYPE_INTEGER, - 255, - [ - 'nullable' => true - ], - "Quantity" - ) - ->addColumn( - 'trial_period_days', - Table::TYPE_INTEGER, - 255, - [ - 'nullable' => true - ], - "Trial period" - ) - ->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], - 'Created At' - ) - ->addColumn( - 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], - 'Updated At' - ) - ->addColumn( - 'pagarme_id', - Table::TYPE_TEXT, - 21, - ['nullable' => true], - 'Pagarme Id' - ) - ->setOption('charset', 'utf8'); - - $installer->getConnection()->createTable($customer); - } - return $installer; - } - - public function installProductsSubscription(SchemaSetupInterface $installer) - { - $tableName = $installer->getTable('pagarme_module_core_recurrence_products_subscription'); - if (!$installer->getConnection()->isTableExists($tableName)) { - $customer = $installer->getConnection() - ->newTable($tableName) - ->addColumn( - 'id', - Table::TYPE_INTEGER, null, [ - 'identity' => true, 'unsigned' => true, 'nullable' => false, - 'primary' => true - ], - 'ID' - ) - ->addColumn( - 'product_id', - Table::TYPE_INTEGER, - 11, - [ - 'nullable' => true - ], - "Product in Magento's table" - ) - ->addColumn( - 'credit_card', - Table::TYPE_TEXT, - 1, - [ - 'nullable' => false - ], - "Accepts credit card" - ) - ->addColumn( - 'allow_installments', - Table::TYPE_TEXT, - 1, - [ - 'nullable' => false - ], - "Accepts installments" - ) - ->addColumn( - 'boleto', - Table::TYPE_TEXT, - 1, - [ - 'nullable' => false - ], - "Accepts boleto" - ) - ->addColumn( - 'sell_as_normal_product', - Table::TYPE_TEXT, - 1, - [ - 'nullable' => false - ], - "Allow sell as normal product" - ) - ->addColumn( - 'billing_type', - Table::TYPE_TEXT, - 11, - [ - 'nullable' => false ], - "Prepaid, postpaid ou exact_day" + 'Quantity' ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) - ->setComment('Product Plan Table') ->setOption('charset', 'utf8'); - $installer->getConnection()->createTable($customer); + $installer->getConnection()->createTable($configTable); } return $installer; } @@ -1264,16 +1103,16 @@ public function installSubscriptionRepetitions(SchemaSetupInterface $installer) ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) ->setOption('charset', 'utf8'); @@ -1405,16 +1244,16 @@ public function installRecurrenceSubscription(SchemaSetupInterface $installer) ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) ->setOption('charset', 'utf8'); @@ -1570,30 +1409,30 @@ public function installRecurrenceCharge(SchemaSetupInterface $installer) ->setOption('charset', 'utf8') ->addColumn( 'cycle_start', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, ['nullable' => false], 'Cycle Start' ) ->addColumn( 'cycle_end', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, ['nullable' => false], 'Cycle End' ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) ->setOption('charset', 'utf8'); @@ -1603,14 +1442,11 @@ public function installRecurrenceCharge(SchemaSetupInterface $installer) return $installer; } - public function installSubscriptionItems(SchemaSetupInterface $installer) + public function installSubProducts(SchemaSetupInterface $installer) { - $tableName = $installer->getTable( - 'pagarme_module_core_recurrence_subscription_items' - ); - + $tableName = $installer->getTable('pagarme_module_core_recurrence_sub_products'); if (!$installer->getConnection()->isTableExists($tableName)) { - $configTable = $installer->getConnection() + $customer = $installer->getConnection() ->newTable($tableName) ->addColumn( 'id', @@ -1625,68 +1461,90 @@ public function installSubscriptionItems(SchemaSetupInterface $installer) 'ID' ) ->addColumn( - 'pagarme_id', - Table::TYPE_TEXT, - null, + 'product_id', + Table::TYPE_INTEGER, + 255, [ 'nullable' => false ], - 'format: si_xxxxxxxxxxxxxxxx' + "Magento's product id" ) - ->setOption('charset', 'utf8') ->addColumn( - 'subscription_id', - Table::TYPE_TEXT, - null, + 'product_recurrence_id', + Table::TYPE_INTEGER, + 255, [ 'nullable' => false ], - 'format: sub_xxxxxxxxxxxxxxxx' + 'Id from table pagarme_module_core_products_(plan/subscription)' ) - ->setOption('charset', 'utf8') ->addColumn( - 'code', + 'recurrence_type', Table::TYPE_TEXT, - 100, + 255, [ - 'nullable' => false, + 'nullable' => false ], - 'Product code on platform' + 'Type of recurrence product (plan or subscription)' + ) + ->addColumn( + 'cycles', + Table::TYPE_INTEGER, + 5, + [ + 'nullable' => true + ], + 'Cycle' ) ->addColumn( 'quantity', Table::TYPE_INTEGER, - null, + 255, [ - 'unsigned' => true, - 'nullable' => false, + 'nullable' => true ], - 'Quantity' + "Quantity" + ) + ->addColumn( + 'trial_period_days', + Table::TYPE_INTEGER, + 255, + [ + 'nullable' => true + ], + "Trial period" ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) + ->addColumn( + 'pagarme_id', + Table::TYPE_TEXT, + 21, + ['nullable' => true], + 'Pagarme Id' + ) ->setOption('charset', 'utf8'); - $installer->getConnection()->createTable($configTable); + $installer->getConnection()->createTable($customer); } return $installer; } - public function installRecipients(SchemaSetupInterface $installer) + public function installProductsPlan(SchemaSetupInterface $installer) { - $tableName = $installer->getTable('pagarme_module_core_recipients'); + $tableName = $installer->getTable('pagarme_module_core_recurrence_products_plan'); if (!$installer->getConnection()->isTableExists($tableName)) { $customer = $installer->getConnection() ->newTable($tableName) @@ -1703,71 +1561,125 @@ public function installRecipients(SchemaSetupInterface $installer) 'ID' ) ->addColumn( - 'external_id', + 'interval_type', Table::TYPE_TEXT, - null, + 15, [ 'nullable' => false ], - 'External ID' + 'Day, week, month ou year' + ) + ->addColumn( + 'interval_count', + Table::TYPE_SMALLINT, + 2, + [ + 'nullable' => false + ], + '1 - 12' ) ->addColumn( 'name', Table::TYPE_TEXT, 255, + [ + 'nullable' => true + ], + "Product name" + ) + ->addColumn( + 'description', + Table::TYPE_TEXT, + 500, + [ + 'nullable' => true + ], + "Product description" + ) + ->addColumn( + 'plan_id', + Table::TYPE_TEXT, + 21, + [ + 'nullable' => true + ], + "Api's id" + ) + ->addColumn( + 'product_id', + Table::TYPE_INTEGER, + 11, + [ + 'nullable' => true + ], + "Product in Magento's table" + ) + ->addColumn( + 'credit_card', + Table::TYPE_TEXT, + 1, [ 'nullable' => false ], - 'Name' + "Accepts credit card" ) ->addColumn( - 'email', + 'installments', Table::TYPE_TEXT, - 255, + 1, [ 'nullable' => false ], - 'Email' + "Accepts installments" ) ->addColumn( - 'document_type', + 'boleto', Table::TYPE_TEXT, - 255, + 1, [ 'nullable' => false ], - 'Document Type' + "Accepts boleto" ) ->addColumn( - 'document', + 'billing_type', Table::TYPE_TEXT, - 255, + 11, [ 'nullable' => false ], - 'Document' + "Prepaid, postpaid ou exact_day" ) ->addColumn( - 'pagarme_id', + 'status', Table::TYPE_TEXT, - null, + 11, [ 'nullable' => false ], - 'format: rp_xxxxxxxxxxxxxxxx' + "Active, inactive ou deleted" + ) + ->addColumn( + 'trial_period_days', + Table::TYPE_TEXT, + 11, + [ + 'nullable' => true + ], + "Trial period in days" ) ->addColumn( 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT], 'Created At' ) ->addColumn( 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, + Table::TYPE_TIMESTAMP, null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], + ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE], 'Updated At' ) ->setOption('charset', 'utf8'); diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 53e51d0a..b78d015a 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -25,10 +25,6 @@ public function upgrade( $setup = $installSchema->installHubToken($setup); } - if (version_compare($version, "1.2.0", "<")) { - $setup = $installSchema->installRecipients($setup); - } - if (version_compare($version, '2.2.5', '<')) { $connection = $setup->getConnection(); $connection->addColumn( diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index b48ccb32..b3a1029d 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -7,6 +7,9 @@ api.mundipagg.com api.pagar.me + brasilapi.com.br + viacep.com.br + servicodados.ibge.gov.br diff --git a/etc/db_schema.xml b/etc/db_schema.xml index bd27c3f8..7180f5df 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -22,7 +22,7 @@ - +
@@ -36,7 +36,7 @@
- +
@@ -50,7 +50,7 @@
- +
@@ -71,4 +71,17 @@
+ + + + + + + + + + + + +
diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json index a4eeac8a..bf54df43 100644 --- a/etc/db_schema_whitelist.json +++ b/etc/db_schema_whitelist.json @@ -79,5 +79,20 @@ "constraint": { "PRIMARY": true } + }, + "pagarme_module_core_recipients": { + "column": { + "id": true, + "external_id": true, + "pagarme_id": true, + "type": true, + "document": true, + "name": true, + "created_at": true, + "updated_at": true + }, + "constraint": { + "PRIMARY": true + } } -} +} \ No newline at end of file diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 49335d9c..fc643199 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -402,6 +402,7 @@ "

Warning! Don't forget to add your store's domain on Pagar.me dashboard

", "

Aviso! Não se esqueça de adicionar o domínio da sua loja no painel do Pagar.me

" "View Integration", "Ver Integração" "Integrate With Pagar.me", "Integrar com Pagar.me" +"Access Pagar.me Dash","Acessar a Dash Pagar.me" "Important!","Importante!" "This store is linked to the Pagar.me test environment. This environment is intended for integration validation and does not generate real financial transactions.","Esta loja está vinculada ao ambiente de testes da Pagar.me. Este ambiente é destinado a validação de integração e não gera operações financeiras reais." "Show VAT Number on Storefront must be defined as "Yes" on Stores > Configuration > Customers > %sCustomer Configuration%s > Create New Account Options for Pagar.me module to work on your store.","Mostrar Número VAT na Vitrine deve ser definido como "Sim" em Lojas > Configuração > Clientes > %sConfigurações de cliente%s > Criar Novas Opções de Conta para que o módulo da Pagar.me funcione na sua loja." @@ -431,14 +432,38 @@ "Name","Nome" "Add New Recipient","Adicionar Novo Recebedor" "Recipient not found.","Recebedor não encontrado." -"Select webkul seller","Selecione o vendedor do webkul" +"Seller information","Informações do recebedor" +"Select Webkul seller","Selecione o vendedor do Webkul" "Search","Pesquisar" "Create","Criar" -"Use an existing Pagar.me recipient","Usar um recipiente existente na Pagar.me" -"External ID","ID externo" +"Webkul ID","ID Webkul" +"Site URL","URL do site" +"Phone numbers","Números de telefones" +"Contact type","Tipo de contato" +"Telephone","Telefone" +"Contact number","Número de contato" "Document type","Tipo do documento" -"Document number","Número do documento" +"Document number", "Número do documento" +"Personal data","Dados pessoais" +"Company data","Dados da empresa" +"Company address","Endereço da empresa" +"Mother name","Nome da mãe" +"Date of birth","Data de nascimento" +"Monthly income","Renda mensal" +"Profession","Profissão" +"Reference point","Ponto de referência" +"Trading name","Nome fantasia" +"Annual revenue","Faturamento anual" +"Founding date","Data de fundação" +"Company type","Tipo da empresa" +"CNAE (Brazilian Classification of Economic Activities)","CNAE (Classificação Nacional das Atividades Econômicas)" +"Company name","Razão social" +"Managing partner","Sócio administrador" +"Managing partner phone numbers","Números de telefones do sócio administrador" +"Managing partner address","Endereço do sócio administrador" "Banking information","Informações de banco" +"The bank account holder must be the recipient (same document number).","O titular da conta bancária deve ser o recebedor (mesmo número de documento)." +"Use an existing Pagar.me recipient","Usar um recebedor existente na Pagar.me" "Holder name","Nome do titular" "Bank code","Código do banco" "Branch number","Número da agência" diff --git a/view/adminhtml/layout/pagarme_pagarme_plans_create.xml b/view/adminhtml/layout/pagarme_pagarme_plans_create.xml index e37a61f2..b8414ec6 100755 --- a/view/adminhtml/layout/pagarme_pagarme_plans_create.xml +++ b/view/adminhtml/layout/pagarme_pagarme_plans_create.xml @@ -1,7 +1,6 @@ - diff --git a/view/frontend/web/css/pagarme_kyc.css b/view/frontend/web/css/pagarme_kyc.css new file mode 100644 index 00000000..0e587dd3 --- /dev/null +++ b/view/frontend/web/css/pagarme_kyc.css @@ -0,0 +1,37 @@ +.wk-mp-design .mp-widgets.pagarme-kyc { + width: 100%; +} + +.pagarme-kyc .container { + padding-bottom: 15px; +} + +.pagarme-kyc-box { + border:1px solid #ccc; +} + +.pagarme-kyc-box-title { + border-bottom: 1px solid #ccc; + display: inline-block; + width: 100%; +} + +.pagarme-kyc-box-content { + padding:5px; +} + +.pagarme-kyc-box-content > div { + display: flex; + flex-direction: column; + align-items: center; +} + +.pagarme-kyc-box-content > div button { + margin: 2.5rem; +} + +.pagarme-kyc-modal { + display: none; + padding-top: 3rem; + text-align: center; +} diff --git a/view/frontend/web/js/view/marketplace/kyc.js b/view/frontend/web/js/view/marketplace/kyc.js new file mode 100644 index 00000000..5b7259b2 --- /dev/null +++ b/view/frontend/web/js/view/marketplace/kyc.js @@ -0,0 +1,44 @@ +define([ + 'Magento_Ui/js/modal/modal', + "mage/url", + 'jquery', + 'mage/translate', + 'loader' +], function (modal, mageUrl, $) { + return function (config) { + + $('#pagarme-kyc-start-validation').on('click', async function (){ + const body = $('body'); + try { + body.loader('show'); + const url = mageUrl.build(`rest/V1/pagarme/marketplace/recipient/kyc/link/${config.id}`); + const response = await $.get(mageUrl.build(url)); + body.loader('hide'); + if (response) { + $('#pagarme-kyc-qrcode').attr('src', response.qr_code); + $('#pagarme-kyc-link').attr('href', response.url); + $('.pagarme-kyc-modal').show(); + + const options = { + responsive: true, + innerScroll: true, + // @todo: Using portuguese title for the translation did't work. + title: $.mage.__('Iniciar validação'), + buttons: [{ + text: $.mage.__('Close'), + click: function () { + this.closeModal(); + } + }] + }; + + const popup = modal(options, $('#modal-content')); + $('#modal-content').modal('openModal'); + } + } catch (exception) { + body.loader('hide'); + // this.mageAlert(exception?.responseJSON?.message, $.mage.__('Error!')); + } + }); + }; +}); From cdd4ce3ad317e5f84dc5a2a0d51c0b6487b37b42 Mon Sep 17 00:00:00 2001 From: Mateus Picoloto Date: Tue, 7 May 2024 09:43:02 -0300 Subject: [PATCH 52/63] feat: added config and status validation and error modal --- Block/Customer/Marketplace/Kyc.php | 9 +++- Model/Api/Recipient.php | 3 ++ Model/Recipient.php | 1 - Test/Unit/Model/Api/RecipientTest.php | 43 ++++++++++++++++++- i18n/pt_BR.csv | 2 + .../web/js/grid/columns/recipientStatus.js | 4 +- .../layout/marketplace_account_dashboard.xml | 7 ++- .../templates/customer/marketplace/kyc.phtml | 17 +++++--- view/frontend/web/js/view/marketplace/kyc.js | 38 ++++++++-------- 9 files changed, 95 insertions(+), 29 deletions(-) diff --git a/Block/Customer/Marketplace/Kyc.php b/Block/Customer/Marketplace/Kyc.php index 83d7c83c..98123226 100644 --- a/Block/Customer/Marketplace/Kyc.php +++ b/Block/Customer/Marketplace/Kyc.php @@ -11,6 +11,7 @@ namespace Pagarme\Pagarme\Block\Customer\Marketplace; use Magento\Customer\Model\Session; +use Pagarme\Pagarme\Model\Recipient; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; use Pagarme\Pagarme\Model\ResourceModel\Recipients\CollectionFactory; @@ -43,7 +44,11 @@ public function __construct( $this->collectionFactory = $collectionFactory; parent::__construct($context, $data); } + + /** + * @return Recipient + */ public function getRecipient() { return $this->collectionFactory->create()->addFieldToFilter( @@ -53,11 +58,11 @@ public function getRecipient() } /** - * Get customerid + * Get customerId * * @return int */ - public function getCustomerId() + protected function getCustomerId() { return $this->customerSession->getCustomerId(); } diff --git a/Model/Api/Recipient.php b/Model/Api/Recipient.php index f6b8ac63..8c2a97a0 100644 --- a/Model/Api/Recipient.php +++ b/Model/Api/Recipient.php @@ -176,6 +176,9 @@ public function createKycLink(string $id) throw new NoSuchEntityException(__('Recipient not founded.')); } $kycLink = $this->recipientService->createKycLink($recipientModel->getPagarmeId()); + if (empty($kycLink->url) || empty($kycLink->base64_qrcode)) { + throw new NoSuchEntityException(__('Security validation not generated.')); + } $kycResponse = $this->kycLinkResponseFactory->create(); $kycResponse->setUrl($kycLink->url) ->setQrCode('data:image/svg+xml;base64,' . $kycLink->base64_qrcode); diff --git a/Model/Recipient.php b/Model/Recipient.php index 254308ba..1e5ce179 100644 --- a/Model/Recipient.php +++ b/Model/Recipient.php @@ -2,7 +2,6 @@ namespace Pagarme\Pagarme\Model; -use Magento\Framework\DataObject\IdentityInterface; use Magento\Framework\Model\AbstractModel; class Recipient extends AbstractModel diff --git a/Test/Unit/Model/Api/RecipientTest.php b/Test/Unit/Model/Api/RecipientTest.php index 0f968e95..2955ec8d 100644 --- a/Test/Unit/Model/Api/RecipientTest.php +++ b/Test/Unit/Model/Api/RecipientTest.php @@ -59,8 +59,9 @@ public function testCreateKycLinkShouldReturnQrCodeAndLink() $result = $recipientModelApi->createKycLink(1); + $expectedBase64QrCode = "data:image/svg+xml;base64,$base64QrCode"; $this->assertSame($kycUrl, $result->getUrl()); - $this->assertSame($base64QrCode, $result->getQrCode()); + $this->assertSame($expectedBase64QrCode, $result->getQrCode()); } public function testCreateKycLinkShouldNotFoundRecipient() @@ -99,4 +100,44 @@ public function testCreateKycLinkShouldNotFoundRecipient() $recipientModelApi->createKycLink(1); } + + public function testCreateKycLinkShouldNotGenerateSecurityValidation() + { + $requestMock = Mockery::mock(Request::class); + + $recipientModelMock = Mockery::mock(RecipientModel::class); + $recipientModelMock->shouldReceive('getPagarmeId') + ->andReturn('rp_xxxxxxxxxxxxxxxx'); + + $recipientFactoryMock = Mockery::mock(RecipientFactory::class); + $recipientFactoryMock->shouldReceive('create') + ->andReturn($recipientModelMock); + + $resourceModelRecipientMock = Mockery::mock(ResourceModelRecipient::class); + $resourceModelRecipientMock->shouldReceive('load') + ->andReturnSelf(); + + $coreRecipientMock = Mockery::mock(CoreRecipient::class); + + $createKyLinkResponseMock = new CreateKycLinkResponse(); + $recipientServiceMock = Mockery::mock(RecipientService::class); + $recipientServiceMock->shouldReceive('createKycLink') + ->andReturn($createKyLinkResponseMock); + + $kycLinkResponseFactoryMock = Mockery::mock(KycLinkResponseInterfaceFactory::class); + + $recipientModelApi = new Recipient( + $requestMock, + $recipientFactoryMock, + $resourceModelRecipientMock, + $coreRecipientMock, + $recipientServiceMock, + $kycLinkResponseFactoryMock + ); + + $this->expectException(NoSuchEntityException::class); + $this->expectExceptionMessage('Security validation not generated.'); + + $recipientModelApi->createKycLink(1); + } } \ No newline at end of file diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index dc00f14a..3c313e72 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -601,3 +601,5 @@ "Blocked","Bloqueado" "Inactive","Inativo" "Recipient not founded.","Recebedor não encontrado." +"Security validation not generated.","Validação de segurança não gerada." +"Problem to generate security validation, please try again later.","Problema ao gerar validação de segurança, por favor tente novamente mais tarde." diff --git a/view/adminhtml/web/js/grid/columns/recipientStatus.js b/view/adminhtml/web/js/grid/columns/recipientStatus.js index cd934e83..558da3aa 100644 --- a/view/adminhtml/web/js/grid/columns/recipientStatus.js +++ b/view/adminhtml/web/js/grid/columns/recipientStatus.js @@ -77,7 +77,9 @@ define([ } catch (exception) { $('body').loader('hide'); $('body').notification('clear'); - this.mageAlert(exception?.responseJSON?.message, translate('Error!')); + // TODO: Using portuguese string because mage/translate and knockout i18n were not working + const errorContent = `

Problema ao gerar validação de segurança, por favor tente novamente mais tarde.

`; + this.mageAlert(errorContent, translate('Error!')); } }, diff --git a/view/frontend/layout/marketplace_account_dashboard.xml b/view/frontend/layout/marketplace_account_dashboard.xml index 75a350b0..59833303 100644 --- a/view/frontend/layout/marketplace_account_dashboard.xml +++ b/view/frontend/layout/marketplace_account_dashboard.xml @@ -14,7 +14,12 @@ - +
diff --git a/view/frontend/templates/customer/marketplace/kyc.phtml b/view/frontend/templates/customer/marketplace/kyc.phtml index ad248cbb..dc19d7ce 100644 --- a/view/frontend/templates/customer/marketplace/kyc.phtml +++ b/view/frontend/templates/customer/marketplace/kyc.phtml @@ -1,13 +1,12 @@ getRecipient(); +$recipientId = $recipient->getId(); -$recipientId = $block->getRecipient()->getId(); - -if (empty($recipientId)) { +if (empty($recipientId) || $recipient->getStatus() !== \Pagarme\Core\Marketplace\Interfaces\RecipientInterface::VALIDATION_REQUESTED) { return; } @@ -34,7 +33,7 @@ if (empty($recipientId)) { -