From 6fef5b2d51b6bb4854cddeab7ce2fa4ce6aae1f5 Mon Sep 17 00:00:00 2001 From: elisei Date: Thu, 29 Jul 2021 12:04:15 -0300 Subject: [PATCH] =?UTF-8?q?Moip=20=E2=99=A5=20Magento=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Desconto para pagamento à vista no cartão de crédito --- Api/Data/MoipInterestInterface.php | 43 ++++ Api/GuestMoipInterestManagementInterface.php | 32 +++ Api/MoipInterestManagementInterface.php | 32 +++ .../Sales/Order/Creditmemo/Totals.php | 69 +++++++ .../Adminhtml/Sales/Order/Invoice/Totals.php | 68 +++++++ Block/Adminhtml/Sales/Order/Totals.php | 64 ++++++ Block/Adminhtml/System/Config/Category.php | 115 +++++++++++ Block/FormCc.php | 20 +- Block/Sales/Totals.php | 114 +++++++++++ Controller/Webhooks/Deny.php | 10 +- Gateway/Config/Config.php | 16 ++ Gateway/Config/ConfigCc.php | 6 +- Gateway/Data/Order/AddressAdapter.php | 2 +- Gateway/Data/Order/OrderAdapter.php | 40 ++++ Gateway/Request/AddressDataRequest.php | 28 ++- Gateway/Request/BillingAddressDataRequest.php | 32 +-- Gateway/Request/DetailTotalsDataRequest.php | 91 +++++++-- Gateway/Request/DeviceDataRequest.php | 4 +- Gateway/Request/PurchasedItemsDataRequest.php | 8 + Gateway/Request/SellerDataRequest.php | 85 +++++--- Model/Data/MoipInterest.php | 36 ++++ Model/GuestMoipInterestManagement.php | 61 ++++++ Model/MoipInterestManagement.php | 188 ++++++++++++++++++ Model/Order/Total/Creditmemo/MoipInterest.php | 46 +++++ Model/Order/Total/Invoice/MoipInterest.php | 48 +++++ Model/Quote/Address/Total/MoipInterest.php | 151 ++++++++++++++ Observer/AddMoipInterestToOrderObserver.php | 38 ++++ etc/adminhtml/di.xml | 14 ++ etc/adminhtml/system.xml | 37 ++-- etc/config.xml | 2 +- etc/db_schema.xml | 35 ++++ etc/db_schema_whitelist.json | 36 ++++ etc/di.xml | 4 +- etc/events.xml | 3 + etc/extension_attributes.xml | 19 ++ etc/fieldset.xml | 21 ++ etc/module.xml | 1 + etc/moip_error_mapping.xml | 2 +- etc/pdf.xml | 20 ++ etc/sales.xml | 26 +++ etc/webapi.xml | 26 +++ i18n/en_US.csv | 96 ++++++++- i18n/pt_BR.csv | 184 ++++++++++++++++- .../layout/sales_order_creditmemo_new.xml | 4 + .../sales_order_creditmemo_updateqty.xml | 16 ++ .../layout/sales_order_creditmemo_view.xml | 16 ++ .../layout/sales_order_invoice_new.xml | 16 ++ .../layout/sales_order_invoice_updateqty.xml | 16 ++ .../layout/sales_order_invoice_view.xml | 17 ++ view/adminhtml/layout/sales_order_view.xml | 17 ++ view/adminhtml/templates/form/cc.phtml | 15 +- view/adminhtml/web/css/system_config.css | 2 +- view/frontend/layout/checkout_cart_index.xml | 35 ++++ view/frontend/layout/checkout_index_index.xml | 20 ++ .../layout/checkout_onepage_success.xml | 3 + .../sales_email_order_creditmemo_items.xml | 15 ++ .../sales_email_order_invoice_items.xml | 16 ++ .../layout/sales_email_order_items.xml | 17 ++ view/frontend/layout/sales_guest_invoice.xml | 16 ++ view/frontend/layout/sales_guest_print.xml | 16 ++ .../layout/sales_guest_printinvoice.xml | 16 ++ view/frontend/layout/sales_guest_view.xml | 16 ++ .../layout/sales_order_creditmemo.xml | 16 ++ view/frontend/layout/sales_order_invoice.xml | 16 ++ view/frontend/layout/sales_order_print.xml | 16 ++ view/frontend/layout/sales_order_view.xml | 16 ++ view/frontend/requirejs-config.js | 6 + .../web/js/action/checkout/cart/totals.js | 71 +++++++ .../action/payment/select-payment-method.js | 21 ++ .../web/js/view/cart/summary/moip_interest.js | 64 ++++++ .../web/js/view/cart/totals/moip_interest.js | 25 +++ .../checkout/cart/totals/moip_interest.js | 23 +++ .../js/view/checkout/summary/moip_interest.js | 64 ++++++ .../method-renderer/moip_magento2_cc.js | 169 +++++++++------- .../js/view/payment/method-renderer/vault.js | 176 +++++++++------- .../template/cart/summary/moip_interest.html | 17 ++ .../template/cart/totals/moip_interest.html | 15 ++ .../checkout/cart/totals/moip_interest.html | 15 ++ .../checkout/summary/moip_interest.html | 18 ++ .../frontend/web/template/payment/boleto.html | 6 +- .../web/template/payment/vault-form.html | 3 +- 81 files changed, 2760 insertions(+), 259 deletions(-) create mode 100644 Api/Data/MoipInterestInterface.php create mode 100644 Api/GuestMoipInterestManagementInterface.php create mode 100644 Api/MoipInterestManagementInterface.php create mode 100644 Block/Adminhtml/Sales/Order/Creditmemo/Totals.php create mode 100644 Block/Adminhtml/Sales/Order/Invoice/Totals.php create mode 100644 Block/Adminhtml/Sales/Order/Totals.php create mode 100644 Block/Adminhtml/System/Config/Category.php create mode 100644 Block/Sales/Totals.php create mode 100644 Model/Data/MoipInterest.php create mode 100644 Model/GuestMoipInterestManagement.php create mode 100644 Model/MoipInterestManagement.php create mode 100644 Model/Order/Total/Creditmemo/MoipInterest.php create mode 100644 Model/Order/Total/Invoice/MoipInterest.php create mode 100644 Model/Quote/Address/Total/MoipInterest.php create mode 100644 Observer/AddMoipInterestToOrderObserver.php create mode 100644 etc/db_schema.xml create mode 100644 etc/db_schema_whitelist.json create mode 100644 etc/extension_attributes.xml create mode 100644 etc/fieldset.xml create mode 100644 etc/pdf.xml create mode 100644 etc/sales.xml create mode 100644 etc/webapi.xml create mode 100644 view/adminhtml/layout/sales_order_creditmemo_updateqty.xml create mode 100644 view/adminhtml/layout/sales_order_creditmemo_view.xml create mode 100644 view/adminhtml/layout/sales_order_invoice_new.xml create mode 100644 view/adminhtml/layout/sales_order_invoice_updateqty.xml create mode 100644 view/adminhtml/layout/sales_order_invoice_view.xml create mode 100644 view/adminhtml/layout/sales_order_view.xml create mode 100644 view/frontend/layout/checkout_cart_index.xml create mode 100644 view/frontend/layout/sales_email_order_creditmemo_items.xml create mode 100644 view/frontend/layout/sales_email_order_invoice_items.xml create mode 100644 view/frontend/layout/sales_email_order_items.xml create mode 100644 view/frontend/layout/sales_guest_invoice.xml create mode 100644 view/frontend/layout/sales_guest_print.xml create mode 100644 view/frontend/layout/sales_guest_printinvoice.xml create mode 100644 view/frontend/layout/sales_guest_view.xml create mode 100644 view/frontend/layout/sales_order_creditmemo.xml create mode 100644 view/frontend/layout/sales_order_invoice.xml create mode 100644 view/frontend/layout/sales_order_print.xml create mode 100644 view/frontend/layout/sales_order_view.xml create mode 100644 view/frontend/web/js/action/checkout/cart/totals.js create mode 100644 view/frontend/web/js/action/payment/select-payment-method.js create mode 100644 view/frontend/web/js/view/cart/summary/moip_interest.js create mode 100644 view/frontend/web/js/view/cart/totals/moip_interest.js create mode 100644 view/frontend/web/js/view/checkout/cart/totals/moip_interest.js create mode 100644 view/frontend/web/js/view/checkout/summary/moip_interest.js create mode 100644 view/frontend/web/template/cart/summary/moip_interest.html create mode 100644 view/frontend/web/template/cart/totals/moip_interest.html create mode 100644 view/frontend/web/template/checkout/cart/totals/moip_interest.html create mode 100644 view/frontend/web/template/checkout/summary/moip_interest.html diff --git a/Api/Data/MoipInterestInterface.php b/Api/Data/MoipInterestInterface.php new file mode 100644 index 0000000..508d085 --- /dev/null +++ b/Api/Data/MoipInterestInterface.php @@ -0,0 +1,43 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Api\Data; + +/** + * Interface MoipInterestInterface - Data Moip Interest. + */ +interface MoipInterestInterface +{ + /** + * @var string + */ + const MOIP_INTEREST_AMOUNT = 'moip_interest_amount'; + + /** + * @var string + */ + const BASE_MOIP_INTEREST_AMOUNT = 'base_moip_interest_amount'; + + /** + * Get Installment for Moip Interest. + * + * @return float + */ + public function getInstallmentForInterest(); + + /** + * Set Installment for Moip Interest. + * + * @param float $moipInterest + * + * @return void + */ + public function setInstallmentForInterest($moipInterest); +} diff --git a/Api/GuestMoipInterestManagementInterface.php b/Api/GuestMoipInterestManagementInterface.php new file mode 100644 index 0000000..26915a1 --- /dev/null +++ b/Api/GuestMoipInterestManagementInterface.php @@ -0,0 +1,32 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Api; + +/** + * Interface for saving the checkout moip interest to the quote for orders. + * + * @api + */ +interface GuestMoipInterestManagementInterface +{ + /** + * Set in the moip interest amount per installment number. + * + * @param string $cartId + * @param \Moip\Magento2\Api\Data\MoipInterestInterface $installment + * + * @return string + */ + public function saveMoipInterest( + $cartId, + \Moip\Magento2\Api\Data\MoipInterestInterface $installment + ); +} diff --git a/Api/MoipInterestManagementInterface.php b/Api/MoipInterestManagementInterface.php new file mode 100644 index 0000000..e025f50 --- /dev/null +++ b/Api/MoipInterestManagementInterface.php @@ -0,0 +1,32 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Api; + +/** + * Interface for saving the checkout moip interest to the quote for orders. + * + * @api + */ +interface MoipInterestManagementInterface +{ + /** + * Set in the moip interest amount per installment number. + * + * @param int $cartId + * @param \Moip\Magento2\Api\Data\MoipInterestInterface $installment + * + * @return string + */ + public function saveMoipInterest( + $cartId, + \Moip\Magento2\Api\Data\MoipInterestInterface $installment + ); +} diff --git a/Block/Adminhtml/Sales/Order/Creditmemo/Totals.php b/Block/Adminhtml/Sales/Order/Creditmemo/Totals.php new file mode 100644 index 0000000..89f6a5d --- /dev/null +++ b/Block/Adminhtml/Sales/Order/Creditmemo/Totals.php @@ -0,0 +1,69 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Block\Adminhtml\Sales\Order\Creditmemo; + +use Magento\Framework\DataObject; +use Magento\Framework\View\Element\Template; + +/** + * Class Totals - Creditmemo. + */ +class Totals extends Template +{ + /** + * Get data (totals) source model. + * + * @return DataObject + */ + public function getSource() + { + return $this->getParentBlock()->getSource(); + } + + /** + * Get Creditmemo. + * + * @return creditmemo + */ + public function getCreditmemo() + { + return $this->getParentBlock()->getCreditmemo(); + } + + /** + * Initialize payment moip_interest totals. + * + * @return $this + */ + public function initTotals() + { + $this->getParentBlock(); + $this->getCreditmemo(); + $this->getSource(); + + if (!$this->getSource()->getMoipInterestAmount()) { + return $this; + } + + $moip_interest = new DataObject( + [ + 'code' => 'moip_interest', + 'strong' => false, + 'value' => $this->getSource()->getMoipInterestAmount(), + 'label' => __('Moip Interest Amount'), + ] + ); + + $this->getParentBlock()->addTotalBefore($moip_interest, 'grand_total'); + + return $this; + } +} diff --git a/Block/Adminhtml/Sales/Order/Invoice/Totals.php b/Block/Adminhtml/Sales/Order/Invoice/Totals.php new file mode 100644 index 0000000..bdac3b0 --- /dev/null +++ b/Block/Adminhtml/Sales/Order/Invoice/Totals.php @@ -0,0 +1,68 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Block\Adminhtml\Sales\Order\Invoice; + +use Magento\Framework\DataObject; +use Magento\Framework\View\Element\Template; + +/** + * Class Totals - Invoice. + */ +class Totals extends Template +{ + /** + * Get data (totals) source model. + * + * @return DataObject + */ + public function getSource() + { + return $this->getParentBlock()->getSource(); + } + + /** + * Get Invoice data. + * + * @return invoice + */ + public function getInvoice() + { + return $this->getParentBlock()->getInvoice(); + } + + /** + * Initialize payment moip_interest totals. + * + * @return $this + */ + public function initTotals() + { + $this->getParentBlock(); + $this->getInvoice(); + $this->getSource(); + + if (!$this->getSource()->getMoipInterestAmount()) { + return $this; + } + + $total = new DataObject( + [ + 'code' => 'moip_interest', + 'value' => $this->getSource()->getMoipInterestAmount(), + 'label' => __('Moip Interest Amount'), + ] + ); + + $this->getParentBlock()->addTotalBefore($total, 'grand_total'); + + return $this; + } +} diff --git a/Block/Adminhtml/Sales/Order/Totals.php b/Block/Adminhtml/Sales/Order/Totals.php new file mode 100644 index 0000000..81b7aac --- /dev/null +++ b/Block/Adminhtml/Sales/Order/Totals.php @@ -0,0 +1,64 @@ + + * See COPYING.txt for license details. + */ + +namespace Moip\Magento2\Block\Adminhtml\Sales\Order; + +use Magento\Framework\DataObject; +use Magento\Framework\View\Element\Template; +use Magento\Sales\Model\Order; + +/** + * Class Totals - Invoice. + */ +class Totals extends Template +{ + /** + * Retrieve current order model instance. + * + * @return Order + */ + public function getOrder() + { + return $this->getParentBlock()->getOrder(); + } + + /** + * Get Source. + * + * @return source + */ + public function getSource() + { + return $this->getParentBlock()->getSource(); + } + + /** + * @return $this + */ + public function initTotals() + { + $this->getParentBlock(); + $this->getOrder(); + $this->getSource(); + + if (!$this->getSource()->getMoipInterestAmount() || (int) $this->getSource()->getMoipInterestAmount() === 0) { + return $this; + } + + $total = new DataObject( + [ + 'code' => 'moip_interest', + 'value' => $this->getSource()->getMoipInterestAmount(), + 'label' => __('Moip Interest Amount'), + ] + ); + $this->getParentBlock()->addTotalBefore($total, 'grand_total'); + + return $this; + } +} diff --git a/Block/Adminhtml/System/Config/Category.php b/Block/Adminhtml/System/Config/Category.php new file mode 100644 index 0000000..9a005a4 --- /dev/null +++ b/Block/Adminhtml/System/Config/Category.php @@ -0,0 +1,115 @@ + + * See COPYING.txt for license details. + */ + +namespace Moip\Magento2\Block\Adminhtml\System\Config; + +/** + * Class Category - Defines Category types. + */ +class Category implements \Magento\Framework\Option\ArrayInterface +{ + /** + * Returns Options. + * + * @return array attributesArrays + */ + public function toOptionArray() + { + return [ + null => __('Select the store segment.'), + 'ANIMALS_AND_PET_SUPPLIES' => __('Animals and Pet Supplies'), + 'APPAREL_AND_ACCESSORIES' => __('Apparel and Accessories'), + 'CLOTHING' => __('Apparel and Accessories > Clothing'), + 'CLOTHING_ACCESSORIES' => __('Apparel and Accessories > Clothing Accessories'), + 'COSTUMES_AND_ACCESSORIES' => __('Apparel and Accessories > Costumes and Accessories'), + 'HANDBAGS_AND_WALLET_ACCESSORIES' => __('Apparel and Accessories > Handbags and Wallet Accessories'), + 'HANDBAGS_WALLETS_AND_CASES' => __('Apparel and Accessories > Handbags and Wallet Accessories'), + 'JEWELRY' => __('Apparel and Accessories > Jewelry'), + 'SHOE_ACCESSORIES' => __('Apparel and Accessories > Shoe Accessories'), + 'SHOES' => __('Apparel and Accessories > Shoes'), + 'OTHER_APPAREL' => __('Apparel and Accessories > Other'), + 'ARTS_AND_ENTERTAINMENT' => __('Arts and Entertainment'), + 'BABY_AND_TODDLER' => __('Baby and Toddler'), + 'BUSINESS_AND_INDUSTRIAL' => __('Business and Industrial'), + 'ADVERTISING_AND_MARKETING' => __('Business and Industrial > Advertising and Marketing'), + 'AGRICULTURE' => __('Business and Industrial > Agriculture'), + 'CONSTRUCTION' => __('Business and Industrial > Construction'), + 'FILM_AND_TELEVISION' => __('Business and Industrial > Film and Television'), + 'FINANCE_AND_INSURANCE' => __('Business and Industrial > Finance and Insurance'), + 'FOOD_SERVICE' => __('Business and Industrial > Food Service'), + 'FORESTRY_AND_LOGGING' => __('Business and Industrial > Forestry and Logging'), + 'HEAVY_MACHINERY' => __('Business and Industrial > Heavy Machinery'), + 'HOTEL_AND_HOSPITALITY' => __('Business and Industrial > Hotel and Hospitality'), + 'INDUSTRIAL_STORAGE' => __('Business and Industrial > Industrial Storage'), + 'LAW_ENFORCEMENT' => __('Business and Industrial > Law Enforcement'), + 'MANUFACTURING' => __('Business and Industrial > Manufacturing'), + 'MATERIAL_HANDLING' => __('Business and Industrial > Material Handling'), + 'MEDICAL' => __('Business and Industrial > Medical'), + 'MINING_AND_QUARRYING' => __('Business and Industrial > Mining and Quarrying'), + 'PIERCING_AND_TATTOOING' => __('Business and Industrial > Piercing and Tattooing'), + 'RETAIL' => __('Business and Industrial > Retail'), + 'SCIENCE_AND_LABORATORY' => __('Business and Industrial > Science and Laboratory'), + 'SIGNAGE' => __('Business and Industrial > Signage'), + 'WORK_SAFETY_PROTECTIVE_GEAR' => __('Business and Industrial > Work Safety Protective Gear'), + 'OTHER_BUSINESSES' => __('Business and Industrial > Other Businesses'), + 'CAMERA_AND_OPTIC_ACCESSORIES' => __('Camera and Optic Accessories'), + 'CAMERAS' => __('Camera and Optic Accessories > Cameras'), + 'CAMERA_ACESSORIES' => __('Camera and Optic Accessories > Camera Acessories'), + 'PHOTOGRAPHY' => __('Camera and Optic Accessories > Photography'), + 'OTHERS_CAMERAS_ACCESSORIES' => __('Camera and Optic Accessories > Others Cameras Accessories'), + 'ELECTRONICS' => __('Electronics'), + '3D_PRINTERS' => __('Electronics > 3d Printers'), + 'AUDIO' => __('Electronics > Audio'), + 'CIRCUIT_BOARDS_AND_COMPONENTS' => __('Electronics > Circuit Boards and Components'), + 'COMMUNICATIONS' => __('Electronics > Communications'), + 'COMPONENTS' => __('Electronics > Components'), + 'COMPUTERS' => __('Electronics > Computers'), + 'ELECTRONICS_ACCESSORIES' => __('Electronics > Electronics Accessories'), + 'GPS_NAVIGATION_SYSTEMS' => __('Electronics > Gps Navigation Systems'), + 'GPS_ACCESSORIES' => __('Electronics > Gps Accessories'), + 'NETWORKING' => __('Electronics > Networking'), + 'PRINT_COPY_SCAN_AND_FAX' => __('Electronics > Print Copy Scan and Fax'), + 'PRINTER_COPIER_AND_FAX_MACHINE_ACCESSORIES' => __('Electronics > Printer Copier and Fax Machine Accessories'), + 'VIDEO' => __('Electronics > Video'), + 'VIDEO_GAME_CONSOLES' => __('Electronics > Video Game Consoles'), + 'VIDEO_GAME_CONSOLE_ACCESSORIES' => __('Electronics > Video Game Console Accessories'), + 'OTHER_ELECTRONICS' => __('Electronics > Other Electronics'), + 'FOOD_BEVERAGES_AND_TOBACCO' => __('Food Beverages and Tobacco'), + 'FURNITURE' => __('Furniture'), + 'TOOL_ACCESSORIES' => __('Tool Accessories'), + 'HEALTH_AND_BEAUTY' => __('Health and Beauty'), + 'PERFUME_AND_COLOGNE' => __('Health and Beauty > Perfume and Cologne'), + 'MAKEUP' => __('Health and Beauty > Makeup'), + 'BATH_AND_BODY' => __('Health and Beauty > Bath and Body'), + 'COSMETIC_TOOLS' => __('Health and Beauty > Cosmetic Tools'), + 'LUGGAGE_AND_BAGS' => __('Luggage and Bags'), + 'ADULT' => __('Adult'), + 'WEAPONS_AND_AMMUNITION' => __('Weapons and Ammunition'), + 'OFFICE_SUPPLIES' => __('Office Supplies'), + 'RELIGIOUS_AND_CEREMONIAL' => __('Religious and Ceremonial'), + 'SOFTWARE' => __('Software'), + 'COMPUTER_SOFTWARE' => __('Software > Computer Software'), + 'DIGITAL_GOODS_AND_CURRENCY' => __('Software > Digital Goods and Currency'), + 'DIGITAL_SERVICES' => __('Software > Digital Services'), + 'VIDEO_GAME_SOFTWARE' => __('Software > Video Game Software'), + 'OTHER_SOFTWARES' => __('Software > Other Softwares'), + 'SPORTING_GOODS' => __('Sporting Goods'), + 'TOYS_AND_GAMES' => __('Toys and Games'), + 'VEHICLES_AND_PARTS' => __('Vehicles and Parts'), + 'BOOKS' => __('Books'), + 'DVDS_AND_VIDEOS' => __('Dvds and Videos'), + 'MAGAZINES_AND_NEWSPAPERS' => __('Magazines and Newspapers'), + 'MUSIC' => __('Music'), + 'CDS_AND_LPS' => __('Music > Cds and Lps'), + 'MUSICAL_INSTRUMENTS' => __('Music > Musical Instruments'), + 'DIGITAL_MUSIC' => __('Music > Digital Music'), + 'OTHER_MUSIC_ITEMS' => __('Music > Other Music Items'), + 'OTHER_CATEGORIES' => __('Music > Other Categories'), + ]; + } +} diff --git a/Block/FormCc.php b/Block/FormCc.php index 202b3d4..31fe811 100755 --- a/Block/FormCc.php +++ b/Block/FormCc.php @@ -122,27 +122,23 @@ public function getKeyPublic() /** * Installments - Cc. * + * @param float $amount + * * @var string */ - public function getInstallments($ammount) + public function getInstallments($amount) { $typeInstallment = $this->configCc->getTypeInstallment(); $limitByInstallment = $this->configCc->getMaxInstallment(); $limitInstallmentValue = $this->configCc->getMinInstallment(); $interestByInstallment = $this->configCc->getInfoInterest(); - + $plotlist = []; foreach ($interestByInstallment as $key => $_interest) { - if ($key > 1 && $key <= $limitByInstallment) { - $plotValue = $this->getInterestCompound($ammount, $_interest, $key); - + if ($key > 0) { + $plotValue = $this->getInterestCompound($amount, $_interest, $key); if ($typeInstallment === 'simple') { - $plotValue = $this->getInterestSimple($ammount, $_interest, $key); + $plotValue = $this->getInterestSimple($amount, $_interest, $key); } - - if ($plotValue < $limitInstallmentValue) { - break; - } - $plotValue = number_format((float) $plotValue, 2, '.', ''); $installmentPrice = $this->priceHelper->currency($plotValue, true, false); $plotlist[$key] = $key.__('x of ').$installmentPrice; @@ -166,7 +162,7 @@ public function getInterestSimple($total, $interest, $portion) return ($total + $valinterest) / $portion; } - return 0; + return $total / $portion; } /** diff --git a/Block/Sales/Totals.php b/Block/Sales/Totals.php new file mode 100644 index 0000000..ecfc9f4 --- /dev/null +++ b/Block/Sales/Totals.php @@ -0,0 +1,114 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Block\Sales; + +use Magento\Framework\DataObject; +use Magento\Framework\View\Element\Template; +use Magento\Sales\Model\Order; + +/** + * Class Totals - Template. + */ +class Totals extends Template +{ + /** + * @var Order + */ + protected $_order; + + /** + * @var DataObject + */ + protected $_source; + + /** + * @return bool + */ + public function displayFullSummary() + { + return true; + } + + /** + * Get data (totals) source model. + * + * @return DataObject + */ + public function getSource() + { + return $this->_source; + } + + /** + * @return store + */ + public function getStore() + { + return $this->_order->getStore(); + } + + /** + * @return Order + */ + public function getOrder() + { + return $this->_order; + } + + /** + * Initialize payment moip_interest totals. + * + * @return $this + */ + public function initTotals() + { + $parent = $this->getParentBlock(); + $this->_order = $parent->getOrder(); + $this->_source = $parent->getSource(); + + if (!$this->_source->getMoipInterestAmount() || (int) $this->_source->getMoipInterestAmount() === 0) { + return $this; + } + + $valueInterest = $this->_source->getMoipInterestAmount(); + $label = $this->getLabelByInterest($valueInterest); + $moipInterest = new DataObject( + [ + 'code' => 'moip_interest', + 'strong' => false, + 'value' => $valueInterest, + 'label' => $label, + ] + ); + + if ((int) $valueInterest !== 0.0000) { + $parent->addTotal($moipInterest, 'moip_interest'); + } + + return $this; + } + + /** + * Get Subtotal label by Interest. + * + * @param $interest | float + * + * @return Phrase + */ + public function getLabelByInterest($interest) + { + if ($interest >= 0) { + return __('Installment Interest'); + } + + return __('Discount Cash'); + } +} diff --git a/Controller/Webhooks/Deny.php b/Controller/Webhooks/Deny.php index bbe2bc8..946bc24 100755 --- a/Controller/Webhooks/Deny.php +++ b/Controller/Webhooks/Deny.php @@ -129,12 +129,12 @@ public function __construct( */ public function execute() { - // if (!$this->getRequest()->isPost()) { - // $resultPage = $this->resultJsonFactory->create(); - // $resultPage->setHttpResponseCode(404); + if (!$this->getRequest()->isPost()) { + $resultPage = $this->resultJsonFactory->create(); + $resultPage->setHttpResponseCode(404); - // return $resultPage; - // } + return $resultPage; + } $resultPage = $this->resultJsonFactory->create(); $response = $this->getRequest()->getContent(); diff --git a/Gateway/Config/Config.php b/Gateway/Config/Config.php index 56b2799..35c7292 100755 --- a/Gateway/Config/Config.php +++ b/Gateway/Config/Config.php @@ -506,4 +506,20 @@ public function getSplitValue($field, $storeId = null): string $storeId ); } + + /** + * Gets the Moip Category. + * + * @param int|null $storeId + * + * @return string + */ + public function getMoipCategory($storeId = null): ?string + { + return $this->scopeConfig->getValue( + 'payment/moip_magento2/category', + ScopeInterface::SCOPE_STORE, + $storeId + ); + } } diff --git a/Gateway/Config/ConfigCc.php b/Gateway/Config/ConfigCc.php index f891219..673890c 100755 --- a/Gateway/Config/ConfigCc.php +++ b/Gateway/Config/ConfigCc.php @@ -238,7 +238,11 @@ public function getInfoInterest($storeId = null) { $juros = []; $juros['0'] = 0; - $juros['1'] = 0; + $juros['1'] = -$this->scopeConfig->getValue( + 'payment/moip_magento2_cc/installment_installment_1', + ScopeInterface::SCOPE_STORE, + $storeId + ); $juros['2'] = $this->scopeConfig->getValue( 'payment/moip_magento2_cc/installment_installment_2', ScopeInterface::SCOPE_STORE, diff --git a/Gateway/Data/Order/AddressAdapter.php b/Gateway/Data/Order/AddressAdapter.php index a40f174..f15dff1 100755 --- a/Gateway/Data/Order/AddressAdapter.php +++ b/Gateway/Data/Order/AddressAdapter.php @@ -94,7 +94,7 @@ public function getStreetLine4() { $street = $this->address->getStreet(); - return isset($street[4]) ? $street[4] : ''; + return isset($street[3]) ? $street[3] : ''; } /** diff --git a/Gateway/Data/Order/OrderAdapter.php b/Gateway/Data/Order/OrderAdapter.php index 08fb19f..1f312fc 100755 --- a/Gateway/Data/Order/OrderAdapter.php +++ b/Gateway/Data/Order/OrderAdapter.php @@ -202,4 +202,44 @@ public function getTaxAmount() { return $this->order->getTaxAmount(); } + + /** + * Returns order base moip interest amount. + * + * @return float|null + */ + public function getBaseMoipInterestAmount() + { + return $this->order->getBaseMoipInterestAmount(); + } + + /** + * Returns order quote id. + * + * @return float|null + */ + public function getQuoteId() + { + return $this->order->getQuoteId(); + } + + /** + * Set order moip interest amount. + * + * @return float|null + */ + public function setMoipInterestAmount($interest) + { + return $this->order->setMoipInterestAmount($interest); + } + + /** + * Set order base moip interest amount. + * + * @return float|null + */ + public function setBaseMoipInterestAmount($interest) + { + return $this->order->setBaseMoipInterestAmount($interest); + } } diff --git a/Gateway/Request/AddressDataRequest.php b/Gateway/Request/AddressDataRequest.php index cc9a53b..ace3df6 100755 --- a/Gateway/Request/AddressDataRequest.php +++ b/Gateway/Request/AddressDataRequest.php @@ -118,26 +118,36 @@ public function getValueForAddress($adress, $field) { $value = (int) $this->config->getAddtionalValue($field); + if ($field === self::STREET) { + $limitSend = 57; + } elseif ($field === self::STREET_NUMBER) { + $limitSend = 6; + } elseif ($field === self::STREET_DISTRICT) { + $limitSend = 60; + } elseif ($field === self::STREET_COMPLEMENT) { + $limitSend = 30; + } + if ($value === 0) { - return $adress->getStreetLine1(); + return substr($adress->getStreetLine1(), 0, $limitSend); } elseif ($value === 1) { - return $adress->getStreetLine2(); + return substr($adress->getStreetLine2(), 0, $limitSend); } elseif ($value === 2) { - return $adress->getStreetLine3(); + return substr($adress->getStreetLine3(), 0, $limitSend); } elseif ($value === 3) { /** contigência para sempre haver o bairro */ - if ($adress->getStreetLine3()) { - return $adress->getStreetLine3(); - } if ($adress->getStreetLine4()) { - return $adress->getStreetLine4(); + return substr($adress->getStreetLine4(), 0, $limitSend); + } + if ($adress->getStreetLine3()) { + return substr($adress->getStreetLine3(), 0, $limitSend); } if ($adress->getStreetLine1()) { - return $adress->getStreetLine1(); + return substr($adress->getStreetLine1(), 0, $limitSend); } } - return $adress->getStreetLine1(); + return substr($adress->getStreetLine1(), 0, $limitSend); } /** diff --git a/Gateway/Request/BillingAddressDataRequest.php b/Gateway/Request/BillingAddressDataRequest.php index 18281ea..33b930c 100755 --- a/Gateway/Request/BillingAddressDataRequest.php +++ b/Gateway/Request/BillingAddressDataRequest.php @@ -113,28 +113,36 @@ public function getValueForAddress($adress, $field) { $value = (int) $this->config->getAddtionalValue($field); + if ($field === self::STREET) { + $limitSend = 57; + } elseif ($field === self::STREET_NUMBER) { + $limitSend = 6; + } elseif ($field === self::STREET_DISTRICT) { + $limitSend = 60; + } elseif ($field === self::STREET_COMPLEMENT) { + $limitSend = 30; + } + if ($value === 0) { - return $adress->getStreetLine1(); + return substr($adress->getStreetLine1(), 0, $limitSend); } elseif ($value === 1) { - return $adress->getStreetLine2(); + return substr($adress->getStreetLine2(), 0, $limitSend); } elseif ($value === 2) { + return substr($adress->getStreetLine3(), 0, $limitSend); + } elseif ($value === 3) { /** contigência para sempre haver o bairro */ - if ($adress->getStreetLine3()) { - return $adress->getStreetLine3(); - } if ($adress->getStreetLine4()) { - return $adress->getStreetLine4(); + return substr($adress->getStreetLine4(), 0, $limitSend); } - if ($adress->getStreetLine1()) { - return $adress->getStreetLine1(); + if ($adress->getStreetLine3()) { + return substr($adress->getStreetLine3(), 0, $limitSend); } - } elseif ($value === 3) { - if ($adress->getStreetLine4()) { - return $adress->getStreetLine4(); + if ($adress->getStreetLine1()) { + return substr($adress->getStreetLine1(), 0, $limitSend); } } - return $adress->getStreetLine1(); + return substr($adress->getStreetLine1(), 0, $limitSend); } /** diff --git a/Gateway/Request/DetailTotalsDataRequest.php b/Gateway/Request/DetailTotalsDataRequest.php index 84516dc..cd08a33 100755 --- a/Gateway/Request/DetailTotalsDataRequest.php +++ b/Gateway/Request/DetailTotalsDataRequest.php @@ -123,38 +123,68 @@ public function build(array $buildSubject) ); $order = $paymentDO->getOrder(); - + // $quoteId = $orderAdapter->getQuoteId(); $storeId = $order->getStoreId(); $addition = $orderAdapter->getTaxAmount(); - $total = $order->getGrandTotalAmount(); + $interest = $orderAdapter->getBaseMoipInterestAmount(); + $grandTotal = $order->getGrandTotalAmount(); + $total = $grandTotal + $interest; + if ($interest > 0) { + $total = $grandTotal - $interest; + } + + $discount = $orderAdapter->getDiscountAmount(); if ($payment->getMethod() === 'moip_magento2_cc' || $payment->getMethod() === 'moip_magento2_cc_vault') { if ($installment = $payment->getAdditionalInformation('cc_installments')) { + // $this->moipInterest->saveMoipInterest($quoteId, (int)$installment); + $interestInfo = $this->configCc->getInfoInterest($storeId); if ($installment > 1) { $typeInstallment = $this->configCc->getTypeInstallment($storeId); - $interest = $this->configCc->getInfoInterest($storeId); - $installmentInterest = $this->getInterestCompound($total, $interest[$installment], $installment); - if ($typeInstallment === 'simple') { - $installmentInterest = $this->getInterestSimple($total, $interest[$installment], $installment); + if ($interestInfo[$installment] > 0) { + $installmentInterest = $this->getInterestCompound($total, $interestInfo[$installment], $installment); + if ($typeInstallment === 'simple') { + $installmentInterest = $this->getInterestSimple($total, $interestInfo[$installment], $installment); + } + + if ($installmentInterest) { + $installmentInterest = number_format((float) $installmentInterest, 2, '.', ''); + $payment->setAdditionalInformation( + self::INSTALLMENT_INTEREST, + $this->priceHelper->currency($installmentInterest, true, false) + ); + if (!$interest) { + $orderAdapter->setMoipInterestAmount($installmentInterest)->setBaseMoipInterestAmount($installmentInterest); + } + $addition = $addition + $installmentInterest; + } } - if ($installmentInterest) { - $total_parcelado = $installmentInterest * $installment; - $additionalPrice = $total_parcelado - $total; - $additionalPrice = number_format((float) $additionalPrice, 2, '.', ''); + } elseif ((int) $installment === 1) { + if ($interestInfo[$installment] < 0) { + $totalWithDiscount = $grandTotal + ($interest * -1); + $discountInterest = $this->getInterestDiscount($totalWithDiscount, $interestInfo[$installment]); + $discountInterest = number_format((float) $discountInterest, 2, '.', ''); + $payment->setAdditionalInformation( self::INSTALLMENT_INTEREST, - $this->priceHelper->currency($additionalPrice, true, false) + $this->priceHelper->currency($discountInterest, true, false) ); - $addition = $addition + $additionalPrice; + if (!$interest) { + $orderAdapter->setMoipInterestAmount($discountInterest)->setBaseMoipInterestAmount($discountInterest); + } + $interest = $discountInterest; } } } } - $total = $total - $orderAdapter->getShippingAmount(); - $discount = -1 * $orderAdapter->getDiscountAmount(); + + if ($interest < 0) { + $discount = $discount + $interest; + } + $discount = $discount * -1; $result[self::TOTALS_AMOUNT] = [ self::TOTALS_AMOUNT_CURRENCY => $order->getCurrencyCode(), - self::TOTALS_AMOUNT_GRAND_TOTAL => ceil($this->config->formatPrice($total)), + self::TOTALS_AMOUNT_GRAND_TOTAL => ceil($this->config->formatPrice($grandTotal)), self::TOTALS_AMOUNT_SUBTOTALS => [ self::TOTALS_AMOUNT_SUBTOTALS_SHIPPING => ceil($this->config->formatPrice( $orderAdapter->getShippingAmount() @@ -168,21 +198,39 @@ public function build(array $buildSubject) } /** - * Get Intereset for Simple. + * Get Intereset Discount. * * @param $total * @param $interest - * @param $portion * * @return string */ - public function getInterestSimple($total, $interest, $portion) + public function getInterestDiscount($total, $interest) { if ($interest) { $taxa = $interest / 100; $valinterest = $total * $taxa; - return ($total + $valinterest) / $portion; + return $valinterest; + } + + return 0; + } + + /** + * Get Intereset for Simple. + * + * @param $total + * @param $interest + * + * @return float + */ + public function getInterestSimple($total, $interest) + { + if ($interest) { + $taxa = $interest / 100; + + return $total * $taxa; } return 0; @@ -195,14 +243,15 @@ public function getInterestSimple($total, $interest, $portion) * @param $interest * @param $portion * - * @return string + * @return float */ public function getInterestCompound($total, $interest, $portion) { if ($interest) { $taxa = $interest / 100; + $calc = (($total * $taxa) * 1) / (1 - (pow(1 / (1 + $taxa), $portion))); - return (($total * $taxa) * 1) / (1 - (pow(1 / (1 + $taxa), $portion))); + return $total - $calc; } return 0; diff --git a/Gateway/Request/DeviceDataRequest.php b/Gateway/Request/DeviceDataRequest.php index 9face00..094735c 100755 --- a/Gateway/Request/DeviceDataRequest.php +++ b/Gateway/Request/DeviceDataRequest.php @@ -77,7 +77,7 @@ public function build(array $buildSubject) $order = $payment->getOrder(); $ipCustomer = $order->getXForwardedFor(); } - $result[self::DEVICE_DATA] = [ + $result[PaymentDataRequest::PAYMENT_INSTRUMENT][self::DEVICE_DATA] = [ self::REMOTE_IP => $ipCustomer, self::REMOTE_USER_AGENT => $this->headerClient->getHttpUserAgent(), ]; @@ -86,7 +86,7 @@ public function build(array $buildSubject) $paymentInfo->setAdditionalInformation( self::DEVICE_DATA, - $result[self::DEVICE_DATA] + $result[PaymentDataRequest::PAYMENT_INSTRUMENT][self::DEVICE_DATA] ); return $result; diff --git a/Gateway/Request/PurchasedItemsDataRequest.php b/Gateway/Request/PurchasedItemsDataRequest.php index 185b672..f4bf5df 100755 --- a/Gateway/Request/PurchasedItemsDataRequest.php +++ b/Gateway/Request/PurchasedItemsDataRequest.php @@ -46,6 +46,12 @@ class PurchasedItemsDataRequest implements BuilderInterface */ const PURCHASED_ITEM_PRICE = 'price'; + /** + * The Category Moip + * Optional. + */ + const PURCHASED_ITEM_CATEGORY = 'category'; + /** * @var SubjectReader */ @@ -77,6 +83,7 @@ public function build(array $buildSubject) $result = []; $order = $paymentDO->getOrder(); + $storeId = $order->getStoreId(); $items = $order->getItems(); $itemcount = count($items); if ($itemcount) { @@ -93,6 +100,7 @@ public function build(array $buildSubject) self::PURCHASED_ITEM_QUANTITY => $item->getQtyOrdered(), self::PURCHASED_ITEM_DETAIL => $item->getSku(), self::PURCHASED_ITEM_PRICE => $this->config->formatPrice($item->getPrice()), + self::PURCHASED_ITEM_CATEGORY => $this->config->getMoipCategory($storeId), ]; } } diff --git a/Gateway/Request/SellerDataRequest.php b/Gateway/Request/SellerDataRequest.php index 8128344..a3b7ddf 100644 --- a/Gateway/Request/SellerDataRequest.php +++ b/Gateway/Request/SellerDataRequest.php @@ -130,41 +130,56 @@ public function build(array $buildSubject) } $addition = $orderAdapter->getTaxAmount(); - $total = $order->getGrandTotalAmount(); + $interest = $orderAdapter->getBaseMoipInterestAmount(); + $grandTotal = $order->getGrandTotalAmount(); + $discount = $orderAdapter->getDiscountAmount(); + $total = $grandTotal + $interest; + if ($interest > 0) { + $total = $grandTotal - $interest; + } $secondaryMPA = $this->config->getSplitValue('secondary_mpa', $storeId); $secondaryPercent = $this->config->getSplitValue('secondary_percent', $storeId); $commiUseShipping = $this->config->getSplitValue('secondary_percent_include_shipping', $storeId); $commiUseInterest = $this->config->getSplitValue('secondary_percent_include_interest', $storeId); - if ($commissionUseInterest) { - if ($payment->getMethod() === 'moip_magento2_cc' || $payment->getMethod() === 'moip_magento2_cc_vault') { - if ($installment = $payment->getAdditionalInformation('cc_installments')) { - if ($installment > 1) { - $typeInstallment = $this->configCc->getTypeInstallment($storeId); - $interest = $this->configCc->getInfoInterest($storeId); - $installmentInterest = $this->getInterestCompound( - $total, - $interest[$installment], - $installment - ); + if ($payment->getMethod() === 'moip_magento2_cc' || $payment->getMethod() === 'moip_magento2_cc_vault') { + if ($installment = $payment->getAdditionalInformation('cc_installments')) { + $interestInfo = $this->configCc->getInfoInterest($storeId); + if ($installment > 1) { + $typeInstallment = $this->configCc->getTypeInstallment($storeId); + if ($interestInfo[$installment] > 0) { + $installmentInterest = $this->getInterestCompound($total, $interestInfo[$installment], $installment); if ($typeInstallment === 'simple') { - $installmentInterest = $this->getInterestSimple( - $total, - $interest[$installment], - $installment - ); + $installmentInterest = $this->getInterestSimple($total, $interestInfo[$installment], $installment); } + if ($installmentInterest) { - $total_parcelado = $installmentInterest * $installment; - $additionalPrice = $total_parcelado - $total; - $additionalPrice = number_format((float) $additionalPrice, 2, '.', ''); + $installmentInterest = number_format((float) $installmentInterest, 2, '.', ''); $payment->setAdditionalInformation( self::INSTALLMENT_INTEREST, - $this->priceHelper->currency($additionalPrice, true, false) + $this->priceHelper->currency($installmentInterest, true, false) ); - $addition = $addition + $additionalPrice; + if (!$interest) { + $orderAdapter->setMoipInterestAmount($installmentInterest)->setBaseMoipInterestAmount($installmentInterest); + } + $addition = $addition + $installmentInterest; + } + } + } elseif ((int) $installment === 1) { + if ($interestInfo[$installment] < 0) { + $totalWithDiscount = $grandTotal + ($interest * -1); + $discountInterest = $this->getInterestDiscount($totalWithDiscount, $interestInfo[$installment]); + $discountInterest = number_format((float) $discountInterest, 2, '.', ''); + + $payment->setAdditionalInformation( + self::INSTALLMENT_INTEREST, + $this->priceHelper->currency($discountInterest, true, false) + ); + if (!$interest) { + $orderAdapter->setMoipInterestAmount($discountInterest)->setBaseMoipInterestAmount($discountInterest); } + $interest = $discountInterest; } } } @@ -175,7 +190,11 @@ public function build(array $buildSubject) } if ($commiUseInterest) { - $total = $total + $addition; + if ($interest > 0) { + $total = $total + $addition; + } elseif ($interest < 0) { + $total = $total + $interest; + } } $commission = $total * ($secondaryPercent / 100); @@ -193,6 +212,26 @@ public function build(array $buildSubject) return $result; } + /** + * Get Intereset Discount. + * + * @param $total + * @param $interest + * + * @return string + */ + public function getInterestDiscount($total, $interest) + { + if ($interest) { + $taxa = $interest / 100; + $valinterest = $total * $taxa; + + return $valinterest; + } + + return 0; + } + /** * Get Intereset for Simple. * diff --git a/Model/Data/MoipInterest.php b/Model/Data/MoipInterest.php new file mode 100644 index 0000000..7e94b10 --- /dev/null +++ b/Model/Data/MoipInterest.php @@ -0,0 +1,36 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model\Data; + +use Magento\Framework\Api\AbstractSimpleObject; +use Moip\Magento2\Api\Data\MoipInterestInterface; + +/** + * Class MoipInterest - Model data. + */ +class MoipInterest extends AbstractSimpleObject implements MoipInterestInterface +{ + /** + * @inheritdoc + */ + public function getInstallmentForInterest() + { + return $this->_get(MoipInterestInterface::MOIP_INTEREST_AMOUNT); + } + + /** + * @inheritdoc + */ + public function setInstallmentForInterest($moipInterest) + { + return $this->setData(MoipInterestInterface::MOIP_INTEREST_AMOUNT, $moipInterest); + } +} diff --git a/Model/GuestMoipInterestManagement.php b/Model/GuestMoipInterestManagement.php new file mode 100644 index 0000000..6c9ce10 --- /dev/null +++ b/Model/GuestMoipInterestManagement.php @@ -0,0 +1,61 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model; + +use Magento\Quote\Model\QuoteIdMaskFactory; +use Moip\Magento2\Api\Data\MoipInterestInterface; +use Moip\Magento2\Api\GuestMoipInterestManagementInterface; +use Moip\Magento2\Api\MoipInterestManagementInterface; + +/** + * Class MoipInterestManagement - Calc Insterest by Installment. + */ +class GuestMoipInterestManagement implements GuestMoipInterestManagementInterface +{ + /** + * @var \Magento\Quote\Model\QuoteIdMaskFactory + */ + protected $quoteIdMaskFactory; + + /** + * @var \Magento\Checkout\Api\ShippingInformationManagementInterface + */ + protected $shippingInformationManagement; + + /** + * @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory + * @param \Magento\Checkout\Api\ShippingInformationManagementInterface $shippingInformationManagement + * @codeCoverageIgnore + */ + public function __construct( + QuoteIdMaskFactory $quoteIdMaskFactory, + MoipInterestManagementInterface $moipInterestManagement + ) { + $this->quoteIdMaskFactory = $quoteIdMaskFactory; + $this->moipInterestManagement = $moipInterestManagement; + } + + /** + * {@inheritDoc} + */ + public function saveMoipInterest( + $cartId, + MoipInterestInterface $moipInterest + ) { + /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */ + $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); + + return $this->moipInterestManagement->saveMoipInterest( + $quoteIdMask->getQuoteId(), + $moipInterest + ); + } +} diff --git a/Model/MoipInterestManagement.php b/Model/MoipInterestManagement.php new file mode 100644 index 0000000..ddce0a8 --- /dev/null +++ b/Model/MoipInterestManagement.php @@ -0,0 +1,188 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model; + +use Exception; +use Magento\Directory\Model\PriceCurrency; +use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Quote\Api\Data\CartInterface as QuoteCartInterface; +use Magento\Quote\Api\Data\TotalsInterface as QuoteTotalsInterface; +use Moip\Magento2\Api\Data\MoipInterestInterface; +use Moip\Magento2\Api\MoipInterestManagementInterface; +use Moip\Magento2\Gateway\Config\Config; +use Moip\Magento2\Gateway\Config\ConfigCc; + +/** + * Class MoipInterestManagement - Calc Insterest by Installment. + */ +class MoipInterestManagement implements MoipInterestManagementInterface +{ + /** + * Quote repository. + * + * @var CartRepositoryInterface + */ + protected $quoteRepository; + + /** + * @var PriceCurrency + */ + protected $priceCurrency; + + /** + * @var total + */ + protected $total; + + /** + * @var Config + */ + private $config; + + /** + * @var configCc + */ + private $configCc; + + /** + * MoipInterestManagement constructor. + * + * @param CartRepositoryInterface $quoteRepository + * @param PriceCurrency $priceCurrency, + * @param Config $config, + * @param ConfigCC $configCc + */ + public function __construct( + CartRepositoryInterface $quoteRepository, + PriceCurrency $priceCurrency, + Config $config, + ConfigCc $configCc + ) { + $this->quoteRepository = $quoteRepository; + $this->priceCurrency = $priceCurrency; + $this->config = $config; + $this->configCc = $configCc; + } + + /** + * Save moip interest number in the quote. + * + * @param int $cartId + * @param MoipInterestInterface $moipInterest + * + * @throws CouldNotSaveException + * @throws NoSuchEntityException + * + * @return null|string + */ + public function saveMoipInterest( + $cartId, + MoipInterestInterface $moipInterest + ) { + $moip = []; + $quote = $this->quoteRepository->getActive($cartId); + if (!$quote->getItemsCount()) { + throw new NoSuchEntityException(__('Cart %1 doesn\'t contain products', $cartId)); + } + $installment = $moipInterest->getInstallmentForInterest(); + $moipInterestValue = $this->calcInterest($quote, $installment); + + try { + $quote->setData(MoipInterestInterface::MOIP_INTEREST_AMOUNT, $moipInterestValue); + $quote->setData(MoipInterestInterface::BASE_MOIP_INTEREST_AMOUNT, $moipInterestValue); + $this->quoteRepository->save($quote); + } catch (Exception $e) { + throw new CouldNotSaveException(__('The moip interest # number could not be saved')); + } + + $moip = [ + 'interest_by_installment' => [ + 'installment' => $installment, + 'interest' => $moipInterestValue, + ], + ]; + + return $moip; + } + + /** + * Calc value Interest. + * + * @param $quote + * @param $installment + * + * @return $installmentInterest + */ + public function calcInterest($quote, $installment) + { + $storeId = $quote->getData(QuoteCartInterface::KEY_STORE_ID); + $grandTotal = $quote->getData(QuoteTotalsInterface::KEY_GRAND_TOTAL); + $total = $grandTotal - $quote->getData(MoipInterestInterface::MOIP_INTEREST_AMOUNT); + $installmentInterest = 0; + + if ($installment) { + $typeInstallment = $this->configCc->getTypeInstallment($storeId); + $interest = $this->configCc->getInfoInterest($storeId); + if ($interest[$installment] > 0) { + $installmentInterest = $this->getInterestCompound($total, $interest[$installment], $installment); + if ($typeInstallment === 'simple') { + $installmentInterest = $this->getInterestSimple($total, $interest[$installment], $installment); + } + } elseif ($interest[$installment] < 0) { + $installmentInterest = $this->getInterestSimple($total, $interest[$installment]); + } + } + + return $this->priceCurrency->round($installmentInterest); + } + + /** + * Get Intereset for Simple. + * + * @param $total + * @param $interest + * + * @return float + */ + public function getInterestSimple($total, $interest) + { + if ($interest) { + $taxa = $interest / 100; + + return $total * $taxa; + } + + return 0; + } + + /** + * Get Intereset for Compound. + * + * @param $total + * @param $interest + * @param $portion + * + * @return float + */ + public function getInterestCompound($total, $interest, $portion) + { + if ($interest) { + $taxa = $interest / 100; + $calc = (($total * $taxa) * 1) / (1 - (pow(1 / (1 + $taxa), $portion))); + + return $total - $calc; + } + + return 0; + } +} diff --git a/Model/Order/Total/Creditmemo/MoipInterest.php b/Model/Order/Total/Creditmemo/MoipInterest.php new file mode 100644 index 0000000..308112c --- /dev/null +++ b/Model/Order/Total/Creditmemo/MoipInterest.php @@ -0,0 +1,46 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model\Order\Total\Creditmemo; + +use Magento\Sales\Model\Order\Creditmemo; +use Magento\Sales\Model\Order\Creditmemo\Total\AbstractTotal; + +/** + * Class MoipInterest - Model data Total Creditmemo. + */ +class MoipInterest extends AbstractTotal +{ + /** + * @param Creditmemo $creditmemo + * + * @return $this + */ + public function collect(Creditmemo $creditmemo) + { + $order = $creditmemo->getOrder(); + + $moipInterest = $order->getMoipInterestAmountInvoiced(); + $baseMoipInterest = $order->getBaseMoipInterestAmountInvoiced(); + + if ((int) $moipInterest === 0) { + return $this; + } + + $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $moipInterest); + $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseMoipInterest); + $creditmemo->setMoipInterestAmount($moipInterest); + $creditmemo->setBaseMoipInterestAmount($baseMoipInterest); + $order->setMoipInterestAmountRefunded($moipInterest); + $order->setBaseMoipInterestAmountRefunded($baseMoipInterest); + + return $this; + } +} diff --git a/Model/Order/Total/Invoice/MoipInterest.php b/Model/Order/Total/Invoice/MoipInterest.php new file mode 100644 index 0000000..70015a9 --- /dev/null +++ b/Model/Order/Total/Invoice/MoipInterest.php @@ -0,0 +1,48 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model\Order\Total\Invoice; + +use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Invoice\Total\AbstractTotal; + +/** + * Class MoipInterest - Model data Total Invoice. + */ +class MoipInterest extends AbstractTotal +{ + /** + * Collect invoice subtotal. + * + * @param Invoice $invoice + * + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function collect(Invoice $invoice) + { + $order = $invoice->getOrder(); + $moipInterest = $order->getMoipInterestAmount(); + $baseMoipInterestAmount = $order->getBaseMoipInterestAmount(); + + if ((int) $moipInterest === 0) { + return $this; + } + + $invoice->setMoipInterestAmount($moipInterest); + $invoice->setBaseMoipInterestAmount($baseMoipInterestAmount); + $invoice->setGrandTotal($invoice->getGrandTotal() + $moipInterest); + $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseMoipInterestAmount); + $order->setMoipInterestAmountInvoiced($moipInterest); + $order->setBaseMoipInterestAmountInvoiced($baseMoipInterestAmount); + + return $this; + } +} diff --git a/Model/Quote/Address/Total/MoipInterest.php b/Model/Quote/Address/Total/MoipInterest.php new file mode 100644 index 0000000..921b118 --- /dev/null +++ b/Model/Quote/Address/Total/MoipInterest.php @@ -0,0 +1,151 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Model\Quote\Address\Total; + +use Magento\Checkout\Model\Session; +use Magento\Framework\Phrase; +use Magento\Quote\Api\Data\PaymentInterface; +use Magento\Quote\Api\Data\ShippingAssignmentInterface; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address\Total; +use Magento\Quote\Model\Quote\Address\Total\AbstractTotal; +use Magento\Quote\Model\QuoteValidator; + +/** + * Class MoipInterest - Model data Total Address. + */ +class MoipInterest extends AbstractTotal +{ + /** + * @var string + */ + protected $_code = 'moip_interest_amount'; + + /** + * @var Session + */ + protected $_checkoutSession; + + /** + * @var QuoteValidator + */ + protected $_quoteValidator = null; + + /** + * @var PaymentInterface + */ + protected $_payment; + + /** + * Payment MoipInterest constructor. + * + * @param QuoteValidator $quoteValidator + * @param Session $checkoutSession + * @param PaymentInterface $payment + */ + public function __construct( + QuoteValidator $quoteValidator, + Session $checkoutSession, + PaymentInterface $payment + ) { + $this->_quoteValidator = $quoteValidator; + $this->_checkoutSession = $checkoutSession; + $this->_payment = $payment; + } + + /** + * Collect totals process. + * + * @param Quote $quote + * @param ShippingAssignmentInterface $shippingAssignment + * @param Total $total + * + * @return $this + */ + public function collect( + Quote $quote, + ShippingAssignmentInterface $shippingAssignment, + Total $total + ) { + parent::collect($quote, $shippingAssignment, $total); + + if (!count($shippingAssignment->getItems())) { + return $this; + } + + $moipInterest = $quote->getMoipInterestAmount(); + $baseMoipInterest = $quote->getBaseMoipInterestAmount(); + + $total->setMoipInterestAmount($moipInterest); + $total->setBaseMoipInterestAmount($baseMoipInterest); + + $total->setTotalAmount('moip_interest_amount', $moipInterest); + $total->setBaseTotalAmount('base_moip_interest_amount', $baseMoipInterest); + + $total->setGrandTotal((float) $total->getGrandTotal()); + $total->setBaseGrandTotal((float) $total->getBaseGrandTotal()); + + return $this; + } + + /** + * Assign subtotal amount and label to address object. + * + * @param Quote $quote + * @param Total $total + * + * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function fetch( + Quote $quote, + Total $total + ) { + $result = null; + $interest = $total->getMoipInterestAmount(); + $labelByInterest = $this->getLabelByInterest($interest); + if ((int) $interest !== 0) { + $result = [ + 'code' => $this->getCode(), + 'title' => $labelByInterest, + 'value' => $interest, + ]; + } + + return $result; + } + + /** + * Get Subtotal label. + * + * @return Phrase + */ + public function getLabel() + { + return __('Installment Interest'); + } + + /** + * Get Subtotal label by Interest. + * + * @param $interest | float + * + * @return Phrase + */ + public function getLabelByInterest($interest) + { + if ($interest >= 0) { + return __('Installment Interest'); + } + + return __('Discount Cash'); + } +} diff --git a/Observer/AddMoipInterestToOrderObserver.php b/Observer/AddMoipInterestToOrderObserver.php new file mode 100644 index 0000000..8e1bfa5 --- /dev/null +++ b/Observer/AddMoipInterestToOrderObserver.php @@ -0,0 +1,38 @@ + + * See COPYING.txt for license details. + */ + +declare(strict_types=1); + +namespace Moip\Magento2\Observer; + +use Magento\Framework\Event\ObserverInterface; +use Moip\Magento2\Api\Data\MoipInterestInterface; + +/** + * Class AddMoipInterestToOrderObserver - Converte quote total in order. + */ +class AddMoipInterestToOrderObserver implements ObserverInterface +{ + /** + * @param \Magento\Framework\Event\Observer $observer + */ + public function execute(\Magento\Framework\Event\Observer $observer) + { + /* @var \Magento\Sales\Model\Order $order */ + $order = $observer->getEvent()->getData('order'); + /* @var \Magento\Quote\Model\Quote $quote */ + $quote = $observer->getEvent()->getData('quote'); + + $moipInterest = $quote->getData(MoipInterestInterface::MOIP_INTEREST_AMOUNT); + $baseMoipInterest = $quote->getData(MoipInterestInterface::BASE_MOIP_INTEREST_AMOUNT); + $order->setData(MoipInterestInterface::MOIP_INTEREST_AMOUNT, $moipInterest); + $order->setData(MoipInterestInterface::BASE_MOIP_INTEREST_AMOUNT, $baseMoipInterest); + + return $this; + } +} diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index ccb2f2c..f098f06 100755 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -21,6 +21,20 @@ + + + + 0 + + + + + + + 0 + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 26f0ee3..31e6bde 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -83,6 +83,13 @@ payment/moip_magento2/statement_descriptor required-entry + + + Moip\Magento2\Block\Adminhtml\System\Config\Category + payment/moip_magento2/category + required-entry validate-select + Select the category that best defines your store's products. + @@ -132,58 +139,64 @@ required-entry validate-number payment/moip_magento2_cc/installment_max_installment - - + + + required-entry validate-digits validate-not-negative-number validate-digits-range digits-range-0-100 + payment/moip_magento2_cc/installment_installment_1 + Discount percentage applied to the total order value. + + + required-entry validate-number payment/moip_magento2_cc/installment_installment_2 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_3 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_4 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_5 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_6 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_7 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_8 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_9 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_10 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_11 - + required-entry validate-number payment/moip_magento2_cc/installment_installment_12 diff --git a/etc/config.xml b/etc/config.xml index fab4aba..3bc87e4 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -71,7 +71,7 @@ BRL MERCHANT_KEY method_name,cc_installments,cc_installment_interest,cc_type,cc_number,cc_holder_fullname,cc_holder_birth_date,tax_document,cc_holder_tax_document,cc_holder_phone,device - device + device,cc_installment_interest 1 1 1 diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 0000000..9f9c9f8 --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,35 @@ + + + + + + +
+ + + +
+ + + + + + + +
+ + + +
+ + + +
+
\ No newline at end of file diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json new file mode 100644 index 0000000..8b4608d --- /dev/null +++ b/etc/db_schema_whitelist.json @@ -0,0 +1,36 @@ +{ + "quote": { + "column": { + "moip_interest_amount": true, + "base_moip_interest_amount": true + } + }, + "quote_address": { + "column": { + "moip_interest_amount": true, + "base_moip_interest_amount": true + } + }, + "sales_order": { + "column": { + "moip_interest_amount": true, + "base_moip_interest_amount": true, + "moip_interest_amount_invoiced": true, + "base_moip_interest_amount_invoiced": true, + "moip_interest_amount_refunded": true, + "base_moip_interest_amount_refunded": true + } + }, + "sales_invoice": { + "column": { + "moip_interest_amount": true, + "base_moip_interest_amount": true + } + }, + "sales_creditmemo": { + "column": { + "moip_interest_amount": true, + "base_moip_interest_amount": true + } + } +} \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index 7c351ab..def41f0 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -13,6 +13,9 @@ type="Moip\Magento2\Plugin\PaymentToken" sortOrder="1"/>
+ + + @@ -185,7 +188,6 @@ Moip\Magento2\Gateway\Request\TaxDocumentDataRequest Moip\Magento2\Gateway\Request\CustomerDataRequest Moip\Magento2\Gateway\Request\AddressDataRequest - Moip\Magento2\Gateway\Request\DeviceDataRequest Moip\Magento2\Gateway\Request\SellerDataRequest diff --git a/etc/events.xml b/etc/events.xml index 8791a6a..10aaadf 100755 --- a/etc/events.xml +++ b/etc/events.xml @@ -12,4 +12,7 @@ + + + diff --git a/etc/extension_attributes.xml b/etc/extension_attributes.xml new file mode 100644 index 0000000..de0098b --- /dev/null +++ b/etc/extension_attributes.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/etc/fieldset.xml b/etc/fieldset.xml new file mode 100644 index 0000000..0e415df --- /dev/null +++ b/etc/fieldset.xml @@ -0,0 +1,21 @@ + + + + +
+ + + + + + +
+
+
\ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml index 24dcbdb..9ffc138 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -15,6 +15,7 @@ + diff --git a/etc/moip_error_mapping.xml b/etc/moip_error_mapping.xml index e3d1014..ee8334f 100755 --- a/etc/moip_error_mapping.xml +++ b/etc/moip_error_mapping.xml @@ -182,7 +182,7 @@ Reembolso só pode ser realizado para conta bancária do mesmo titular do pagamento. Pagamento só pode ser reembolsado no cartão de crédito no período inferior a 180 dias após autorização pagamento. Um dos recebedores do pagamento não possui saldo suficiente para o reembolso. - Uma das contas informadas não é recebedora do pagamento. + Uma das contas informadas não é recebedora do pagamento. O recebedor primário não pode assumir o reembolso do recebedor secundário. O recebedor secundário não pode reembolsar um valor maior do que o recebido no pagamento. A conta a ser creditada é um dos recebedores do pagamento. Por favor escolha outra forma de reembolso. diff --git a/etc/pdf.xml b/etc/pdf.xml new file mode 100644 index 0000000..a3f9f95 --- /dev/null +++ b/etc/pdf.xml @@ -0,0 +1,20 @@ + + + + + + Interest Amount + moip_interest + 7 + false + 500 + + + \ No newline at end of file diff --git a/etc/sales.xml b/etc/sales.xml new file mode 100644 index 0000000..2c4607c --- /dev/null +++ b/etc/sales.xml @@ -0,0 +1,26 @@ + + + +
+ + + +
+
+ + + +
+
+ + + +
+
\ No newline at end of file diff --git a/etc/webapi.xml b/etc/webapi.xml new file mode 100644 index 0000000..e008e4d --- /dev/null +++ b/etc/webapi.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + %cart_id% + + + \ No newline at end of file diff --git a/i18n/en_US.csv b/i18n/en_US.csv index eefacc2..06fdf49 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -117,4 +117,98 @@ Use Split,Use Split MPA - Secondary,MPA - Secondary Include Freight on Commission,Include Freight on Commission Include credit card interest in the commission,Include credit card interest in the commission -Percentage sent to the commissioner,Percentage sent to the commissioner \ No newline at end of file +Percentage sent to the commissioner,Percentage sent to the commissioner +%1x of %2 not interest,%1x of %2 not interest +%1% of discount cash with total of %2,%1% of discount cash with total of %2 +%1x of %2 in the total value of %3,%1x of %2 in the total value of %3 +Installment Interest,Installment Interest +Discount Cash,Discount Cash +"Select the store segment.","Select the store segment." +"Select the category that best defines your store's products.","Select the category that best defines your store's products." +Animals and Pet Supplies","Animals and Pet Supplies" +"Apparel and Accessories","Apparel and Accessories" +"Apparel and Accessories > Clothing","Apparel and Accessories > Clothing" +"Apparel and Accessories > Clothing Accessories","Apparel and Accessories > Clothing Accessories" +"Apparel and Accessories > Costumes and Accessories","Apparel and Accessories > Costumes and Accessories" +"Apparel and Accessories > Handbags and Wallet Accessories","Apparel and Accessories > Handbags and Wallet Accessories" +"Apparel and Accessories > Jewelry","Apparel and Accessories > Jewelry" +"Apparel and Accessories > Shoe Accessories","Apparel and Accessories > Shoe Accessories" +"Apparel and Accessories > Shoes","Apparel and Accessories > Shoes" +"Apparel and Accessories > Other","Apparel and Accessories > Other" +"Arts and Entertainment","Arts and Entertainment" +"Baby and Toddler","Baby and Toddler" +"Business and Industrial","Business and Industrial" +"Business and Industrial > Advertising and Marketing","Business and Industrial > Advertising and Marketing" +"Business and Industrial > Agriculture","Business and Industrial > Agriculture" +"Business and Industrial > Construction","Business and Industrial > Construction" +"Business and Industrial > Film and Television","Business and Industrial > Film and Television" +"Business and Industrial > Finance and Insurance","Business and Industrial > Finance and Insurance" +"Business and Industrial > Food Service","Business and Industrial > Food Service" +"Business and Industrial > Forestry and Logging","Business and Industrial > Forestry and Logging" +"Business and Industrial > Heavy Machinery","Business and Industrial > Heavy Machinery" +"Business and Industrial > Hotel and Hospitality","Business and Industrial > Hotel and Hospitality" +"Business and Industrial > Industrial Storage","Business and Industrial > Industrial Storage" +"Business and Industrial > Law Enforcement","Business and Industrial > Law Enforcement" +"Business and Industrial > Manufacturing","Business and Industrial > Manufacturing" +"Business and Industrial > Material Handling","Business and Industrial > Material Handling" +"Business and Industrial > Medical","Business and Industrial > Medical" +"Business and Industrial > Mining and Quarrying","Business and Industrial > Mining and Quarrying" +"Business and Industrial > Piercing and Tattooing","Business and Industrial > Piercing and Tattooing" +"Business and Industrial > Retail","Business and Industrial > Retail" +"Business and Industrial > Science and Laboratory","Business and Industrial > Science and Laboratory" +"Business and Industrial > Signage","Business and Industrial > Signage" +"Business and Industrial > Work Safety Protective Gear","Business and Industrial > Work Safety Protective Gear" +"Business and Industrial > Other Businesses","Business and Industrial > Other Businesses" +"Camera and Optic Accessories","Camera and Optic Accessories" +"Camera and Optic Accessories > Cameras","Camera and Optic Accessories > Cameras" +"Camera and Optic Accessories > Camera Acessories","Camera and Optic Accessories > Camera Acessories" +"Camera and Optic Accessories > Photography","Camera and Optic Accessories > Photography" +"Camera and Optic Accessories > Others Cameras Accessories","Camera and Optic Accessories > Others Cameras Accessories" +Electronics,Electronics +"Electronics > 3d Printers","Electronics > 3d Printers" +"Electronics > Audio","Electronics > Audio" +"Electronics > Circuit Boards and Components","Electronics > Circuit Boards and Components" +"Electronics > Communications","Electronics > Communications" +"Electronics > Components","Electronics > Components" +"Electronics > Computers","Electronics > Computers" +"Electronics > Electronics Accessories","Electronics > Electronics Accessories" +"Electronics > Gps Navigation Systems","Electronics > Gps Navigation Systems" +"Electronics > Gps Accessories","Electronics > Gps Accessories" +"Electronics > Networking","Electronics > Networking" +"Electronics > Print Copy Scan and Fax","Electronics > Print Copy Scan and Fax" +"Electronics > Printer Copier and Fax Machine Accessories","Electronics > Printer Copier and Fax Machine Accessories" +"Electronics > Video","Electronics > Video" +"Electronics > Video Game Consoles","Electronics > Video Game Consoles" +"Electronics > Video Game Console Accessories","Electronics > Video Game Console Accessories" +"Electronics > Other Electronics","Electronics > Other Electronics" +"Food Beverages and Tobacco","Food Beverages and Tobacco" +Furniture,Furniture +"Tool Accessories","Tool Accessories" +"Health and Beauty","Health and Beauty" +"Health and Beauty > Perfume and Cologne","Health and Beauty > Perfume and Cologne" +"Health and Beauty > Makeup","Health and Beauty > Makeup" +"Health and Beauty > Bath and Body","Health and Beauty > Bath and Body" +"Health and Beauty > Cosmetic Tools","Health and Beauty > Cosmetic Tools" +"Luggage and Bags","Luggage and Bags" +Adult,Adult +"Weapons and Ammunition","Weapons and Ammunition" +"Office Supplies","Office Supplies" +"Religious and Ceremonial","Religious and Ceremonial" +Software,Software +"Software > Computer Software","Software > Computer Software" +"Software > Digital Goods and Currency","Software > Digital Goods and Currency" +"Software > Digital Services","Software > Digital Services" +"Software > Video Game Software","Software > Video Game Software" +"Software > Other Softwares","Software > Other Softwares" +"Sporting Goods","Sporting Goods" +"Toys and Games","Toys and Games" +"Vehicles and Parts","Vehicles and Parts" +Books,Books +"Dvds and Videos","Dvds and Videos" +"Magazines and Newspapers","Magazines and Newspapers" +Music,Music +"Music > Cds and Lps","Music > Cds and Lps" +"Music > Musical Instruments","Music > Musical Instruments" +"Music > Digital Music","Music > Digital Music" +"Music > Other Music Items","Music > Other Music Items" +"Music > Other Categories","Music > Other Categories" diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv index 0b63150..a529c53 100755 --- a/i18n/pt_BR.csv +++ b/i18n/pt_BR.csv @@ -276,4 +276,186 @@ Use Split,Usar um Split MPA - Secondary,MPA - Secundário Include Freight on Commission,Incluir o valor do frete no cálculo da comissão Include credit card interest in the commission,Incluir o valor de juros de parcelamento no cálculo da comissão -Percentage sent to the commissioner,Percentagem de comissão enviada \ No newline at end of file +Percentage sent to the commissioner,Percentagem de comissão enviada +%1x of %2 not interest,%1x de %2 sem juros +%1% of discount cash with total of %2, %2 à vista com %1% de desconto +%1x of %2 in the total value of %3,%1x de %2 no valor total de %3 +Installment Interest,Juros de Parcelamento +Discount Cash,Desconto à vista +"Moip Interest Amount","MOIP - Taxa de Juros" +"Animals and Pet Supplies","Animals and Pet Supplies" +"Apparel and Accessories","Apparel and Accessories" +"Apparel and Accessories > Clothing","Apparel and Accessories > Clothing" +"Apparel and Accessories > Clothing Accessories","Apparel and Accessories > Clothing Accessories" +"Apparel and Accessories > Costumes and Accessories","Apparel and Accessories > Costumes and Accessories" +"Apparel and Accessories > Handbags and Wallet Accessories","Apparel and Accessories > Handbags and Wallet Accessories" +"Apparel and Accessories > Jewelry","Apparel and Accessories > Jewelry" +"Apparel and Accessories > Shoe Accessories","Apparel and Accessories > Shoe Accessories" +"Apparel and Accessories > Shoes","Apparel and Accessories > Shoes" +"Apparel and Accessories > Other","Apparel and Accessories > Other" +"Arts and Entertainment","Arts and Entertainment" +"Baby and Toddler","Baby and Toddler" +"Business and Industrial","Business and Industrial" +"Business and Industrial > Advertising and Marketing","Business and Industrial > Advertising and Marketing" +"Business and Industrial > Agriculture","Business and Industrial > Agriculture" +"Business and Industrial > Construction","Business and Industrial > Construction" +"Business and Industrial > Film and Television","Business and Industrial > Film and Television" +"Business and Industrial > Finance and Insurance","Business and Industrial > Finance and Insurance" +"Business and Industrial > Food Service","Business and Industrial > Food Service" +"Business and Industrial > Forestry and Logging","Business and Industrial > Forestry and Logging" +"Business and Industrial > Heavy Machinery","Business and Industrial > Heavy Machinery" +"Business and Industrial > Hotel and Hospitality","Business and Industrial > Hotel and Hospitality" +"Business and Industrial > Industrial Storage","Business and Industrial > Industrial Storage" +"Business and Industrial > Law Enforcement","Business and Industrial > Law Enforcement" +"Business and Industrial > Manufacturing","Business and Industrial > Manufacturing" +"Business and Industrial > Material Handling","Business and Industrial > Material Handling" +"Business and Industrial > Medical","Business and Industrial > Medical" +"Business and Industrial > Mining and Quarrying","Business and Industrial > Mining and Quarrying" +"Business and Industrial > Piercing and Tattooing","Business and Industrial > Piercing and Tattooing" +"Business and Industrial > Retail","Business and Industrial > Retail" +"Business and Industrial > Science and Laboratory","Business and Industrial > Science and Laboratory" +"Business and Industrial > Signage","Business and Industrial > Signage" +"Business and Industrial > Work Safety Protective Gear","Business and Industrial > Work Safety Protective Gear" +"Business and Industrial > Other Businesses","Business and Industrial > Other Businesses" +"Camera and Optic Accessories","Camera and Optic Accessories" +"Camera and Optic Accessories > Cameras","Camera and Optic Accessories > Cameras" +"Camera and Optic Accessories > Camera Acessories","Camera and Optic Accessories > Camera Acessories" +"Camera and Optic Accessories > Photography","Camera and Optic Accessories > Photography" +"Camera and Optic Accessories > Others Cameras Accessories","Camera and Optic Accessories > Others Cameras Accessories" +Electronics,Electronics +"Electronics > 3d Printers","Electronics > 3d Printers" +"Electronics > Audio","Electronics > Audio" +"Electronics > Circuit Boards and Components","Electronics > Circuit Boards and Components" +"Electronics > Communications","Electronics > Communications" +"Electronics > Components","Electronics > Components" +"Electronics > Computers","Electronics > Computers" +"Electronics > Electronics Accessories","Electronics > Electronics Accessories" +"Electronics > Gps Navigation Systems","Electronics > Gps Navigation Systems" +"Electronics > Gps Accessories","Electronics > Gps Accessories" +"Electronics > Networking","Electronics > Networking" +"Electronics > Print Copy Scan and Fax","Electronics > Print Copy Scan and Fax" +"Electronics > Printer Copier and Fax Machine Accessories","Electronics > Printer Copier and Fax Machine Accessories" +"Electronics > Video","Electronics > Video" +"Electronics > Video Game Consoles","Electronics > Video Game Consoles" +"Electronics > Video Game Console Accessories","Electronics > Video Game Console Accessories" +"Electronics > Other Electronics","Electronics > Other Electronics" +"Food Beverages and Tobacco","Food Beverages and Tobacco" +Furniture,Furniture +"Tool Accessories","Tool Accessories" +"Health and Beauty","Health and Beauty" +"Health and Beauty > Perfume and Cologne","Health and Beauty > Perfume and Cologne" +"Health and Beauty > Makeup","Health and Beauty > Makeup" +"Health and Beauty > Bath and Body","Health and Beauty > Bath and Body" +"Health and Beauty > Cosmetic Tools","Health and Beauty > Cosmetic Tools" +"Luggage and Bags","Luggage and Bags" +Adult,Adult +"Weapons and Ammunition","Weapons and Ammunition" +"Office Supplies","Office Supplies" +"Religious and Ceremonial","Religious and Ceremonial" +Software,Software +"Software > Computer Software","Software > Computer Software" +"Software > Digital Goods and Currency","Software > Digital Goods and Currency" +"Software > Digital Services","Software > Digital Services" +"Software > Video Game Software","Software > Video Game Software" +"Software > Other Softwares","Software > Other Softwares" +"Sporting Goods","Sporting Goods" +"Toys and Games","Toys and Games" +"Vehicles and Parts","Vehicles and Parts" +Books,Books +"Dvds and Videos","Dvds and Videos" +"Magazines and Newspapers","Magazines and Newspapers" +Music,Music +"Music > Cds and Lps","Music > Cds and Lps" +"Music > Musical Instruments","Music > Musical Instruments" +"Music > Digital Music","Music > Digital Music" +"Music > Other Music Items","Music > Other Music Items" +"Music > Other Categories","Music > Other Categories" +"Please select the store category.","Please select the store category." +"Select the category that best defines your store's products.","Selecione a categoria que melhor define os produtos da sua loja." +Animals and Pet Supplies","Animals and Pet Supplies" +"Apparel and Accessories","Apparel and Accessories" +"Apparel and Accessories > Clothing","Apparel and Accessories > Clothing" +"Apparel and Accessories > Clothing Accessories","Apparel and Accessories > Clothing Accessories" +"Apparel and Accessories > Costumes and Accessories","Apparel and Accessories > Costumes and Accessories" +"Apparel and Accessories > Handbags and Wallet Accessories","Apparel and Accessories > Handbags and Wallet Accessories" +"Apparel and Accessories > Jewelry","Apparel and Accessories > Jewelry" +"Apparel and Accessories > Shoe Accessories","Apparel and Accessories > Shoe Accessories" +"Apparel and Accessories > Shoes","Apparel and Accessories > Shoes" +"Apparel and Accessories > Other","Apparel and Accessories > Other" +"Arts and Entertainment","Arts and Entertainment" +"Baby and Toddler","Baby and Toddler" +"Business and Industrial","Business and Industrial" +"Business and Industrial > Advertising and Marketing","Business and Industrial > Advertising and Marketing" +"Business and Industrial > Agriculture","Business and Industrial > Agriculture" +"Business and Industrial > Construction","Business and Industrial > Construction" +"Business and Industrial > Film and Television","Business and Industrial > Film and Television" +"Business and Industrial > Finance and Insurance","Business and Industrial > Finance and Insurance" +"Business and Industrial > Food Service","Business and Industrial > Food Service" +"Business and Industrial > Forestry and Logging","Business and Industrial > Forestry and Logging" +"Business and Industrial > Heavy Machinery","Business and Industrial > Heavy Machinery" +"Business and Industrial > Hotel and Hospitality","Business and Industrial > Hotel and Hospitality" +"Business and Industrial > Industrial Storage","Business and Industrial > Industrial Storage" +"Business and Industrial > Law Enforcement","Business and Industrial > Law Enforcement" +"Business and Industrial > Manufacturing","Business and Industrial > Manufacturing" +"Business and Industrial > Material Handling","Business and Industrial > Material Handling" +"Business and Industrial > Medical","Business and Industrial > Medical" +"Business and Industrial > Mining and Quarrying","Business and Industrial > Mining and Quarrying" +"Business and Industrial > Piercing and Tattooing","Business and Industrial > Piercing and Tattooing" +"Business and Industrial > Retail","Business and Industrial > Retail" +"Business and Industrial > Science and Laboratory","Business and Industrial > Science and Laboratory" +"Business and Industrial > Signage","Business and Industrial > Signage" +"Business and Industrial > Work Safety Protective Gear","Business and Industrial > Work Safety Protective Gear" +"Business and Industrial > Other Businesses","Business and Industrial > Other Businesses" +"Camera and Optic Accessories","Camera and Optic Accessories" +"Camera and Optic Accessories > Cameras","Camera and Optic Accessories > Cameras" +"Camera and Optic Accessories > Camera Acessories","Camera and Optic Accessories > Camera Acessories" +"Camera and Optic Accessories > Photography","Camera and Optic Accessories > Photography" +"Camera and Optic Accessories > Others Cameras Accessories","Camera and Optic Accessories > Others Cameras Accessories" +Electronics,Electronics +"Electronics > 3d Printers","Electronics > 3d Printers" +"Electronics > Audio","Electronics > Audio" +"Electronics > Circuit Boards and Components","Electronics > Circuit Boards and Components" +"Electronics > Communications","Electronics > Communications" +"Electronics > Components","Electronics > Components" +"Electronics > Computers","Electronics > Computers" +"Electronics > Electronics Accessories","Electronics > Electronics Accessories" +"Electronics > Gps Navigation Systems","Electronics > Gps Navigation Systems" +"Electronics > Gps Accessories","Electronics > Gps Accessories" +"Electronics > Networking","Electronics > Networking" +"Electronics > Print Copy Scan and Fax","Electronics > Print Copy Scan and Fax" +"Electronics > Printer Copier and Fax Machine Accessories","Electronics > Printer Copier and Fax Machine Accessories" +"Electronics > Video","Electronics > Video" +"Electronics > Video Game Consoles","Electronics > Video Game Consoles" +"Electronics > Video Game Console Accessories","Electronics > Video Game Console Accessories" +"Electronics > Other Electronics","Electronics > Other Electronics" +"Food Beverages and Tobacco","Food Beverages and Tobacco" +Furniture,Furniture +"Tool Accessories","Tool Accessories" +"Health and Beauty","Health and Beauty" +"Health and Beauty > Perfume and Cologne","Health and Beauty > Perfume and Cologne" +"Health and Beauty > Makeup","Health and Beauty > Makeup" +"Health and Beauty > Bath and Body","Health and Beauty > Bath and Body" +"Health and Beauty > Cosmetic Tools","Health and Beauty > Cosmetic Tools" +"Luggage and Bags","Luggage and Bags" +Adult,Adult +"Weapons and Ammunition","Weapons and Ammunition" +"Office Supplies","Office Supplies" +"Religious and Ceremonial","Religious and Ceremonial" +Software,Software +"Software > Computer Software","Software > Computer Software" +"Software > Digital Goods and Currency","Software > Digital Goods and Currency" +"Software > Digital Services","Software > Digital Services" +"Software > Video Game Software","Software > Video Game Software" +"Software > Other Softwares","Software > Other Softwares" +"Sporting Goods","Sporting Goods" +"Toys and Games","Toys and Games" +"Vehicles and Parts","Vehicles and Parts" +Books,Books +"Dvds and Videos","Dvds and Videos" +"Magazines and Newspapers","Magazines and Newspapers" +Music,Music +"Music > Cds and Lps","Music > Cds and Lps" +"Music > Musical Instruments","Music > Musical Instruments" +"Music > Digital Music","Music > Digital Music" +"Music > Other Music Items","Music > Other Music Items" +"Music > Other Categories","Music > Other Categories" \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_creditmemo_new.xml b/view/adminhtml/layout/sales_order_creditmemo_new.xml index e72e8d8..7b6d634 100644 --- a/view/adminhtml/layout/sales_order_creditmemo_new.xml +++ b/view/adminhtml/layout/sales_order_creditmemo_new.xml @@ -17,5 +17,9 @@ + + + diff --git a/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml b/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml new file mode 100644 index 0000000..d9dd7f3 --- /dev/null +++ b/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_creditmemo_view.xml b/view/adminhtml/layout/sales_order_creditmemo_view.xml new file mode 100644 index 0000000..5ff8f02 --- /dev/null +++ b/view/adminhtml/layout/sales_order_creditmemo_view.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_invoice_new.xml b/view/adminhtml/layout/sales_order_invoice_new.xml new file mode 100644 index 0000000..ed07684 --- /dev/null +++ b/view/adminhtml/layout/sales_order_invoice_new.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_invoice_updateqty.xml b/view/adminhtml/layout/sales_order_invoice_updateqty.xml new file mode 100644 index 0000000..ed07684 --- /dev/null +++ b/view/adminhtml/layout/sales_order_invoice_updateqty.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_invoice_view.xml b/view/adminhtml/layout/sales_order_invoice_view.xml new file mode 100644 index 0000000..c015cfe --- /dev/null +++ b/view/adminhtml/layout/sales_order_invoice_view.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/layout/sales_order_view.xml b/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 0000000..ed865ec --- /dev/null +++ b/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/templates/form/cc.phtml b/view/adminhtml/templates/form/cc.phtml index 8028a74..6ffa3e3 100755 --- a/view/adminhtml/templates/form/cc.phtml +++ b/view/adminhtml/templates/form/cc.phtml @@ -160,15 +160,12 @@ $ccInstallment = $block->getInfoData('cc_installment');
diff --git a/view/adminhtml/web/css/system_config.css b/view/adminhtml/web/css/system_config.css index 7688839..b02beeb 100755 --- a/view/adminhtml/web/css/system_config.css +++ b/view/adminhtml/web/css/system_config.css @@ -12,7 +12,7 @@ .complex.moip-payment-section .moip-payment-logo { flex-basis: 15%; height: 70px; - background: url('images/logo.svg') no-repeat center center; + background: url('../images/logo.svg') no-repeat center center; -webkit-background-size: contain; -moz-background-size: contain; -o-background-size: contain; diff --git a/view/frontend/layout/checkout_cart_index.xml b/view/frontend/layout/checkout_cart_index.xml new file mode 100644 index 0000000..23e1a36 --- /dev/null +++ b/view/frontend/layout/checkout_cart_index.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + Moip_Magento2/js/view/cart/totals/moip_interest + + Payment Moip Interest + + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 550d820..bfff136 100755 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -49,6 +49,26 @@ + + + + + + + + Moip_Magento2/js/view/checkout/cart/totals/moip_interest + 20 + + Moip_Magento2/checkout/cart/totals/moip_interest + Payment Moip Interest + + + + + + + + diff --git a/view/frontend/layout/checkout_onepage_success.xml b/view/frontend/layout/checkout_onepage_success.xml index 05becf8..a219fa0 100755 --- a/view/frontend/layout/checkout_onepage_success.xml +++ b/view/frontend/layout/checkout_onepage_success.xml @@ -10,4 +10,7 @@ + + + \ No newline at end of file diff --git a/view/frontend/layout/sales_email_order_creditmemo_items.xml b/view/frontend/layout/sales_email_order_creditmemo_items.xml new file mode 100644 index 0000000..845ad06 --- /dev/null +++ b/view/frontend/layout/sales_email_order_creditmemo_items.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/view/frontend/layout/sales_email_order_invoice_items.xml b/view/frontend/layout/sales_email_order_invoice_items.xml new file mode 100644 index 0000000..13c9bc4 --- /dev/null +++ b/view/frontend/layout/sales_email_order_invoice_items.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_email_order_items.xml b/view/frontend/layout/sales_email_order_items.xml new file mode 100644 index 0000000..8cf0bcb --- /dev/null +++ b/view/frontend/layout/sales_email_order_items.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_guest_invoice.xml b/view/frontend/layout/sales_guest_invoice.xml new file mode 100644 index 0000000..51feed7 --- /dev/null +++ b/view/frontend/layout/sales_guest_invoice.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_guest_print.xml b/view/frontend/layout/sales_guest_print.xml new file mode 100644 index 0000000..a0b21b1 --- /dev/null +++ b/view/frontend/layout/sales_guest_print.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_guest_printinvoice.xml b/view/frontend/layout/sales_guest_printinvoice.xml new file mode 100644 index 0000000..273a107 --- /dev/null +++ b/view/frontend/layout/sales_guest_printinvoice.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_guest_view.xml b/view/frontend/layout/sales_guest_view.xml new file mode 100644 index 0000000..e1f41f5 --- /dev/null +++ b/view/frontend/layout/sales_guest_view.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/sales_order_creditmemo.xml b/view/frontend/layout/sales_order_creditmemo.xml new file mode 100644 index 0000000..3dfe570 --- /dev/null +++ b/view/frontend/layout/sales_order_creditmemo.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_order_invoice.xml b/view/frontend/layout/sales_order_invoice.xml new file mode 100644 index 0000000..7226b44 --- /dev/null +++ b/view/frontend/layout/sales_order_invoice.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/layout/sales_order_print.xml b/view/frontend/layout/sales_order_print.xml new file mode 100644 index 0000000..e1f41f5 --- /dev/null +++ b/view/frontend/layout/sales_order_print.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/sales_order_view.xml b/view/frontend/layout/sales_order_view.xml new file mode 100644 index 0000000..e1f41f5 --- /dev/null +++ b/view/frontend/layout/sales_order_view.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index 02dd225..bbfa70e 100755 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -4,6 +4,12 @@ * See COPYING.txt for license details. */ var config = { + map: { + '*': { + 'Magento_Checkout/js/action/select-payment-method': + 'Moip_Magento2/js/action/payment/select-payment-method' + } + }, config: { mixins: { "Magento_Payment/js/model/credit-card-validation/credit-card-number-validator/credit-card-type": { diff --git a/view/frontend/web/js/action/checkout/cart/totals.js b/view/frontend/web/js/action/checkout/cart/totals.js new file mode 100644 index 0000000..dc104ac --- /dev/null +++ b/view/frontend/web/js/action/checkout/cart/totals.js @@ -0,0 +1,71 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +define( + [ + "jquery", + "Magento_Checkout/js/model/quote", + "Magento_Checkout/js/model/url-builder", + "Magento_Checkout/js/model/error-processor", + "mage/url", + "Magento_Checkout/js/action/get-totals", + 'Magento_Customer/js/model/customer', + ], + function ($, quote, urlBuilder, errorProcessor, urlFormatter, getTotalsAction, customer) { + "use strict"; + return { + /** + * Save Moip Interest by Installment + * + * @param installment + */ + save(installment) { + var serviceUrl, + payload, + quoteId = quote.getQuoteId(); + + if (!customer.isLoggedIn()) { + serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/set-installment-for-moip-interest', { + cartId: quoteId + }); + payload = { + cartId: quoteId, + installment: { + installment_for_interest: installment + } + }; + } else { + serviceUrl = urlBuilder.createUrl('/carts/mine/set-installment-for-moip-interest', {}); + payload = { + cartId: quoteId, + installment: { + installment_for_interest: installment + } + }; + } + + var result = true; + $.ajax({ + url: urlFormatter.build(serviceUrl), + data: JSON.stringify(payload), + global: false, + contentType: "application/json", + type: "PUT", + async: false + }).done( + function (response) { + var deferred = $.Deferred(); + getTotalsAction([], deferred); + } + ).fail( + function (response) { + result = false; + errorProcessor.process(response); + } + ); + return result; + } + }; +}); \ No newline at end of file diff --git a/view/frontend/web/js/action/payment/select-payment-method.js b/view/frontend/web/js/action/payment/select-payment-method.js new file mode 100644 index 0000000..e43685d --- /dev/null +++ b/view/frontend/web/js/action/payment/select-payment-method.js @@ -0,0 +1,21 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +define([ + 'Magento_Checkout/js/model/quote', + 'Moip_Magento2/js/action/checkout/cart/totals' +], function (quote, totals) { + 'use strict'; + + return function (paymentMethod) { + if (paymentMethod) { + paymentMethod.__disableTmpl = { + title: true + }; + } + quote.paymentMethod(paymentMethod); + totals.save(0); + }; +}); \ No newline at end of file diff --git a/view/frontend/web/js/view/cart/summary/moip_interest.js b/view/frontend/web/js/view/cart/summary/moip_interest.js new file mode 100644 index 0000000..1f22a04 --- /dev/null +++ b/view/frontend/web/js/view/cart/summary/moip_interest.js @@ -0,0 +1,64 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +define( + [ + "Magento_Checkout/js/view/summary/abstract-total", + "Magento_Checkout/js/model/quote", + "Magento_Catalog/js/price-utils", + "Magento_Checkout/js/model/totals", + "mage/translate", + ], + function (Component, quote, priceUtils, totals, $t) { + "use strict"; + return Component.extend({ + defaults: { + template: "Moip_Magento2/cart/summary/moip_interest", + active: false + }, + totals: quote.getTotals(), + + initObservable() { + this._super().observe(["active"]); + return this; + }, + + isActive() { + return this.getPureValue() !== 0; + }, + + getPureValue() { + var price = 0, + priceInterest; + if (this.totals() && totals.getSegment("moip_interest_amount")) { + priceInterest = totals.getSegment("moip_interest_amount").value + if(priceInterest !== 0.000) { + return priceInterest; + } + } + return price; + }, + + customTitle() { + if(this.getPureValue() > 0) { + return $t("Installment Interest"); + } + return $t("Discount Cash"); + }, + + getValue() { + return this.getFormattedPrice(this.getPureValue()); + }, + + getBaseValue() { + var price = 0; + if (this.totals()) { + price = this.totals().base_payment_charge; + } + return priceUtils.formatPrice(price, quote.getBasePriceFormat()); + } + }); + } +); \ No newline at end of file diff --git a/view/frontend/web/js/view/cart/totals/moip_interest.js b/view/frontend/web/js/view/cart/totals/moip_interest.js new file mode 100644 index 0000000..c7138cc --- /dev/null +++ b/view/frontend/web/js/view/cart/totals/moip_interest.js @@ -0,0 +1,25 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +/*global define*/ +define( + [ + "Moip_Magento2/js/view/cart/summary/moip_interest" + ], + function (Component) { + "use strict"; + + return Component.extend({ + /** + * @override + * + * @returns {boolean} + */ + isDisplayed() { + return this.getPureValue() !== 0; + } + }); + } +); diff --git a/view/frontend/web/js/view/checkout/cart/totals/moip_interest.js b/view/frontend/web/js/view/checkout/cart/totals/moip_interest.js new file mode 100644 index 0000000..77ef178 --- /dev/null +++ b/view/frontend/web/js/view/checkout/cart/totals/moip_interest.js @@ -0,0 +1,23 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +define( + [ + "Moip_Magento2/js/view/checkout/summary/moip_interest" + ], + function (Component) { + "use strict"; + + return Component.extend({ + + /** + * @override + */ + isDisplayed() { + return this.getPureValue() != 0; + }, + }); + } +); \ No newline at end of file diff --git a/view/frontend/web/js/view/checkout/summary/moip_interest.js b/view/frontend/web/js/view/checkout/summary/moip_interest.js new file mode 100644 index 0000000..02b6e37 --- /dev/null +++ b/view/frontend/web/js/view/checkout/summary/moip_interest.js @@ -0,0 +1,64 @@ +/** + * Copyright © Wirecard Brasil. All rights reserved. + * @author Bruno Elisei + * See COPYING.txt for license details. + */ +define( + [ + "Magento_Checkout/js/view/summary/abstract-total", + "Magento_Checkout/js/model/quote", + "Magento_Catalog/js/price-utils", + "Magento_Checkout/js/model/totals", + "mage/translate", + ], + function (Component, quote, priceUtils, totals, $t) { + "use strict"; + return Component.extend({ + defaults: { + template: "Moip_Magento2/checkout/summary/moip_interest", + active: false + }, + totals: quote.getTotals(), + + initObservable() { + this._super().observe(["active"]); + return this; + }, + + isActive() { + return this.getPureValue() !== 0; + }, + + getPureValue() { + var price = 0, + priceInterest; + if (this.totals() && totals.getSegment("moip_interest_amount")) { + priceInterest = totals.getSegment("moip_interest_amount").value + if(priceInterest !== 0.000) { + return priceInterest; + } + } + return price; + }, + + customTitle() { + if(this.getPureValue() > 0) { + return $t("Installment Interest"); + } + return $t("Discount Cash"); + }, + + getValue() { + return this.getFormattedPrice(this.getPureValue()); + }, + + getBaseValue() { + var price = 0; + if (this.totals()) { + price = this.totals().base_payment_charge; + } + return priceUtils.formatPrice(price, quote.getBasePriceFormat()); + } + }); + } +); \ No newline at end of file diff --git a/view/frontend/web/js/view/payment/method-renderer/moip_magento2_cc.js b/view/frontend/web/js/view/payment/method-renderer/moip_magento2_cc.js index e2874dc..858a9b8 100755 --- a/view/frontend/web/js/view/payment/method-renderer/moip_magento2_cc.js +++ b/view/frontend/web/js/view/payment/method-renderer/moip_magento2_cc.js @@ -16,9 +16,10 @@ define([ "mage/translate", "ko", "mage/calendar", + "Moip_Magento2/js/action/checkout/cart/totals", "Moip_Magento2/js/view/payment/gateway/moip", - "Magento_Payment/js/model/credit-card-validation/validator" -], function (_, $, Component, VaultEnabler, creditCardData, custom, mask, quote, priceUtils, $t, ko, calendar) { + "Magento_Payment/js/model/credit-card-validation/validator", +], function (_, $, Component, VaultEnabler, creditCardData, custom, mask, quote, priceUtils, $t, ko, calendar, TotalsMoipInterest) { "use strict"; return Component.extend({ @@ -33,6 +34,7 @@ define([ creditCardHolderPhone: "", creditCardHolderBirthDate: "" }, + totals: quote.getTotals(), initObservable() { this._super().observe(["active","creditCardInstallment","creditCardHash","creditCardHolderFullName","creditCardHolderTaxDocument","creditCardHolderPhone","creditCardHolderBirthDate"]); @@ -90,11 +92,15 @@ define([ } } }; - + dob.mask("00/00/0000", { clearIfNotMatch: true }); tel.mask("(00)00000-0000", { clearIfNotMatch: true }); + + + this.creditCardInstallment.subscribe(function (value) { creditCardData.creditCardInstallment = value; + self.genetateInterest(); }); this.creditCardHash.subscribe(function (value) { @@ -116,7 +122,6 @@ define([ }); this.creditCardHolderBirthDate.subscribe(function (value) { - creditCardData.creditCardHolderBirthDate = value; }); @@ -146,7 +151,15 @@ define([ $(this.formElement).validation(); }, + genetateInterest() { + var value = this.creditCardInstallment(); + if(value){ + TotalsMoipInterest.save(value); + } + }, + beforePlaceOrder() { + this.genetateInterest(); this.getHash(); if (!$(this.formElement).valid()) { return; @@ -227,102 +240,120 @@ define([ return window.checkoutConfig.payment[this.getCode()].phone_capture; }, - getInstall() { - var valor = quote.totals().base_grand_total; + getInterestApply(){ + var valueInterest = 0; + _.map(this.totals()['total_segments'], function (segment) { + if(segment['code'] === 'moip_interest_amount') { + valueInterest = segment['value']; + } + }); + return valueInterest; + }, + + getInstalmentsValues() { + var grandTotal = quote.totals().base_grand_total; + var moipIterest = this.getInterestApply(); + var calcTotal = grandTotal - moipIterest; var type_interest = window.checkoutConfig.payment[this.getCode()].type_interest var info_interest = window.checkoutConfig.payment[this.getCode()].info_interest; var min_installment = window.checkoutConfig.payment[this.getCode()].min_installment; var max_installment = window.checkoutConfig.payment[this.getCode()].max_installment; - var json_parcelas = {}; + var installmentsCalcValues = {}; var count = 0; - json_parcelas[1] = - {"parcela" : priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_parcelado" : priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_juros" : 0, - "juros" : 0 - }; - - var max_div = (valor/min_installment); + + var max_div = (calcTotal/min_installment); max_div = parseInt(max_div); if(max_div > max_installment) { max_div = max_installment; - }else{ + } else { if(max_div > 12) { max_div = 12; } } - var limite = max_div; - - _.each( info_interest, function( key, value ) { - if(count <= max_div){ - value = info_interest[value]; - if(value > 0){ - - var taxa = value/100; - if(type_interest === "compound"){ - var pw = Math.pow((1 / (1 + taxa)), count); - var parcela = (((valor * taxa) * 1) / (1 - pw)); - } else { - var parcela = ((valor*taxa)+valor) / count; - } - - var total_parcelado = parcela*count; - - var juros = value; - if(parcela > 5 && parcela > min_installment){ - json_parcelas[count] = { - "parcela" : priceUtils.formatPrice(parcela, quote.getPriceFormat()), - "total_parcelado": priceUtils.formatPrice(total_parcelado, quote.getPriceFormat()), - "total_juros" : priceUtils.formatPrice(total_parcelado - valor, quote.getPriceFormat()), - "juros" : juros, - }; - } + var limit = max_div; + + _.each(info_interest, function( key, value ) { + value = info_interest[value]; + + if(value > 0){ + var taxa = value/100; + if(type_interest === "compound"){ + var pw = Math.pow((1 / (1 + taxa)), count); + var installment = (((calcTotal * taxa) * 1) / (1 - pw)); } else { - if(valor > 0 && count > 0){ - json_parcelas[count] = { - "parcela" : priceUtils.formatPrice((valor/count), quote.getPriceFormat()), - "total_parcelado": priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_juros" : 0, - "juros" : 0, - }; - } + var installment = ((calcTotal*taxa)+calcTotal) / count; + } + + var totalInstallment = installment*count; + var interest = value; + if(installment > 5 && installment > min_installment){ + installmentsCalcValues[count] = { + "installment" : priceUtils.formatPrice(installment, quote.getPriceFormat()), + "totalInstallment": priceUtils.formatPrice(totalInstallment, quote.getPriceFormat()), + "totalInterest" : priceUtils.formatPrice(totalInstallment - calcTotal, quote.getPriceFormat()), + "interest" : interest, + }; + } + } else if(value == 0) { + if(calcTotal > 0 && count > 0){ + installmentsCalcValues[count] = { + "installment" : priceUtils.formatPrice((calcTotal/count), quote.getPriceFormat()), + "totalInstallment": priceUtils.formatPrice(calcTotal, quote.getPriceFormat()), + "totalInterest" : 0, + "interest" : 0, + }; + } + } else if(value < 0) { + var taxa = value/100; + if(calcTotal > 0 && count > 0){ + var installment = ((calcTotal*taxa)+calcTotal) / count; + installmentsCalcValues[count] = { + "totalWithTheDiscount": priceUtils.formatPrice(installment, quote.getPriceFormat()), + "discount" : value, + "interest": value + }; } } count++; }); - _.each( json_parcelas, function( key, value ) { - if(key > limite){ - delete json_parcelas[key]; - } - }); - return json_parcelas; + if(limit) { + _.each( installmentsCalcValues, function( key, value ) { + if(key > limit){ + delete installmentsCalcValues[key]; + } + }); + } + return installmentsCalcValues; }, getInstallments() { - var temp = _.map(this.getInstall(), function (value, key) { - if(value["juros"] === 0){ - var info_interest = "sem juros"; + var temp = _.map(this.getInstalmentsValues(), function (value, key) { + var inst; + + if(value["interest"] === 0){ + inst = $t("%1x of %2 not interest").replace("%1",key).replace("%2",value["installment"]); + } else if(value["interest"] < 0){ + inst = $t("%1% of discount cash with total of %2").replace("%1", value["discount"]).replace("%2", value["totalWithTheDiscount"]); } else { - var info_interest = "com juros total de " + value["total_juros"]; + inst = $t("%1x of %2 in the total value of %3").replace("%1",key).replace("%2",value["installment"]).replace("%3",value["totalInstallment"]); } - var inst = key+" x "+ value["parcela"]+" no valor total de " + value["total_parcelado"] + " " + info_interest; - return { - "value": key, - "installments": inst - }; - - }); + + return { + "value": key, + "installments": inst + }; + }); + var newArray = []; for (var i = 0; i < temp.length; i++) { - if (temp[i].installments!="undefined" && temp[i].installments!=undefined) { newArray.push(temp[i]); } } - + return newArray; }, diff --git a/view/frontend/web/js/view/payment/method-renderer/vault.js b/view/frontend/web/js/view/payment/method-renderer/vault.js index b5c495e..646b2dd 100755 --- a/view/frontend/web/js/view/payment/method-renderer/vault.js +++ b/view/frontend/web/js/view/payment/method-renderer/vault.js @@ -7,28 +7,36 @@ define([ "underscore", "jquery", "Magento_Vault/js/view/payment/method-renderer/vault", + "Magento_Payment/js/model/credit-card-validation/credit-card-data", "Magento_Checkout/js/model/quote", "Magento_Catalog/js/price-utils", "mage/translate", - "ko" -], function (_, $, VaultComponent, quote, priceUtils, $t, ko) { + "ko", + "Moip_Magento2/js/action/checkout/cart/totals" +], function (_, $, VaultComponent, creditCardData, quote, priceUtils, $t, ko, TotalsMoipInterest) { "use strict"; return VaultComponent.extend({ defaults: { active: false, template: "Moip_Magento2/payment/vault", - vaultForm: "Moip_Magento2/payment/vault-form" + vaultForm: "Moip_Magento2/payment/vault-form", + creditCardInstallment: "" }, + totals: quote.getTotals(), initialize() { var self = this; - this._super(); + + this.creditCardInstallment.subscribe(function (value) { + creditCardData.creditCardInstallment = value; + self.genetateInterest(); + }); }, initObservable() { - this._super().observe(["active"]); + this._super().observe(["active","creditCardInstallment"]); return this; }, @@ -49,7 +57,15 @@ define([ return data; }, + genetateInterest() { + var value = this.creditCardInstallment(); + if(value){ + TotalsMoipInterest.save(value); + } + }, + beforePlaceOrder() { + this.genetateInterest(); if (!$(this.formElement).valid()) { return; } else { @@ -101,104 +117,122 @@ define([ window.checkoutConfig.payment[this.getCode()].icons[type] : false; }, + + getInterestApply(){ + var valueInterest = 0; + _.map(this.totals()['total_segments'], function (segment) { + if(segment['code'] === 'moip_interest_amount') { + valueInterest = segment['value']; + } + }); + return valueInterest; + }, - getInstall() { - var valor = quote.totals().base_grand_total; + getInstalmentsValues() { + var grandTotal = quote.totals().base_grand_total; + var moipIterest = this.getInterestApply(); + var calcTotal = grandTotal - moipIterest; var type_interest = window.checkoutConfig.payment[this.getAuxiliaryCode()].type_interest var info_interest = window.checkoutConfig.payment[this.getAuxiliaryCode()].info_interest; var min_installment = window.checkoutConfig.payment[this.getAuxiliaryCode()].min_installment; var max_installment = window.checkoutConfig.payment[this.getAuxiliaryCode()].max_installment; - var json_parcelas = {}; + var installmentsCalcValues = {}; var count = 0; - json_parcelas[1] = - {"parcela" : priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_parcelado" : priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_juros" : 0, - "juros" : 0 - }; - - var max_div = (valor/min_installment); + + var max_div = (calcTotal/min_installment); max_div = parseInt(max_div); if(max_div > max_installment) { max_div = max_installment; - }else{ + } else { if(max_div > 12) { max_div = 12; } } - var limite = max_div; - - _.each( info_interest, function( key, value ) { - if(count <= max_div){ - value = info_interest[value]; - if(value > 0){ - - var taxa = value/100; - if(type_interest === "compound"){ - var pw = Math.pow((1 / (1 + taxa)), count); - var parcela = (((valor * taxa) * 1) / (1 - pw)); - } else { - var parcela = ((valor*taxa)+valor) / count; - } - - var total_parcelado = parcela*count; - - var juros = value; - if(parcela > 5 && parcela > min_installment){ - json_parcelas[count] = { - "parcela" : priceUtils.formatPrice(parcela, quote.getPriceFormat()), - "total_parcelado": priceUtils.formatPrice(total_parcelado, quote.getPriceFormat()), - "total_juros" : priceUtils.formatPrice(total_parcelado - valor, quote.getPriceFormat()), - "juros" : juros, - }; - } + var limit = max_div; + + _.each(info_interest, function( key, value ) { + value = info_interest[value]; + + if(value > 0){ + var taxa = value/100; + if(type_interest === "compound"){ + var pw = Math.pow((1 / (1 + taxa)), count); + var installment = (((calcTotal * taxa) * 1) / (1 - pw)); } else { - if(valor > 0 && count > 0){ - json_parcelas[count] = { - "parcela" : priceUtils.formatPrice((valor/count), quote.getPriceFormat()), - "total_parcelado": priceUtils.formatPrice(valor, quote.getPriceFormat()), - "total_juros" : 0, - "juros" : 0, - }; - } + var installment = ((calcTotal*taxa)+calcTotal) / count; + } + + var totalInstallment = installment*count; + var interest = value; + if(installment > 5 && installment > min_installment){ + installmentsCalcValues[count] = { + "installment" : priceUtils.formatPrice(installment, quote.getPriceFormat()), + "totalInstallment": priceUtils.formatPrice(totalInstallment, quote.getPriceFormat()), + "totalInterest" : priceUtils.formatPrice(totalInstallment - calcTotal, quote.getPriceFormat()), + "interest" : interest, + }; + } + } else if(value == 0) { + if(calcTotal > 0 && count > 0){ + installmentsCalcValues[count] = { + "installment" : priceUtils.formatPrice((calcTotal/count), quote.getPriceFormat()), + "totalInstallment": priceUtils.formatPrice(calcTotal, quote.getPriceFormat()), + "totalInterest" : 0, + "interest" : 0, + }; + } + } else if(value < 0) { + var taxa = value/100; + if(calcTotal > 0 && count > 0){ + var installment = ((calcTotal*taxa)+calcTotal) / count; + installmentsCalcValues[count] = { + "totalWithTheDiscount": priceUtils.formatPrice(installment, quote.getPriceFormat()), + "discount" : value, + "interest": value + }; } } count++; }); - _.each( json_parcelas, function( key, value ) { - if(key > limite){ - delete json_parcelas[key]; - } - }); - return json_parcelas; + if(limit) { + _.each( installmentsCalcValues, function( key, value ) { + if(key > limit){ + delete installmentsCalcValues[key]; + } + }); + } + return installmentsCalcValues; }, getInstallments() { - var temp = _.map(this.getInstall(), function (value, key) { - if(value["juros"] === 0){ - var info_interest = "sem juros"; + var temp = _.map(this.getInstalmentsValues(), function (value, key) { + var inst; + + if(value["interest"] === 0){ + inst = $t("%1x of %2 not interest").replace("%1",key).replace("%2",value["installment"]); + } else if(value["interest"] < 0){ + inst = $t("%1% of discount cash with total of %2").replace("%1", value["discount"]).replace("%2", value["totalWithTheDiscount"]); } else { - var info_interest = "com juros total de " + value["total_juros"]; + inst = $t("%1x of %2 in the total value of %3").replace("%1",key).replace("%2",value["installment"]).replace("%3",value["totalInstallment"]); } - var inst = key+" x "+ value["parcela"]+" no valor total de " + value["total_parcelado"] + " " + info_interest; - return { - "value": key, - "installments": inst - }; - - }); + + return { + "value": key, + "installments": inst + }; + }); + var newArray = []; for (var i = 0; i < temp.length; i++) { - if (temp[i].installments!="undefined" && temp[i].installments!=undefined) { newArray.push(temp[i]); } } - + return newArray; - } + }, }); }); \ No newline at end of file diff --git a/view/frontend/web/template/cart/summary/moip_interest.html b/view/frontend/web/template/cart/summary/moip_interest.html new file mode 100644 index 0000000..2755795 --- /dev/null +++ b/view/frontend/web/template/cart/summary/moip_interest.html @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/web/template/cart/totals/moip_interest.html b/view/frontend/web/template/cart/totals/moip_interest.html new file mode 100644 index 0000000..0057123 --- /dev/null +++ b/view/frontend/web/template/cart/totals/moip_interest.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/view/frontend/web/template/checkout/cart/totals/moip_interest.html b/view/frontend/web/template/checkout/cart/totals/moip_interest.html new file mode 100644 index 0000000..4a76d03 --- /dev/null +++ b/view/frontend/web/template/checkout/cart/totals/moip_interest.html @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/web/template/checkout/summary/moip_interest.html b/view/frontend/web/template/checkout/summary/moip_interest.html new file mode 100644 index 0000000..7007911 --- /dev/null +++ b/view/frontend/web/template/checkout/summary/moip_interest.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/web/template/payment/boleto.html b/view/frontend/web/template/payment/boleto.html index fa186fb..a7e20c4 100755 --- a/view/frontend/web/template/payment/boleto.html +++ b/view/frontend/web/template/payment/boleto.html @@ -36,11 +36,7 @@
-
- - - -
+
diff --git a/view/frontend/web/template/payment/vault-form.html b/view/frontend/web/template/payment/vault-form.html index 543ff8f..e14e518 100755 --- a/view/frontend/web/template/payment/vault-form.html +++ b/view/frontend/web/template/payment/vault-form.html @@ -65,7 +65,8 @@ options: getInstallments(), optionsValue: 'value', optionsText: 'installments', - optionsCaption: $t('Select Instalmment')"> + optionsCaption: $t('Select Instalmment'), + value: creditCardInstallment">