Skip to content

Commit

Permalink
Moip ♥ Magento 2
Browse files Browse the repository at this point in the history
Desconto para pagamento à vista no cartão de crédito
  • Loading branch information
elisei committed Jul 29, 2021
1 parent 6f49309 commit 6fef5b2
Show file tree
Hide file tree
Showing 81 changed files with 2,760 additions and 259 deletions.
43 changes: 43 additions & 0 deletions Api/Data/MoipInterestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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);
}
32 changes: 32 additions & 0 deletions Api/GuestMoipInterestManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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
);
}
32 changes: 32 additions & 0 deletions Api/MoipInterestManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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
);
}
69 changes: 69 additions & 0 deletions Block/Adminhtml/Sales/Order/Creditmemo/Totals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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;
}
}
68 changes: 68 additions & 0 deletions Block/Adminhtml/Sales/Order/Invoice/Totals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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;
}
}
64 changes: 64 additions & 0 deletions Block/Adminhtml/Sales/Order/Totals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* 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;
}
}
Loading

0 comments on commit 6fef5b2

Please sign in to comment.