Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra logs #67

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions Block/Payment/Confirm.php

This file was deleted.

2 changes: 1 addition & 1 deletion Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function execute()
$redirectUrl = $order->getPayment()->getAdditionalInformation(PaymentField::REDIRECT_URL_FIELD_NAME);
$paymentId = $order->getPayment()->getAdditionalInformation(PaymentField::PAYMENT_ID_FIELD_NAME);
if ($redirectUrl) {
$this->logger->info(
$this->logger->debug(
'Redirecting to payment provider page',
[
PaymentField::EXTERNAL_ID_FIELD_NAME => $order->getRealOrderId(),
Expand Down
58 changes: 40 additions & 18 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 @@ -116,10 +121,27 @@ private function retrievePaymentStatusAndUpdateOrder()
{
$allPayments = $this->order->getAllPayments();
$lastPaymentId = end($allPayments)->getAdditionalInformation(PaymentField::PAYMENT_ID_FIELD_NAME);
$status = $this->paymentStatusService->getStatus($lastPaymentId);
$loggerContext = [PaymentField::PAYMENT_ID_FIELD_NAME => $lastPaymentId];
$this->logger->info(
"Retrieving payment status",
$loggerContext
);

try {
$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 Down
115 changes: 0 additions & 115 deletions Controller/Payment/Confirm.php

This file was deleted.

7 changes: 5 additions & 2 deletions Controller/Payment/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute()
{
$payload = $this->getRequest()->getContent();
$notificationData = json_decode($payload, true);
$this->logger->debug("Received payment status notification", $notificationData);
$this->logger->info("Received payment status notification", $notificationData);
$storeId = $this->storeManager->getStore()->getId();
$signatureKey = $this->configHelper->getSignatureKey($storeId, $this->configHelper->isTestMode($storeId));

Expand Down Expand Up @@ -118,7 +118,10 @@ public function execute()
);
$this->getResponse()->setHttpResponseCode(400);
} catch (OrderHasBeenAlreadyPaidException $exception) {
$this->logger->info($exception->getMessage() . ' Skip processing the notification.');
$this->logger->info(
$exception->getMessage() . ' Skip processing the notification.',
$notificationData
);
$this->getResponse()->setHttpResponseCode(200);
}
}
Expand Down
Loading