Skip to content

Commit

Permalink
Revert "Merge branch 'master' into extra-logs"
Browse files Browse the repository at this point in the history
This reverts commit 8d2f560, reversing
changes made to 4d936a0.
  • Loading branch information
Emil Leszczak committed Feb 25, 2022
1 parent 8d2f560 commit 8d3d21f
Show file tree
Hide file tree
Showing 33 changed files with 52 additions and 886 deletions.
51 changes: 0 additions & 51 deletions Block/Payment/Confirm.php

This file was deleted.

47 changes: 28 additions & 19 deletions Controller/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\CsrfAwareActionInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect as ResponseRedirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\UrlInterface;
use Magento\Sales\Model\Order;
use Paynow\PaymentGateway\Helper\NotificationProcessor;
use Paynow\PaymentGateway\Helper\PaymentField;
use Paynow\PaymentGateway\Helper\PaymentStatusService;
use Paynow\PaymentGateway\Helper\PaymentHelper;
use Paynow\PaymentGateway\Model\Logger\Logger;
use Paynow\Service\Payment;

/**
* Class Return
Expand Down Expand Up @@ -39,21 +45,25 @@ class Success extends Action
* @var Order
*/
private $order;
/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;

/**
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var NotificationProcessor
* @var PaymentHelper
*/
private $notificationProcessor;
private $paymentHelper;

/**
* @var PaymentStatusService
* @var NotificationProcessor
*/
private $paymentStatusService;
private $notificationProcessor;

/**
* Redirect constructor.
Expand All @@ -62,34 +72,33 @@ class Success extends Action
* @param Logger $logger
* @param UrlInterface $urlBuilder
* @param NotificationProcessor $notificationProcessor
* @param PaymentStatusService $paymentStatusService
* @param PaymentHelper $paymentHelper
*/
public function __construct(
Context $context,
CheckoutSession $checkoutSession,
Logger $logger,
UrlInterface $urlBuilder,
NotificationProcessor $notificationProcessor,
PaymentStatusService $paymentStatusService
PaymentHelper $paymentHelper
) {
parent::__construct($context);
$this->checkoutSession = $checkoutSession;
$this->logger = $logger;
$this->redirectResult = $this->resultRedirectFactory->create();
$this->request = $this->getRequest();
$this->urlBuilder = $urlBuilder;
$this->notificationProcessor = $notificationProcessor;
$this->paymentHelper = $paymentHelper;
$this->order = $this->checkoutSession->getLastRealOrder();
$this->paymentStatusService = $paymentStatusService;
}

/**
* @return ResponseRedirect
* @return ResponseInterface|ResponseRedirect|ResultInterface
*/
public function execute(): ResponseRedirect
public function execute()
{
$isRetry = $this->order &&
$this->order->getPayment() &&
$this->order->getPayment()->hasAdditionalInformation(PaymentField::IS_PAYMENT_RETRY_FIELD_NAME);
$isRetry = $this->order->getPayment()->hasAdditionalInformation(PaymentField::IS_PAYMENT_RETRY_FIELD_NAME);

if ($this->shouldRetrieveStatus() && ! $isRetry) {
$this->retrievePaymentStatusAndUpdateOrder();
Expand All @@ -99,10 +108,6 @@ public function execute(): ResponseRedirect
return $this->redirectResult;
}

/**
* @param bool $forRetryPayment
* @return string
*/
public function getRedirectUrl(bool $forRetryPayment): string
{
if ($forRetryPayment) {
Expand All @@ -121,13 +126,17 @@ private function retrievePaymentStatusAndUpdateOrder()
"Retrieving payment status",
$loggerContext
);

try {
$status = $this->paymentStatusService->getStatus($lastPaymentId);
$service = new Payment($this->paymentHelper->initializePaynowClient());
$paymentStatusObject = $service->status($lastPaymentId);
$status = $paymentStatusObject ->getStatus();
$this->logger->info(
"Retrieved payment status response",
array_merge($loggerContext, [PaymentField::STATUS_FIELD_NAME => $status])
);
$this->notificationProcessor->process($lastPaymentId, $status, $this->order->getIncrementId());

} catch (\Exception $exception) {
$this->logger->error($exception->getMessage(), $loggerContext);
}
Expand All @@ -136,7 +145,7 @@ private function retrievePaymentStatusAndUpdateOrder()
/**
* @return bool
*/
private function shouldRetrieveStatus(): bool
private function shouldRetrieveStatus()
{
return $this->getRequest()->getParam('paymentStatus') &&
$this->getRequest()->getParam('paymentId') &&
Expand Down
115 changes: 0 additions & 115 deletions Controller/Payment/Confirm.php

This file was deleted.

81 changes: 0 additions & 81 deletions Controller/Payment/Status.php

This file was deleted.

3 changes: 1 addition & 2 deletions Gateway/Http/Client/PaymentAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function placeRequest(TransferInterface $transferObject)
$loggerContext = [
PaymentField::EXTERNAL_ID_FIELD_NAME => $transferObject->getBody()[PaymentField::EXTERNAL_ID_FIELD_NAME]
];

try {
$service = new Payment($this->client);
$apiResponseObject = $service->authorize(
Expand Down Expand Up @@ -81,7 +80,7 @@ public function placeRequest(TransferInterface $transferObject)
foreach ($exception->getErrors() as $error) {
$this->logger->debug($error->getType() . ' - ' . $error->getMessage(), $loggerContext);
}
return ['errors' => $exception->getErrors()];
return $response['errors'] = $exception->getErrors();
}
}
}
Loading

0 comments on commit 8d3d21f

Please sign in to comment.