Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
  • Loading branch information
elisei committed Jan 10, 2024
1 parent f98911f commit 818d831
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Controller/AbstractNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ public function filterInvalidNotification($order)
return $result;
}

$state = $order->getState();

if ($state !== Order::STATE_NEW && $state !== Order::STATE_PAYMENT_REVIEW) {
$result = [
'isInvalid' => true,
'code' => 406,
'msg' => __('Not Apply.'),
];

return $result;
}

$result = [
'isInvalid' => false,
];
Expand Down
9 changes: 0 additions & 9 deletions Gateway/Response/FetchPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\InvoiceSender;

/**
Expand Down Expand Up @@ -118,14 +117,6 @@ public function handle(array $handlingSubject, array $response)

$amount = $order->getBaseGrandTotal();

$state = $order->getState();

if ($state !== Order::STATE_NEW && $state !== Order::STATE_PAYMENT_REVIEW) {
throw new LocalizedException(
__('Update not available because the initial state is incompatible: %1', $order->getState())
);
}

if (isset($response[self::RESPONSE_CHARGES])) {
$charges = $response[self::RESPONSE_CHARGES];
$pagbankPayId = $charges[0][self::RESPONSE_PAGBANK_ID];
Expand Down
10 changes: 10 additions & 0 deletions Model/Console/Command/Orders/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use PagBank\PaymentMagento\Model\Console\Command\AbstractModel;

/**
Expand Down Expand Up @@ -157,6 +158,15 @@ public function getMageOrder($incrementId)
$order = null;
$this->writeln('<error>'.__('Order not found').'</error>');
}

$state = $order->getState();

if ($state !== Order::STATE_NEW && $state !== Order::STATE_PAYMENT_REVIEW) {
$this->writeln('<error>'.
__('Update not available because the initial state is incompatible: %1', $order->getState())
.'</error>');
$order = null;
}
} catch (LocalizedException $exc) {
$this->writeln('<error>'.$exc->getMessage().'</error>');
}
Expand Down

0 comments on commit 818d831

Please sign in to comment.