From 82a6389889d199c4ebc7b6165c07537e0715ab27 Mon Sep 17 00:00:00 2001 From: Vinicius Berardi Date: Fri, 23 Jul 2021 12:15:45 -0300 Subject: [PATCH 001/123] =?UTF-8?q?=F0=9F=9A=A7=20Adds=20config=20"Marketp?= =?UTF-8?q?lace"=20on=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etc/adminhtml/system.xml | 1 + etc/adminhtml/system/marketplace.xml | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 etc/adminhtml/system/marketplace.xml diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index d0ddc59a..61311561 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -28,6 +28,7 @@ + diff --git a/etc/adminhtml/system/marketplace.xml b/etc/adminhtml/system/marketplace.xml new file mode 100644 index 00000000..78d071a6 --- /dev/null +++ b/etc/adminhtml/system/marketplace.xml @@ -0,0 +1,13 @@ + + + + + + + + + Magento\Config\Model\Config\Source\Yesno + pagarme_pagarme/marketplace/active + + + From 122eb3e1cd9f657d92e81d9952a40956bdc35217 Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Fri, 6 Aug 2021 15:39:35 -0300 Subject: [PATCH 002/123] :sparkles: adds new marketplace configs on admin --- Concrete/Magento2CoreSetup.php | 50 +++++++++++++++++++------- Model/Source/Marketplace/Recipient.php | 26 ++++++++++++++ etc/adminhtml/system/marketplace.xml | 36 +++++++++++++++++++ 3 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 Model/Source/Marketplace/Recipient.php diff --git a/Concrete/Magento2CoreSetup.php b/Concrete/Magento2CoreSetup.php index 94a65e31..2ba95be7 100644 --- a/Concrete/Magento2CoreSetup.php +++ b/Concrete/Magento2CoreSetup.php @@ -143,19 +143,20 @@ public function loadModuleConfigurationFromPlatform($storeConfig = null) return; } - self::fillWithGeneralConfig($configData, $storeConfig); - self::fillWithPagarmeKeys($configData, $storeConfig); - self::fillWithCardConfig($configData, $storeConfig); - self::fillWithBoletoConfig($configData, $storeConfig); - self::fillWithPixConfig($configData, $storeConfig); - self::fillWithBoletoCreditCardConfig($configData, $storeConfig); - self::fillWithTwoCreditCardsConfig($configData, $storeConfig); - self::fillWithVoucherConfig($configData, $storeConfig); - self::fillWithDebitConfig($configData, $storeConfig); - self::fillWithAddressConfig($configData, $storeConfig); - self::fillWithMultiBuyerConfig($configData, $storeConfig); - self::fillWithRecurrenceConfig($configData, $storeConfig); - self::fillWithHubConfig($configData, $storeConfig); + self::fillWithGeneralConfig($configData, $storeConfig); + self::fillWithPagarmeKeys($configData, $storeConfig); + self::fillWithCardConfig($configData, $storeConfig); + self::fillWithBoletoConfig($configData, $storeConfig); + self::fillWithPixConfig($configData, $storeConfig); + self::fillWithBoletoCreditCardConfig($configData, $storeConfig); + self::fillWithTwoCreditCardsConfig($configData, $storeConfig); + self::fillWithVoucherConfig($configData, $storeConfig); + self::fillWithDebitConfig($configData, $storeConfig); + self::fillWithAddressConfig($configData, $storeConfig); + self::fillWithMultiBuyerConfig($configData, $storeConfig); + self::fillWithRecurrenceConfig($configData, $storeConfig); + self::fillWithHubConfig($configData, $storeConfig); + self::fillWithMarketplaceConfig($configData, $storeConfig); $configurationFactory = new ConfigurationFactory(); $config = $configurationFactory->createFromJsonData( @@ -609,4 +610,27 @@ static private function fillWithRecurrenceConfig(&$dataObj, $storeConfig) $section ); } + + static private function fillWithMarketplaceConfig( + stdClass $configData, + ScopeConfigInterface $storeConfig + ) { + $options = [ + 'enabled' => 'active', + 'responsibilityForProcessingFees' + => 'responsibility_for_processing_fees', + 'responsibilityForChargebacks' + => 'responsibility_for_chargebacks', + 'responsibilityForReceivingSplitRemainder' + => 'responsibility_for_receiving_split_remainder', + 'responsibilityForReceivingExtrasAndDiscounts' + => 'responsibility_for_receiving_extras_discounts' + ]; + + $section = 'pagarme_pagarme/marketplace/'; + + $marketplaceObject = new \stdClass(); + + $configData->marketplaceConfig = self::fillDataObj($storeConfig, $options, $marketplaceObject, $section); + } } diff --git a/Model/Source/Marketplace/Recipient.php b/Model/Source/Marketplace/Recipient.php new file mode 100644 index 00000000..62ca454f --- /dev/null +++ b/Model/Source/Marketplace/Recipient.php @@ -0,0 +1,26 @@ + 'marketplace_sellers', + 'label' => __('Marketplace and Sellers'), + ], + [ + 'value' => 'marketplace', + 'label' => __('Marketplace') + ], + [ + 'value' => 'sellers', + 'label' => __('Sellers') + ] + ]; + } +} diff --git a/etc/adminhtml/system/marketplace.xml b/etc/adminhtml/system/marketplace.xml index 78d071a6..e2acb3d8 100644 --- a/etc/adminhtml/system/marketplace.xml +++ b/etc/adminhtml/system/marketplace.xml @@ -9,5 +9,41 @@ Magento\Config\Model\Config\Source\Yesno pagarme_pagarme/marketplace/active + + + + Pagarme\Pagarme\Model\Source\Marketplace\Recipient + pagarme_pagarme/marketplace/responsibility_for_processing_fees + + 1 + + + + + + Pagarme\Pagarme\Model\Source\Marketplace\Recipient + pagarme_pagarme/marketplace/responsibility_for_chargebacks + + 1 + + + + + + Pagarme\Pagarme\Model\Source\Marketplace\Recipient + pagarme_pagarme/marketplace/responsibility_for_receiving_split_remainder + + 1 + + + + + + Pagarme\Pagarme\Model\Source\Marketplace\Recipient + pagarme_pagarme/marketplace/responsibility_for_receiving_extras_and_discounts + + 1 + + From 8fc5a583c97162354f86e07f291e9e3685f940bf Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Fri, 6 Aug 2021 17:22:56 -0300 Subject: [PATCH 003/123] :globe_with_meridians: adds translation for fields on admin --- i18n/en_US.csv | 6 ++++++ i18n/pt_BR.csv | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/i18n/en_US.csv b/i18n/en_US.csv index e01b0179..5e487cf6 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -289,3 +289,9 @@ "Integrate With Pagar.me", "Integrate With Pagar.me" "Important! This store is linked to the Pagar.me test environment. This environment is intended for integration validation and does not generate real financial transactions.","Important! This store is linked to the Pagar.me test environment. This environment is intended for integration validation and does not generate real financial transactions." "Important! This store is in the testing phase. Orders placed in this environment will not be carried out.","Important! This store is in the testing phase. Orders placed in this environment will not be carried out." +"Responsibility for processing fees","Responsibility for processing fees" +"Responsibility for chargebacks","Responsibility for chargebacks" +"Responsibility for receiving split remainder","Responsibility for receiving split remainder" +"Responsibility for receiving extras and discounts","Responsibility for receiving extras and discounts" +"Marketplace and Sellers","Marketplace and Sellers" +"Sellers","Sellers" diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 33b672c1..cd753fa8 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -370,4 +370,9 @@ "Important! This store is in the testing phase. Orders placed in this environment will not be carried out.","Importante! Esta loja está em fase de testes. Os pedidos realizados neste ambiente não serão efetivados." "Please enter a number greater than 0 in this field.", "Digite um número maior que 0 neste campo." "A installment times should be set between 1 and 24!", "Um prazo de parcelamento deve ser definido entre 1 e 24!" -"Please enter a valid number in this field.", "Insira um número válido neste campo." \ No newline at end of file +"Please enter a valid number in this field.", "Insira um número válido neste campo.""Responsibility for processing fees","Responsabilidade pelas taxas de processamento" +"Responsibility for chargebacks","Responsabilidade pelos estornos" +"Responsibility for receiving split remainder","Responsabilidade pelo recebimento do restante da divisão" +"Responsibility for receiving extras and discounts","Responsabilidade pelo recebimento de extras e descontos" +"Marketplace and Sellers","Marketplace e Vendedores" +"Sellers","Vendedores" From 588c54522a3e5954f67425d334a5124ec532cc9a Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Tue, 10 Aug 2021 15:41:10 -0300 Subject: [PATCH 004/123] :globe_with_meridians: fixes translation --- i18n/pt_BR.csv | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index cd753fa8..f597959c 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -370,8 +370,9 @@ "Important! This store is in the testing phase. Orders placed in this environment will not be carried out.","Importante! Esta loja está em fase de testes. Os pedidos realizados neste ambiente não serão efetivados." "Please enter a number greater than 0 in this field.", "Digite um número maior que 0 neste campo." "A installment times should be set between 1 and 24!", "Um prazo de parcelamento deve ser definido entre 1 e 24!" -"Please enter a valid number in this field.", "Insira um número válido neste campo.""Responsibility for processing fees","Responsabilidade pelas taxas de processamento" -"Responsibility for chargebacks","Responsabilidade pelos estornos" +"Please enter a valid number in this field.", "Insira um número válido neste campo." +"Responsibility for processing fees","Responsabilidade pelas taxas de processamento" +"Responsibility for chargebacks","Responsabilidade pelos chargebacks" "Responsibility for receiving split remainder","Responsabilidade pelo recebimento do restante da divisão" "Responsibility for receiving extras and discounts","Responsabilidade pelo recebimento de extras e descontos" "Marketplace and Sellers","Marketplace e Vendedores" From 08158b238040019ceefb366e4b21055ab8617ff9 Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Wed, 11 Aug 2021 12:35:47 -0300 Subject: [PATCH 005/123] :sparkles: adds recipients page and table --- Controller/Adminhtml/Recipients/Index.php | 37 +++++ Model/Recipient.php | 24 ++++ Model/ResourceModel/Recipients.php | 19 +++ Model/ResourceModel/Recipients/Collection.php | 23 +++ Setup/InstallSchema.php | 85 +++++++++++ Setup/UpgradeSchema.php | 2 + etc/adminhtml/menu.xml | 3 + etc/di.xml | 17 ++- i18n/en_US.csv | 3 + i18n/pt_BR.csv | 3 + .../pagarme_pagarme_recipients_index.xml | 9 ++ .../pagarme_pagarme_recipients_listing.xml | 134 ++++++++++++++++++ 12 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 Controller/Adminhtml/Recipients/Index.php create mode 100644 Model/Recipient.php create mode 100644 Model/ResourceModel/Recipients.php create mode 100644 Model/ResourceModel/Recipients/Collection.php create mode 100644 view/adminhtml/layout/pagarme_pagarme_recipients_index.xml create mode 100644 view/adminhtml/ui_component/pagarme_pagarme_recipients_listing.xml diff --git a/Controller/Adminhtml/Recipients/Index.php b/Controller/Adminhtml/Recipients/Index.php new file mode 100644 index 00000000..2aac6b14 --- /dev/null +++ b/Controller/Adminhtml/Recipients/Index.php @@ -0,0 +1,37 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + + /** + * Index action + * + * @return \Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__("Recipients")); + + return $resultPage; + } +} diff --git a/Model/Recipient.php b/Model/Recipient.php new file mode 100644 index 00000000..29f1688a --- /dev/null +++ b/Model/Recipient.php @@ -0,0 +1,24 @@ +_init('Pagarme\Pagarme\Model\ResourceModel\Recipients'); + } + + /** + * Return unique ID(s) for each object in system + * + * @return string[] + */ + public function getIdentities() + { + return $this->getId(); + } +} diff --git a/Model/ResourceModel/Recipients.php b/Model/ResourceModel/Recipients.php new file mode 100644 index 00000000..6a764c2e --- /dev/null +++ b/Model/ResourceModel/Recipients.php @@ -0,0 +1,19 @@ +_init('pagarme_module_core_recipients', 'id'); + } +} diff --git a/Model/ResourceModel/Recipients/Collection.php b/Model/ResourceModel/Recipients/Collection.php new file mode 100644 index 00000000..bb70fbcf --- /dev/null +++ b/Model/ResourceModel/Recipients/Collection.php @@ -0,0 +1,23 @@ +_init( + 'Pagarme\Pagarme\Model\Recipient', + 'Pagarme\Pagarme\Model\ResourceModel\Recipients' + ); + } +} diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 6009c919..9dce383d 100755 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -40,6 +40,7 @@ public function install( $this->installRecurrenceCharge($setup); $this->installSubProducts($setup); $this->installProductsPlan($setup); + $this->installRecipients($setup); $setup->endSetup(); } @@ -1682,4 +1683,88 @@ public function installSubscriptionItems(SchemaSetupInterface $installer) } return $installer; } + + public function installRecipients(SchemaSetupInterface $installer) + { + $tableName = $installer->getTable('pagarme_module_core_recipients'); + 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( + 'internal_id', + Table::TYPE_TEXT, + null, + [ + 'nullable' => false + ], + 'Id internal from WebKul' + ) + ->addColumn( + 'name', + Table::TYPE_TEXT, + 255, + [ + 'nullable' => false + ], + 'Name' + ) + ->addColumn( + 'email', + Table::TYPE_TEXT, + 255, + [ + 'nullable' => false + ], + 'Email' + ) + ->addColumn( + 'document', + Table::TYPE_TEXT, + 255, + [ + 'nullable' => false + ], + 'Document' + ) + ->addColumn( + 'pagarme_id', + Table::TYPE_TEXT, + null, + [ + 'nullable' => false + ], + 'format: si_xxxxxxxxxxxxxxxx' + ) + ->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' + ) + ->setOption('charset', 'utf8'); + + $installer->getConnection()->createTable($customer); + } + return $installer; + } } diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 2dca7e71..50a875c0 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -24,6 +24,8 @@ public function upgrade( $setup = $installSchema->installHubToken($setup); } + $setup = $installSchema->installRecipients($setup); + $setup->endSetup(); } } diff --git a/etc/adminhtml/menu.xml b/etc/adminhtml/menu.xml index f7aeaeb8..d2a71921 100644 --- a/etc/adminhtml/menu.xml +++ b/etc/adminhtml/menu.xml @@ -7,6 +7,9 @@ + + + diff --git a/etc/di.xml b/etc/di.xml index bdb2ded7..58326476 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -99,6 +99,21 @@ + + + + + Pagarme\Pagarme\Model\ResourceModel\Recipients\Grid\Collection + + + + + + pagarme_module_core_recipients + Pagarme\Pagarme\Model\ResourceModel\Recipients + + + @@ -114,8 +129,6 @@ - - diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 5e487cf6..51f963df 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -295,3 +295,6 @@ "Responsibility for receiving extras and discounts","Responsibility for receiving extras and discounts" "Marketplace and Sellers","Marketplace and Sellers" "Sellers","Sellers" +"Recipients","Recipients" +"Name","Name" +"Add New Recipient","Add New Recipient" diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index f597959c..32b7b028 100644 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -377,3 +377,6 @@ "Responsibility for receiving extras and discounts","Responsabilidade pelo recebimento de extras e descontos" "Marketplace and Sellers","Marketplace e Vendedores" "Sellers","Vendedores" +"Recipients","Recebedores" +"Name","Nome" +"Add New Recipient","Adicionar Novo Recebedor" diff --git a/view/adminhtml/layout/pagarme_pagarme_recipients_index.xml b/view/adminhtml/layout/pagarme_pagarme_recipients_index.xml new file mode 100644 index 00000000..35d1cdb3 --- /dev/null +++ b/view/adminhtml/layout/pagarme_pagarme_recipients_index.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/view/adminhtml/ui_component/pagarme_pagarme_recipients_listing.xml b/view/adminhtml/ui_component/pagarme_pagarme_recipients_listing.xml new file mode 100644 index 00000000..373aad38 --- /dev/null +++ b/view/adminhtml/ui_component/pagarme_pagarme_recipients_listing.xml @@ -0,0 +1,134 @@ ++ + + pagarme_pagarme_recipients_listing.pagarme_pagarme_recipients_listing_data_source + pagarme_pagarme_recipients_listing.pagarme_pagarme_recipients_listing_data_source + + spinner_columns + + + add + Add New Recipient + primary + */*/create + + + + + + + + true + + + + + + + + + + Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider + pagarme_pagarme_recipients_listing_data_source + id + id + + + Magento_Ui/js/grid/provider + + + id + + + + + + + + + + textRange + asc + ID + + + + + + + text + + text + + true + + + Internal ID + + + + + + + text + + text + + true + + + Name + + + + + + + text + + text + + true + + + E-mail + + + + + + + text + + text + + true + + + Document + + + + + + + text + + text + + true + + + Pagar.me ID + + + + + + + id + + + + + From e79b10cff3c48b0082325972e10d31a6b529b873 Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Thu, 12 Aug 2021 12:24:16 -0300 Subject: [PATCH 006/123] :recycle: adds check module version at UpgradeSchema --- Setup/UpgradeSchema.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 50a875c0..831b61e8 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -24,7 +24,9 @@ public function upgrade( $setup = $installSchema->installHubToken($setup); } - $setup = $installSchema->installRecipients($setup); + if (version_compare($version, "1.2.0", "<")) { + $setup = $installSchema->installRecipients($setup); + } $setup->endSetup(); } From 06d8f641091400f9f5a965b98db6e6a0d5ec3ca5 Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Thu, 12 Aug 2021 15:42:39 -0300 Subject: [PATCH 007/123] :recycle: changes format id comment --- Setup/InstallSchema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 9dce383d..78130738 100755 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -1709,7 +1709,7 @@ public function installRecipients(SchemaSetupInterface $installer) [ 'nullable' => false ], - 'Id internal from WebKul' + 'Internal ID' ) ->addColumn( 'name', @@ -1745,7 +1745,7 @@ public function installRecipients(SchemaSetupInterface $installer) [ 'nullable' => false ], - 'format: si_xxxxxxxxxxxxxxxx' + 'format: rp_xxxxxxxxxxxxxxxx' ) ->addColumn( 'created_at', From 80097e219f67bcaf8ae12bfa16f34ba57ae38d78 Mon Sep 17 00:00:00 2001 From: Yan Pantoja Date: Mon, 16 Aug 2021 15:08:06 -0300 Subject: [PATCH 008/123] :sparkles: adds new page to create recipient, sending data to Mark1 and saving to database --- Api/RecipientInterface.php | 13 + Block/Adminhtml/Marketplace/Recipient.php | 19 ++ Concrete/Magento2DatabaseDecorator.php | 5 +- Controller/Adminhtml/Recipients/Create.php | 40 +++ Controller/Adminhtml/Recipients/Index.php | 13 +- Model/Api/Recipient.php | 130 +++++++++ Setup/InstallSchema.php | 9 + etc/di.xml | 3 + etc/webapi.xml | 8 + .../pagarme_pagarme_recipients_create.xml | 13 + .../marketplace/recipients/create.phtml | 255 ++++++++++++++++++ view/adminhtml/web/css/pagarme_style.css | 21 +- view/adminhtml/web/js/recipients.js | 97 +++++++ 13 files changed, 619 insertions(+), 7 deletions(-) create mode 100644 Api/RecipientInterface.php create mode 100644 Block/Adminhtml/Marketplace/Recipient.php create mode 100644 Controller/Adminhtml/Recipients/Create.php create mode 100644 Model/Api/Recipient.php create mode 100644 view/adminhtml/layout/pagarme_pagarme_recipients_create.xml create mode 100644 view/adminhtml/templates/marketplace/recipients/create.phtml create mode 100644 view/adminhtml/web/js/recipients.js diff --git a/Api/RecipientInterface.php b/Api/RecipientInterface.php new file mode 100644 index 00000000..8a3157f1 --- /dev/null +++ b/Api/RecipientInterface.php @@ -0,0 +1,13 @@ +db->getTableName('pagarme_module_core_recurrence_subscription_items'), AbstractDatabaseDecorator::TABLE_HUB_INSTALL_TOKEN => - $this->db->getTableName('pagarme_module_core_hub_install_token') + $this->db->getTableName('pagarme_module_core_hub_install_token'), + + AbstractDatabaseDecorator::TABLE_RECIPIENTS => + $this->db->getTableName('pagarme_module_core_recipients') ]; } diff --git a/Controller/Adminhtml/Recipients/Create.php b/Controller/Adminhtml/Recipients/Create.php new file mode 100644 index 00000000..525c8b74 --- /dev/null +++ b/Controller/Adminhtml/Recipients/Create.php @@ -0,0 +1,40 @@ +resultPageFactory = $resultPageFactory; + } + + /** + * Index action + * + * @return ResultInterface + */ + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__("Create Recipient")); + + return $resultPage; + } +} diff --git a/Controller/Adminhtml/Recipients/Index.php b/Controller/Adminhtml/Recipients/Index.php index 2aac6b14..a5bcc2f8 100644 --- a/Controller/Adminhtml/Recipients/Index.php +++ b/Controller/Adminhtml/Recipients/Index.php @@ -3,6 +3,9 @@ namespace Pagarme\Pagarme\Controller\Adminhtml\Recipients; use Magento\Backend\App\Action; +use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\PageFactory; +use Magento\Framework\Controller\ResultInterface; class Index extends Action { @@ -11,12 +14,12 @@ class Index extends Action /** * Constructor * - * @param \Magento\Backend\App\Action\Context $context - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param Context $context + * @param PageFactory $resultPageFactory */ public function __construct( - \Magento\Backend\App\Action\Context $context, - \Magento\Framework\View\Result\PageFactory $resultPageFactory + Context $context, + PageFactory $resultPageFactory ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($context); @@ -25,7 +28,7 @@ public function __construct( /** * Index action * - * @return \Magento\Framework\Controller\ResultInterface + * @return ResultInterface */ public function execute() { diff --git a/Model/Api/Recipient.php b/Model/Api/Recipient.php new file mode 100644 index 00000000..0850ba90 --- /dev/null +++ b/Model/Api/Recipient.php @@ -0,0 +1,130 @@ +request = $request; + } + + /** + * @return mixed + */ + public function saveFormData() + { + + $post = $this->request->getBodyParams(); + parse_str($post[0], $params); + + $form = $this->getFormattedForm($params['form']); + + if (empty($form)) { + return json_encode([ + 'code' => 400, + 'message' => 'Error on save recipient' + ]); + } + + try { + $recipientService = new RecipientService(); + $recipient = $recipientService->saveFormRecipient($form); + } catch (\Exception $exception) { + return json_encode([ + 'code' => 404, + 'message' => $exception->getMessage() + ]); + } + + return json_encode([ + 'code' => 200, + 'message' => 'Recipient saved' + ]); + } + + public function getFormattedForm($form) + { + if (isset($form['internal_id'])) { + $form['internal_id'] = $form['internal_id']; + } + + if (isset($form['name'])) { + $form['name'] = $form['name']; + } + + if (isset($form['email'])) { + $form['email'] = $form['email']; + } + + if (isset($form['document_type'])) { + $form['document_type'] = $form['document_type']; + } + + if (isset($form['document_number'])) { + $form['document_number'] = $form['document_number']; + } + + if (isset($form['holder_name'])) { + $form['holder_name'] = $form['holder_name']; + } + + if (isset($form['holder_document'])) { + $form['holder_document'] = $form['holder_document']; + } + + if (isset($form['bank'])) { + $form['bank'] = $form['bank']; + } + + if (isset($form['branch_number'])) { + $form['branch_number'] = $form['branch_number']; + } + + if (isset($form['branch_check_digit'])) { + $form['branch_check_digit'] = $form['branch_check_digit']; + } + + if (isset($form['account_number'])) { + $form['account_number'] = $form['account_number']; + } + + if (isset($form['account_check_digit'])) { + $form['account_check_digit'] = $form['account_check_digit']; + } + + if (isset($form['account_type'])) { + $form['account_type'] = $form['account_type']; + } + + if (isset($form['account_type'])) { + $form['account_type'] = $form['account_type']; + } + + if (isset($form['transfer_enabled'])) { + $form['transfer_enabled'] = $form['transfer_enabled']; + } + + if (isset($form['transfer_interval'])) { + $form['transfer_interval'] = $form['transfer_interval']; + } + + if (isset($form['transfer_day'])) { + $form['transfer_day'] = $form['transfer_day']; + } + + return $form; + } +} diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 78130738..24e1a312 100755 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -1729,6 +1729,15 @@ public function installRecipients(SchemaSetupInterface $installer) ], 'Email' ) + ->addColumn( + 'document_type', + Table::TYPE_TEXT, + 255, + [ + 'nullable' => false + ], + 'Document Type' + ) ->addColumn( 'document', Table::TYPE_TEXT, diff --git a/etc/di.xml b/etc/di.xml index 58326476..e5a2b087 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -37,6 +37,9 @@ + + diff --git a/etc/webapi.xml b/etc/webapi.xml index 4e687199..f80fb08f 100755 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -72,6 +72,14 @@ + + + + + + + diff --git a/view/adminhtml/layout/pagarme_pagarme_recipients_create.xml b/view/adminhtml/layout/pagarme_pagarme_recipients_create.xml new file mode 100644 index 00000000..7f1dbd90 --- /dev/null +++ b/view/adminhtml/layout/pagarme_pagarme_recipients_create.xml @@ -0,0 +1,13 @@ + + + + + + +