From 7feff141c9daca2fdbfe81b07a3f705038f53a2f Mon Sep 17 00:00:00 2001 From: Emil Leszczak Date: Thu, 24 Feb 2022 13:56:30 +0100 Subject: [PATCH] Release 1.1.2 --- Controller/Payment/Notifications.php | 5 ++++- Gateway/Http/Client/PaymentAuthorization.php | 6 ++++-- Gateway/Http/Client/PaymentCapture.php | 19 ++++++++++++------- Gateway/Http/Client/PaymentRefund.php | 9 +++++---- Helper/NotificationProcessor.php | 12 ++++++++---- .../OrderHasBeenAlreadyPaidException.php | 2 +- .../Payment/AuthorizationHandlerTest.php | 1 + composer.json | 2 +- etc/module.xml | 2 +- 9 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Controller/Payment/Notifications.php b/Controller/Payment/Notifications.php index 8cc0257..ccacad0 100644 --- a/Controller/Payment/Notifications.php +++ b/Controller/Payment/Notifications.php @@ -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); } } diff --git a/Gateway/Http/Client/PaymentAuthorization.php b/Gateway/Http/Client/PaymentAuthorization.php index 53ab483..b1aa5d3 100644 --- a/Gateway/Http/Client/PaymentAuthorization.php +++ b/Gateway/Http/Client/PaymentAuthorization.php @@ -69,10 +69,12 @@ public function placeRequest(TransferInterface $transferObject) ]; } catch (PaynowException $exception) { $this->logger->error( - $exception->getMessage(), + 'An error occurred during payment authorization', array_merge($loggerContext, [ 'service' => 'Payment', - 'action' => 'authorize' + 'action' => 'authorize', + 'message' => $exception->getMessage(), + 'errors' => $exception->getPrevious()->getErrors() ]) ); foreach ($exception->getErrors() as $error) { diff --git a/Gateway/Http/Client/PaymentCapture.php b/Gateway/Http/Client/PaymentCapture.php index 261595c..2b187f7 100644 --- a/Gateway/Http/Client/PaymentCapture.php +++ b/Gateway/Http/Client/PaymentCapture.php @@ -55,13 +55,18 @@ public function placeRequest(TransferInterface $transferObject) ); } catch (PaynowException $exception) { $response['errors'] = $exception->getMessage(); - $this->logger->error($exception->getMessage(), array_merge( - $loggerContext, - [ - 'service' => 'Payment', - 'action' => 'status' - ] - )); + $this->logger->error( + 'An error occurred during payment authorization', + array_merge( + $loggerContext, + [ + 'service' => 'Payment', + 'action' => 'status', + 'message' => $exception->getMessage(), + 'errors' => $exception->getPrevious()->getErrors() + ] + ) + ); } return $response; diff --git a/Gateway/Http/Client/PaymentRefund.php b/Gateway/Http/Client/PaymentRefund.php index 64a2aa7..7cab967 100644 --- a/Gateway/Http/Client/PaymentRefund.php +++ b/Gateway/Http/Client/PaymentRefund.php @@ -58,8 +58,7 @@ public function placeRequest(TransferInterface $transferObject) ]) ); try { - $service = new Refund($this->client); - $apiResponseObject = $service->create( + $apiResponseObject = (new Refund($this->client))->create( $data[PaymentField::PAYMENT_ID_FIELD_NAME], $transferObject->getHeaders()[PaymentField::IDEMPOTENCY_KEY_FIELD_NAME], $data[RefundField::AMOUNT_FIELD_NAME] @@ -78,10 +77,12 @@ public function placeRequest(TransferInterface $transferObject) ]; } catch (PaynowException $exception) { $this->logger->error( - $exception->getMessage(), + 'An error occurred during refund create', array_merge($loggerContext, [ 'service' => 'Refund', - 'action' => 'create' + 'action' => 'create', + 'message' => $exception->getMessage(), + 'errors' => $exception->getPrevious()->getErrors() ]) ); foreach ($exception->getErrors() as $error) { diff --git a/Helper/NotificationProcessor.php b/Helper/NotificationProcessor.php index 50b7c57..0f606c9 100644 --- a/Helper/NotificationProcessor.php +++ b/Helper/NotificationProcessor.php @@ -90,9 +90,12 @@ public function process($paymentId, $status, $externalId) $this->logger->debug( "Current order state", - array_merge($this->loggerContext, [ - 'currentStatus' => $orderPaymentStatus - ]) + array_merge( + [ + 'currentStatus' => $orderPaymentStatus + ], + $this->loggerContext + ) ); if ($finalPaymentStatus) { @@ -212,7 +215,7 @@ private function paymentRejected() $this->order->addCommentToStatusHistory($message); } - $this->order->getPayment()->setIsClosed(true); + $this->order->getPayment()->setIsClosed(true); } /** @@ -250,6 +253,7 @@ private function isCorrectStatus($previousStatus, $nextStatus): bool { $paymentStatusFlow = [ Status::STATUS_NEW => [ + Status::STATUS_NEW, Status::STATUS_PENDING, Status::STATUS_ERROR, Status::STATUS_EXPIRED, diff --git a/Model/Exception/OrderHasBeenAlreadyPaidException.php b/Model/Exception/OrderHasBeenAlreadyPaidException.php index d3f9198..49d5bf9 100644 --- a/Model/Exception/OrderHasBeenAlreadyPaidException.php +++ b/Model/Exception/OrderHasBeenAlreadyPaidException.php @@ -11,7 +11,7 @@ */ class OrderHasBeenAlreadyPaidException extends Exception { - const EXCEPTION_MESSAGE = 'Order %s has been already paid in %s.'; + const EXCEPTION_MESSAGE = 'An order %s has been already paid in %s.'; public function __construct($orderId, $paymentId) { diff --git a/Test/Unit/Gateway/Response/Payment/AuthorizationHandlerTest.php b/Test/Unit/Gateway/Response/Payment/AuthorizationHandlerTest.php index 044e816..497af8e 100644 --- a/Test/Unit/Gateway/Response/Payment/AuthorizationHandlerTest.php +++ b/Test/Unit/Gateway/Response/Payment/AuthorizationHandlerTest.php @@ -34,6 +34,7 @@ public function testHandle() PaymentField::PAYMENT_ID_FIELD_NAME => 'testPaymentId', PaymentField::STATUS_FIELD_NAME => 'NEW', PaymentField::REDIRECT_URL_FIELD_NAME => 'testRedirectUrl', + PaymentField::EXTERNAL_ID_FIELD_NAME => 'testExternalId', ]; $paymentDO->expects(static::atLeastOnce()) diff --git a/composer.json b/composer.json index caf07c6..77c2a51 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "pay-now/paynow-magento2", "description": "Module for Paynow payments", "type": "magento2-module", - "version": "1.1.1", + "version": "1.1.2", "license": "MIT", "keywords": [ "paynow", diff --git a/etc/module.xml b/etc/module.xml index b3d5b00..5f8deb7 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - +