Skip to content

Commit

Permalink
Moip ♥ Magento 2
Browse files Browse the repository at this point in the history
Reembolso de pedido diretamente pela Magento ;)
  • Loading branch information
elisei committed Jul 8, 2021
1 parent 8d386f5 commit 1b717f3
Show file tree
Hide file tree
Showing 32 changed files with 824 additions and 182 deletions.
124 changes: 124 additions & 0 deletions Block/Adminhtml/Sales/Creditmemo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?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;

use Moip\Magento2\Model\Ui\ConfigProviderBoleto;

class Creditmemo extends \Magento\Backend\Block\Template
{
const BANK_NUMBER = 'moip_magento2_boleto_bank_number';

const AGENCY_NUMBER = 'moip_magento2_boleto_agency_number';

const AGENCY_CHECK_NUMBER = 'moip_magento2_boleto_agency_check_number';

const ACCOUNT_NUMBER = 'moip_magento2_boleto_account_number';

const ACCOUNT_CHECK_NUMBER = 'moip_magento2_boleto_account_check_number';

const HOLDER_FULLNAME = 'moip_magento2_boleto_account_holder_fullname';

const HOLDER_DOCUMENT_NUMBER = 'moip_magento2_boleto_account_holder_document_number';

const CREDITMEMO_COMMENT_TEXT = 'comment_text';

/**
* @var \Magento\Framework\Registry
*/
private $coreRegistry;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->coreRegistry = $registry;
parent::__construct($context, $data);
}

/**
* @return \Magento\Sales\Model\Order\Creditmemo
*/
public function getCreditmemo()
{
return $this->coreRegistry->registry('current_creditmemo');
}

/**
* @return \Magento\Sales\Model\Order
*/
public function getOrder()
{
return $this->getCreditmemo()->getOrder();
}

/**
* Check whether can refund to payment by boleto.
*
* @return bool
*/
public function canRefundBoleto()
{
/** @var \Magento\Sales\Model\Order $order */
$order = $this->getCreditmemo()->getOrder();

if ($order->getPayment()->getMethodInstance()->getCode() === ConfigProviderBoleto::CODE) {
return true;
}

return false;
}

/**
* Json configuration for tooltip.
*
* @parms $field
*
* @return string json
*/
public function getTooltipConfig($field)
{
$tooltipConfig = [
'tooltip' => [
'trigger' => '[data-tooltip-trigger=moip_magento2_tooltip_'.$field.']',
'action' => 'click',
'delay' => 0,
'track' => false,
'position' => 'top',
],
];

return str_replace('"', "'", \Zend_Json::encode($tooltipConfig));
}

public function getBankNumber()
{
return $this->getCreditmemo()->getData(self::BANK_NUMBER);
}

public function getAgencyNumber()
{
return $this->getCreditmemo()->getData(self::AGENCY_NUMBER);
}

public function getAgencyCheckNumber()
{
return $this->getCreditmemo()->getData(self::AGENCY_CHECK_NUMBER);
}

public function getAccountNumber()
{
return $this->getCreditmemo()->getData(self::ACCOUNT_NUMBER);
}

public function getAccountCheckNumber()
{
return $this->getCreditmemo()->getData(self::ACCOUNT_CHECK_NUMBER);
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/PaymentGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ protected function _isCollapseState($element)

return false;
}
}
}
1 change: 1 addition & 0 deletions Block/Customer/CardRenderer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Copyright © Wirecard Brasil. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* See COPYING.txt for license details.
*/
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Order/MassUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function massAction(AbstractCollection $collection)
$method->fetchTransactionInfo($payment, $transactionId);
$payment->getOrder()->save();
$state = $payment->getOrder()->getState();
if($state === "processing") {
if ($state === 'processing') {
$countUpdate++;
}
$countNotUpdate++;
Expand Down
10 changes: 5 additions & 5 deletions Controller/Webhooks/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\CsrfAwareActionInterface as Csrf;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory;
Expand All @@ -27,7 +27,7 @@
/**
* Class Accept - Receives communication for accept payment.
*/
class Accept extends Action implements CsrfAwareActionInterface
class Accept extends Action implements Csrf
{
/**
* createCsrfValidationException.
Expand Down Expand Up @@ -136,12 +136,12 @@ public function execute()
$storeCaptureToken = $this->config->getMerchantGatewayCaptureToken($storeId);
if ($storeCaptureToken === $authorization) {
$data = $originalNotification['resource']['order'];
$order = $this->orderFactory->create()->load($data['ownId'], 'ext_order_id');
$order = $this->orderFactory->create()->load($data['id'], 'ext_order_id');
$this->logger->debug([
'webhook' => 'accept',
'ext_order_id' => $data['ownId'],
'ext_order_id' => $data['id'],
'increment_order_id' => $order->getIncrementId(),
'webhook_data' => $response
'webhook_data' => $response,
]);
$payment = $order->getPayment();
if (!$order->getInvoiceCollection()->count()) {
Expand Down
9 changes: 4 additions & 5 deletions Controller/Webhooks/Deny.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\CsrfAwareActionInterface as Csrf;
use Magento\Framework\App\Request\InvalidRequestException;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Api\Data\OrderInterfaceFactory;
use Magento\Sales\Model\Order\CreditmemoFactory;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Service\CreditmemoService;
use Magento\Store\Model\StoreManagerInterface;
use Moip\Magento2\Gateway\Config\Config;

/**
* Class Deny - Receives communication for deny payment.
*/
class Deny extends Action implements CsrfAwareActionInterface
class Deny extends Action implements Csrf
{
/**
* createCsrfValidationException.
Expand Down Expand Up @@ -149,7 +149,7 @@ public function execute()
'webhook' => 'deny',
'ext_order_id' => $data['id'],
'increment_order_id' => $order->getIncrementId(),
'webhook_data' => $response
'webhook_data' => $response,
]);
$payment = $order->getPayment();
if (!$order->canCancel()) {
Expand Down Expand Up @@ -183,7 +183,6 @@ public function execute()
$order->save();

$this->orderCommentSender->send($order, 1, $cancelDetailsCus);

} catch (\Exception $exc) {
$resultPage->setHttpResponseCode(500);
$resultPage->setJsonData(
Expand Down
Loading

0 comments on commit 1b717f3

Please sign in to comment.