From 3345b053f842ffd35ebc3084c60016391bca5e7a Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Fri, 18 Aug 2023 11:09:50 +0300 Subject: [PATCH 1/6] BP-2433 - Create more descriptive logging --- Controller/Applepay/AbstractApplepay.php | 12 +- Controller/Applepay/Add.php | 12 +- Controller/Applepay/GetShippingMethods.php | 12 +- Controller/Applepay/SaveOrder.php | 26 ++-- Controller/Applepay/UpdateShippingMethods.php | 8 +- Controller/Checkout/Giftcard.php | 10 +- Controller/Checkout/Idin.php | 12 +- Controller/Payconiq/Process.php | 6 +- Controller/Pos/CheckOrderStatus.php | 10 +- Controller/Pos/SetTerminal.php | 10 +- Controller/Redirect/IdinProcess.php | 6 +- Controller/Redirect/Process.php | 10 +- Cron/LogCleaner.php | 16 +-- Gateway/Http/Client/Json.php | 10 +- .../AddressHandler/AbstractAddressHandler.php | 12 +- .../DHLParcelAddressHandler.php | 10 +- .../DPDPickupAddressHandler.php | 16 +-- .../AddressHandler/MyParcelAddressHandler.php | 22 ++-- .../AddressHandler/PostNLAddressHandler.php | 8 +- .../AbstractArticlesHandler.php | 2 +- Gateway/Response/RefundHandler.php | 2 +- Gateway/Validator/PosPaymentValidator.php | 2 +- Helper/Data.php | 10 +- Helper/PaymentGroupTransaction.php | 14 +-- Logging/BuckarooLoggerInterface.php | 33 +++++ Logging/Log.php | 13 +- Logging/SimplifiedLog.php | 116 ++++++++++++++++++ Model/Adapter/BuckarooAdapter.php | 10 +- Model/Giftcard/Response/Giftcard.php | 4 +- Model/Order/CreditmemoFactory.php | 10 +- Model/PaypalExpress/OrderCreate.php | 10 +- Model/PaypalExpress/QuoteCreate.php | 10 +- Model/Push.php | 20 +-- Model/Push/AfterpayProcessor.php | 10 +- Model/Push/CancelAuthorizeProcessor.php | 4 +- Model/Push/DefaultProcessor.php | 74 +++++------ Model/Push/GroupTransactionPushProcessor.php | 12 +- Model/Push/IdealProcessor.php | 8 +- Model/Push/KlarnaKpProcessor.php | 10 +- Model/Push/KlarnaProcessor.php | 2 +- Model/Push/PayPerEmailProcessor.php | 26 ++-- Model/Push/PaypalProcessor.php | 10 +- Model/Push/RefundProcessor.php | 14 +-- Model/Push/TransferProcessor.php | 8 +- Model/Refund/Push.php | 60 ++++----- Model/RequestPush/RequestPushFactory.php | 18 +-- Model/ResourceModel/Order/Handler/State.php | 14 +-- Model/Service/Order.php | 40 +++--- Model/Service/QuoteAddressService.php | 10 +- Model/Service/QuoteService.php | 10 +- Model/Total/Quote/BuckarooFee.php | 12 +- Model/Total/Quote/Tax/BuckarooFee.php | 8 +- Model/Validator/Push.php | 14 +-- Model/Voucher/ApplyVoucher.php | 10 +- Observer/GroupTransactionRegister.php | 10 +- Observer/HandleFailedQuoteOrder.php | 16 +-- Observer/OrderCancelAfter.php | 14 +-- Observer/SalesOrderShipmentAfter.php | 10 +- Observer/SendInvoiceMail.php | 20 +-- Observer/SendOrderConfirmation.php | 14 +-- Plugin/CommandInterface.php | 20 +-- Plugin/FixSession.php | 10 +- Plugin/GuestSaveManager.php | 10 +- Plugin/MyParcelNLBuckarooPlugin.php | 10 +- Plugin/Onepage/Success.php | 10 +- Service/Applepay/Add.php | 10 +- Service/Formatter/Address/PhoneFormatter.php | 10 +- Service/Push/OrderRequestService.php | 28 ++--- Service/RefundGroupTransactionService.php | 2 +- Service/Sales/Quote/Recreate.php | 10 +- Test/Unit/Model/PushTest.php | 4 +- etc/di.xml | 12 +- 72 files changed, 626 insertions(+), 452 deletions(-) create mode 100644 Logging/BuckarooLoggerInterface.php create mode 100644 Logging/SimplifiedLog.php diff --git a/Controller/Applepay/AbstractApplepay.php b/Controller/Applepay/AbstractApplepay.php index d25feb82b..6e68c2355 100644 --- a/Controller/Applepay/AbstractApplepay.php +++ b/Controller/Applepay/AbstractApplepay.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Controller\Applepay; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\App\Action\HttpPostActionInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\Json; @@ -32,9 +32,9 @@ abstract class AbstractApplepay implements HttpPostActionInterface { /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public Log $logging; + public BuckarooLoggerInterface $logger; /** * @var JsonFactory @@ -49,16 +49,16 @@ abstract class AbstractApplepay implements HttpPostActionInterface /** * @param JsonFactory $resultJsonFactory * @param RequestInterface $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger */ public function __construct( JsonFactory $resultJsonFactory, RequestInterface $request, - Log $logging + BuckarooLoggerInterface $logger ) { $this->resultJsonFactory = $resultJsonFactory; $this->request = $request; - $this->logging = $logging; + $this->logger = $logger; } /** diff --git a/Controller/Applepay/Add.php b/Controller/Applepay/Add.php index 170cb69bb..2e7b57df5 100644 --- a/Controller/Applepay/Add.php +++ b/Controller/Applepay/Add.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Controller\Applepay; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Service\Applepay\Add as AddService; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\Json; @@ -37,19 +37,19 @@ class Add extends AbstractApplepay /** * @param JsonFactory $resultJsonFactory * @param RequestInterface $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param AddService $addService */ public function __construct( JsonFactory $resultJsonFactory, RequestInterface $request, - Log $logging, + BuckarooLoggerInterface $logger, AddService $addService ) { parent::__construct( $resultJsonFactory, $request, - $logging + $logger ); $this->addService = $addService; } @@ -61,10 +61,10 @@ public function __construct( */ public function execute() { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($this->getParams(), true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($this->getParams(), true)); $data = $this->addService->process($this->getParams()); $errorMessage = $data['error'] ?? false; - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($data, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($data, true)); return $this->commonResponse($data, $errorMessage); } diff --git a/Controller/Applepay/GetShippingMethods.php b/Controller/Applepay/GetShippingMethods.php index 36214c74e..1b48834d1 100644 --- a/Controller/Applepay/GetShippingMethods.php +++ b/Controller/Applepay/GetShippingMethods.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Controller\Applepay; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay; use Buckaroo\Magento2\Model\Service\ApplePayFormatData; use Buckaroo\Magento2\Model\Service\QuoteService; @@ -47,21 +47,21 @@ class GetShippingMethods extends AbstractApplepay /** * @param JsonFactory $resultJsonFactory * @param RequestInterface $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param QuoteService $quoteService * @param ApplePayFormatData $applePayFormatData */ public function __construct( JsonFactory $resultJsonFactory, RequestInterface $request, - Log $logging, + BuckarooLoggerInterface $logger, QuoteService $quoteService, ApplePayFormatData $applePayFormatData ) { parent::__construct( $resultJsonFactory, $request, - $logging + $logger ); $this->quoteService = $quoteService; $this->applePayFormatData = $applePayFormatData; @@ -75,7 +75,7 @@ public function __construct( public function execute() { $postValues = $this->getParams(); - $this->logging->addDebug(__METHOD__ . '|1| post Values: ' . var_export($postValues, true)); + $this->logger->addDebug(__METHOD__ . '|1| post Values: ' . var_export($postValues, true)); $data = []; $errorMessage = false; @@ -114,7 +114,7 @@ public function execute() 'totals' => $totals ]; } catch (\Exception $exception) { - $this->logging->addDebug(__METHOD__ . '|exception|' . $exception->getMessage()); + $this->logger->addDebug(__METHOD__ . '|exception|' . $exception->getMessage()); $errorMessage = __( 'Get shipping methods failed' ); diff --git a/Controller/Applepay/SaveOrder.php b/Controller/Applepay/SaveOrder.php index ba47ff587..e3edcf4c9 100644 --- a/Controller/Applepay/SaveOrder.php +++ b/Controller/Applepay/SaveOrder.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Controller\Applepay; use Buckaroo\Magento2\Exception; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Factory as ConfigProviderFactory; use Buckaroo\Magento2\Model\Service\QuoteAddressService; use Magento\Checkout\Model\ConfigProviderInterface; @@ -101,7 +101,7 @@ class SaveOrder extends AbstractApplepay * * @param JsonFactory $resultJsonFactory * @param RequestInterface $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param QuoteManagement $quoteManagement * @param CustomerSession $customerSession * @param DataObjectFactory $objectFactory @@ -119,7 +119,7 @@ class SaveOrder extends AbstractApplepay public function __construct( JsonFactory $resultJsonFactory, RequestInterface $request, - Log $logging, + BuckarooLoggerInterface $logger, QuoteManagement $quoteManagement, CustomerSession $customerSession, DataObjectFactory $objectFactory, @@ -133,7 +133,7 @@ public function __construct( parent::__construct( $resultJsonFactory, $request, - $logging + $logger ); $this->quoteManagement = $quoteManagement; @@ -167,9 +167,9 @@ public function execute() && ($payment = $isPost['payment']) && ($extra = $isPost['extra']) ) { - $this->logging->addDebug(__METHOD__ . '|1|'); - $this->logging->addDebug(var_export($payment, true)); - $this->logging->addDebug(var_export($extra, true)); + $this->logger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(var_export($payment, true)); + $this->logger->addDebug(var_export($extra, true)); // Get Cart $quote = $this->checkoutSession->getQuote(); @@ -202,7 +202,7 @@ public function execute() */ private function submitQuote($quote, $extra) { - $this->logging->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(__METHOD__ . '|2|'); try { if (!($this->customerSession->getCustomer() && $this->customerSession->getCustomer()->getId())) { @@ -222,7 +222,7 @@ private function submitQuote($quote, $extra) $this->quoteManagement->submit($quote); } catch (\Throwable $th) { - $this->logging->addDebug(__METHOD__ . '|exception|' . var_export($th->getMessage(), true)); + $this->logger->addDebug(__METHOD__ . '|exception|' . var_export($th->getMessage(), true)); } } @@ -236,16 +236,16 @@ private function handleResponse() $data = []; if ($this->registry && $this->registry->registry('buckaroo_response')) { $data = $this->registry->registry('buckaroo_response')[0]; - $this->logging->addDebug(__METHOD__ . '|4|' . var_export($data, true)); + $this->logger->addDebug(__METHOD__ . '|4|' . var_export($data, true)); if (!empty($data->RequiredAction->RedirectURL)) { //test mode - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); $data = [ 'RequiredAction' => $data->RequiredAction ]; } else { //live mode - $this->logging->addDebug(__METHOD__ . '|6|'); + $this->logger->addDebug(__METHOD__ . '|6|'); if (isset($data['Status']['Code']['Code']) && $data['Status']['Code']['Code'] == '190' && isset($data['Order']) ) { @@ -279,7 +279,7 @@ private function processBuckarooResponse(&$data) $store = $order->getStore(); $url = $store->getBaseUrl() . '/' . $this->accountConfig->getSuccessRedirect($store); - $this->logging->addDebug(__METHOD__ . '|7|' . var_export($url, true)); + $this->logger->addDebug(__METHOD__ . '|7|' . var_export($url, true)); $data = [ 'RequiredAction' => [ 'RedirectURL' => $url diff --git a/Controller/Applepay/UpdateShippingMethods.php b/Controller/Applepay/UpdateShippingMethods.php index 1424106e5..8c4f279b5 100644 --- a/Controller/Applepay/UpdateShippingMethods.php +++ b/Controller/Applepay/UpdateShippingMethods.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Controller\Applepay; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\Result\JsonFactory; @@ -41,21 +41,21 @@ class UpdateShippingMethods extends AbstractApplepay /** * @param JsonFactory $resultJsonFactory * @param RequestInterface $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param QuoteRepository $quoteRepository * @param CheckoutSession $checkoutSession */ public function __construct( JsonFactory $resultJsonFactory, RequestInterface $request, - Log $logging, + BuckarooLoggerInterface $logger, QuoteRepository $quoteRepository, CheckoutSession $checkoutSession ) { parent::__construct( $resultJsonFactory, $request, - $logging + $logger ); $this->checkoutSession = $checkoutSession; diff --git a/Controller/Checkout/Giftcard.php b/Controller/Checkout/Giftcard.php index 9cd37224b..4d26ec3cb 100644 --- a/Controller/Checkout/Giftcard.php +++ b/Controller/Checkout/Giftcard.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Controller\Checkout; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Giftcard\Api\ApiException; use Buckaroo\Magento2\Model\Giftcard\Request\GiftcardInterface; use Buckaroo\Magento2\Model\Giftcard\Response\Giftcard as GiftcardResponse; @@ -38,9 +38,9 @@ class Giftcard extends Action implements HttpPostActionInterface, HttpGetActionInterface { /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var GiftcardInterface @@ -62,14 +62,14 @@ class Giftcard extends Action implements HttpPostActionInterface, HttpGetActionI * @param Session $checkoutSession * @param GiftcardInterface $giftcardRequest * @param GiftcardResponse $giftcardResponse - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( Context $context, Session $checkoutSession, GiftcardInterface $giftcardRequest, GiftcardResponse $giftcardResponse, - Log $logger + BuckarooLoggerInterface $logger ) { parent::__construct($context); $this->checkoutSession = $checkoutSession; diff --git a/Controller/Checkout/Idin.php b/Controller/Checkout/Idin.php index d740e058a..6f7f48288 100644 --- a/Controller/Checkout/Idin.php +++ b/Controller/Checkout/Idin.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Controller\Checkout; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Transaction\Response\TransactionResponse; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; @@ -46,9 +46,9 @@ class Idin extends Action */ protected ClientInterface $clientInterface; /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logger; + private BuckarooLoggerInterface $logger; /** * @@ -56,14 +56,14 @@ class Idin extends Action * @param BuilderInterface $requestDataBuilder * @param TransferFactoryInterface $transferFactory * @param ClientInterface $clientInterface - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( Context $context, BuilderInterface $requestDataBuilder, TransferFactoryInterface $transferFactory, ClientInterface $clientInterface, - Log $logger + BuckarooLoggerInterface $logger ) { parent::__construct($context); $this->logger = $logger; @@ -108,7 +108,7 @@ public function execute() ); } } catch (\Throwable $th) { - $this->logger->debug($th->getMessage()); + $this->logger->addError($th->getMessage()); return $this->json( ['error' => 'Unknown buckaroo error occurred'] ); diff --git a/Controller/Payconiq/Process.php b/Controller/Payconiq/Process.php index 9fcc965d5..66c53d4b4 100644 --- a/Controller/Payconiq/Process.php +++ b/Controller/Payconiq/Process.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Controller\Payconiq; use Buckaroo\Magento2\Exception; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account as AccountConfig; use Buckaroo\Magento2\Model\OrderStatusFactory; @@ -66,7 +66,7 @@ class Process extends \Buckaroo\Magento2\Controller\Redirect\Process /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Quote $quote * @param AccountConfig $accountConfig * @param OrderRequestService $orderRequestService @@ -85,7 +85,7 @@ class Process extends \Buckaroo\Magento2\Controller\Redirect\Process */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, Quote $quote, AccountConfig $accountConfig, OrderRequestService $orderRequestService, diff --git a/Controller/Pos/CheckOrderStatus.php b/Controller/Pos/CheckOrderStatus.php index bc2a9ccbc..c5da97a6c 100644 --- a/Controller/Pos/CheckOrderStatus.php +++ b/Controller/Pos/CheckOrderStatus.php @@ -22,7 +22,7 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Factory; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Customer\Model\Session; @@ -41,9 +41,9 @@ class CheckOrderStatus extends Action { /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var Order $order @@ -87,7 +87,7 @@ class CheckOrderStatus extends Action /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Order $order * @param JsonFactory $resultJsonFactory * @param Factory $configProviderFactory @@ -102,7 +102,7 @@ class CheckOrderStatus extends Action */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, Order $order, JsonFactory $resultJsonFactory, Factory $configProviderFactory, diff --git a/Controller/Pos/SetTerminal.php b/Controller/Pos/SetTerminal.php index 8dd85ea33..d9d0c1830 100644 --- a/Controller/Pos/SetTerminal.php +++ b/Controller/Pos/SetTerminal.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Controller\Pos; use Buckaroo\Magento2\Exception as BuckarooException; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Factory; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Framework\App\Action\Action; @@ -44,9 +44,9 @@ class SetTerminal extends Action protected $accountConfig; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var StoreManagerInterface @@ -65,7 +65,7 @@ class SetTerminal extends Action /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Factory $configProviderFactory * @param StoreManagerInterface $storemanager * @param CookieManagerInterface $cookieManager @@ -74,7 +74,7 @@ class SetTerminal extends Action */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, Factory $configProviderFactory, StoreManagerInterface $storemanager, CookieManagerInterface $cookieManager, diff --git a/Controller/Redirect/IdinProcess.php b/Controller/Redirect/IdinProcess.php index e329e6dc4..e89139be8 100644 --- a/Controller/Redirect/IdinProcess.php +++ b/Controller/Redirect/IdinProcess.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Controller\Redirect; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account as AccountConfig; use Buckaroo\Magento2\Model\OrderStatusFactory; use Buckaroo\Magento2\Model\RequestPush\RequestPushFactory; @@ -50,7 +50,7 @@ class IdinProcess extends Process /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Quote $quote * @param AccountConfig $accountConfig * @param OrderRequestService $orderRequestService @@ -68,7 +68,7 @@ class IdinProcess extends Process */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, Quote $quote, AccountConfig $accountConfig, OrderRequestService $orderRequestService, diff --git a/Controller/Redirect/Process.php b/Controller/Redirect/Process.php index f5e4f8f4c..cfa8c38c4 100644 --- a/Controller/Redirect/Process.php +++ b/Controller/Redirect/Process.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Controller\Redirect; use Buckaroo\Magento2\Api\PushRequestInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account as AccountConfig; use Buckaroo\Magento2\Model\Method\BuckarooAdapter; @@ -86,9 +86,9 @@ class Process extends Action protected OrderStatusFactory $orderStatusFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var CheckoutSession @@ -127,7 +127,7 @@ class Process extends Action /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Quote $quote * @param AccountConfig $accountConfig * @param OrderRequestService $orderRequestService @@ -143,7 +143,7 @@ class Process extends Action */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, Quote $quote, AccountConfig $accountConfig, OrderRequestService $orderRequestService, diff --git a/Cron/LogCleaner.php b/Cron/LogCleaner.php index a7ff01d77..979401c6b 100644 --- a/Cron/LogCleaner.php +++ b/Cron/LogCleaner.php @@ -22,7 +22,7 @@ use Buckaroo\Magento2\Model\ConfigProvider\Account; use Magento\Framework\App\ResourceConnection; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ResourceModel\Log as LogResourceModel; use Buckaroo\Magento2\Model\Config\Source\LogHandler; use Magento\Framework\Filesystem\DirectoryList; @@ -48,9 +48,9 @@ class LogCleaner private $resourceConnection; /** - * @var Log + * @var BuckarooLoggerInterface */ - private $logging; + private BuckarooLoggerInterface $logger; /** * @var DirectoryList @@ -73,7 +73,7 @@ class LogCleaner * @param LogResourceModel $resource * @param Account $accountConfig * @param ResourceConnection $resourceConnection - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param DirectoryList $directoryList * @param File $driverFile * @param IoFile $ioFile @@ -82,7 +82,7 @@ public function __construct( LogResourceModel $resource, Account $accountConfig, ResourceConnection $resourceConnection, - Log $logging, + BuckarooLoggerInterface $logger, DirectoryList $directoryList, File $driverFile, IoFile $ioFile @@ -90,7 +90,7 @@ public function __construct( $this->resource = $resource; $this->accountConfig = $accountConfig; $this->resourceConnection = $resourceConnection; - $this->logging = $logging; + $this->logger = $logger; $this->directoryList = $directoryList; $this->driverFile = $driverFile; $this->ioFile = $ioFile; @@ -129,7 +129,7 @@ private function proceedDb(int $retentionPeriod) ['time <= date_sub(now(),interval ' . $retentionPeriod . ' second)'] ); } catch (\Exception $e) { - $this->logging->error('Proceed Db error:' . var_export($e->getMessage(), true)); + $this->logger->error('Proceed Db error:' . var_export($e->getMessage(), true)); } } @@ -168,7 +168,7 @@ private function getAllFiles(string $path): array $path = $this->directoryList->getPath('var') . $path; $paths = $this->driverFile->readDirectory($path); } catch (FileSystemException $e) { - $this->logging->error('Get All Files error:' . var_export($e->getMessage(), true)); + $this->logger->error('Get All Files error:' . var_export($e->getMessage(), true)); } return $paths; diff --git a/Gateway/Http/Client/Json.php b/Gateway/Http/Client/Json.php index 0072da3d0..0166bdc1f 100644 --- a/Gateway/Http/Client/Json.php +++ b/Gateway/Http/Client/Json.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Gateway\Http\Client; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\HTTP\Client\Curl; class Json @@ -32,9 +32,9 @@ class Json private $client; /** - * @var Log + * @var BuckarooLoggerInterface */ - private $logger; + private BuckarooLoggerInterface $logger; /** * @var string @@ -48,11 +48,11 @@ class Json /** * @param Curl $client - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( Curl $client, - Log $logger + BuckarooLoggerInterface $logger ) { $this->client = $client; $this->logger = $logger; diff --git a/Gateway/Request/AddressHandler/AbstractAddressHandler.php b/Gateway/Request/AddressHandler/AbstractAddressHandler.php index 3c0280234..2575a0a04 100644 --- a/Gateway/Request/AddressHandler/AbstractAddressHandler.php +++ b/Gateway/Request/AddressHandler/AbstractAddressHandler.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Gateway\Request\AddressHandler; use Buckaroo\Magento2\Api\AddressHandlerInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; /** * The default chaining behavior can be implemented inside a base handler class. @@ -30,17 +30,17 @@ abstract class AbstractAddressHandler implements AddressHandlerInterface { /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $buckarooLogger; + protected BuckarooLoggerInterface $logger; /** - * @param Log $buckarooLogger + * @param BuckarooLoggerInterface $logger */ public function __construct( - Log $buckarooLogger + BuckarooLoggerInterface $logger ) { - $this->buckarooLogger = $buckarooLogger; + $this->logger = $logger; } /** diff --git a/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php b/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php index 1518bdbd7..ae8754b13 100644 --- a/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php +++ b/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Gateway\Request\AddressHandler; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\HTTP\Client\Curl; use Magento\Sales\Api\Data\OrderAddressInterface; use Magento\Sales\Model\Order; @@ -35,13 +35,13 @@ class DHLParcelAddressHandler extends AbstractAddressHandler private Curl $curl; /** - * @param Log $buckarooLogger + * @param BuckarooLoggerInterface $logger * @param Curl $curl */ - public function __construct(Log $buckarooLogger, Curl $curl) + public function __construct(BuckarooLoggerInterface $logger, Curl $curl) { $this->curl = $curl; - parent::__construct($buckarooLogger); + parent::__construct($logger); } /** @@ -71,7 +71,7 @@ public function handle(Order $order, OrderAddressInterface $shippingAddress): Or */ public function updateShippingAddressByDhlParcel(string $servicePointId, OrderAddressInterface $shippingAddress) { - $this->buckarooLogger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); $matches = []; if (preg_match('/^(.*)-([A-Z]{2})-(.*)$/', $servicePointId, $matches)) { $this->curl->get( diff --git a/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php b/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php index 7dca6f2d6..f3bbdae7e 100644 --- a/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php +++ b/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Gateway\Request\AddressHandler; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Api\Data\CartInterface; @@ -37,13 +37,13 @@ class DPDPickupAddressHandler extends AbstractAddressHandler protected CartRepositoryInterface $quoteRepository; /** - * @param Log $buckarooLogger + * @param BuckarooLoggerInterface $logger * @param CartRepositoryInterface $quoteRepository */ - public function __construct(Log $buckarooLogger, CartRepositoryInterface $quoteRepository) + public function __construct(BuckarooLoggerInterface $logger, CartRepositoryInterface $quoteRepository) { $this->quoteRepository = $quoteRepository; - parent::__construct($buckarooLogger); + parent::__construct($logger); } /** @@ -84,8 +84,8 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r $country = $quote->getDpdCountry(); if (!$fullStreet && $quote->getDpdParcelshopId()) { - $this->buckarooLogger->addDebug(__METHOD__ . '|2|'); - $this->buckarooLogger->addDebug(var_export($_COOKIE, true)); + $this->logger->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(var_export($_COOKIE, true)); $fullStreet = $_COOKIE['dpd-selected-parcelshop-street'] ?? ''; $postalCode = $_COOKIE['dpd-selected-parcelshop-zipcode'] ?? ''; $city = $_COOKIE['dpd-selected-parcelshop-city'] ?? ''; @@ -94,7 +94,7 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r $matches = false; if ($fullStreet && preg_match('/(.*)\s(.+)$/', $fullStreet, $matches)) { - $this->buckarooLogger->addDebug(__METHOD__ . '|3|'); + $this->logger->addDebug(__METHOD__ . '|3|'); $street = $matches[1]; $streetHouseNumber = $matches[2]; @@ -107,7 +107,7 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r ['StreetNumber', $streetHouseNumber], ]; - $this->buckarooLogger->addDebug(var_export($mapping, true)); + $this->logger->addDebug(var_export($mapping, true)); $this->updateShippingAddressCommonMapping($mapping, $requestData); diff --git a/Gateway/Request/AddressHandler/MyParcelAddressHandler.php b/Gateway/Request/AddressHandler/MyParcelAddressHandler.php index 52a37a718..b7985de27 100644 --- a/Gateway/Request/AddressHandler/MyParcelAddressHandler.php +++ b/Gateway/Request/AddressHandler/MyParcelAddressHandler.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Gateway\Request\AddressHandler; use Buckaroo\Magento2\Helper\Data as BuckarooHelper; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Sales\Api\Data\OrderAddressInterface; use Magento\Sales\Model\Order; @@ -34,13 +34,13 @@ class MyParcelAddressHandler extends AbstractAddressHandler public BuckarooHelper $helper; /** - * @param Log $buckarooLogger + * @param BuckarooLoggerInterface $logger * @param BuckarooHelper $helper */ - public function __construct(Log $buckarooLogger, BuckarooHelper $helper) + public function __construct(BuckarooLoggerInterface $logger, BuckarooHelper $helper) { $this->helper = $helper; - parent::__construct($buckarooLogger); + parent::__construct($logger); } /** @@ -54,7 +54,7 @@ public function __construct(Log $buckarooLogger, BuckarooHelper $helper) */ public function handle(Order $order, OrderAddressInterface $shippingAddress): Order { - $this->buckarooLogger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); $myparcelFetched = false; $myparcelOptions = $order->getData('myparcel_delivery_options'); $requestData = $shippingAddress->getData(); @@ -70,25 +70,25 @@ public function handle(Order $order, OrderAddressInterface $shippingAddress): Or $myparcelFetched = true; } } catch (\JsonException $je) { - $this->buckarooLogger->addDebug( + $this->logger->addDebug( __METHOD__ . '|2|' . ' Error related to json_decode (MyParcel plugin compatibility)' ); } } if (!$myparcelFetched) { - $this->buckarooLogger->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); if ((strpos((string)$order->getShippingMethod(), 'myparcelnl') !== false) && (strpos((string)$order->getShippingMethod(), 'pickup') !== false) ) { - $this->buckarooLogger->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); if ($this->helper->getCheckoutSession()->getMyParcelNLBuckarooData() && $myParcelNLData = $this->helper->getJson()->unserialize( $this->helper->getCheckoutSession()->getMyParcelNLBuckarooData() ) ) { - $this->buckarooLogger->addDebug(__METHOD__ . '|20|'); + $this->logger->addDebug(__METHOD__ . '|20|'); $this->updateShippingAddressByMyParcel($myParcelNLData, $requestData); } } @@ -116,7 +116,7 @@ protected function updateShippingAddressByMyParcel(array $myParcelLocation, arra ['ShippingHouseNumberSuffix', $myParcelLocation['number_suffix']], ]; - $this->buckarooLogger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); $this->updateShippingAddressCommonMappingV2($mapping, $requestData); } @@ -139,7 +139,7 @@ protected function updateShippingAddressByMyParcelV2(array $myParcelLocation, ar ['StreetNumberAdditional', $myParcelLocation['number_suffix']], ]; - $this->buckarooLogger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); $this->updateShippingAddressCommonMapping($mapping, $requestData); } diff --git a/Gateway/Request/AddressHandler/PostNLAddressHandler.php b/Gateway/Request/AddressHandler/PostNLAddressHandler.php index 630a9a113..1729442ae 100644 --- a/Gateway/Request/AddressHandler/PostNLAddressHandler.php +++ b/Gateway/Request/AddressHandler/PostNLAddressHandler.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Gateway\Request\AddressHandler; use Buckaroo\Magento2\Api\AddressUpdaterInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Quote\Model\Quote\Address; use Magento\Quote\Model\Quote\AddressFactory; use Magento\Sales\Api\Data\OrderAddressInterface; @@ -36,13 +36,13 @@ class PostNLAddressHandler extends AbstractAddressHandler protected $addressFactory; /** - * @param Log $buckarooLogger + * @param BuckarooLoggerInterface $logger * @param AddressFactory $addressFactory */ - public function __construct(Log $buckarooLogger, AddressFactory $addressFactory) + public function __construct(BuckarooLoggerInterface $logger, AddressFactory $addressFactory) { $this->addressFactory = $addressFactory; - parent::__construct($buckarooLogger); + parent::__construct($logger); } /** diff --git a/Gateway/Request/Articles/ArticlesHandler/AbstractArticlesHandler.php b/Gateway/Request/Articles/ArticlesHandler/AbstractArticlesHandler.php index c36bba634..9c5b0df9e 100644 --- a/Gateway/Request/Articles/ArticlesHandler/AbstractArticlesHandler.php +++ b/Gateway/Request/Articles/ArticlesHandler/AbstractArticlesHandler.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Gateway\Request\Articles\ArticlesHandler; use Buckaroo\Magento2\Api\ArticleHandlerInterface; -use Buckaroo\Magento2\Logging\Log as BuckarooLog; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface as BuckarooLog; use Buckaroo\Magento2\Model\ConfigProvider\BuckarooFee; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory as ConfigProviderMethodFactory; use Buckaroo\Magento2\Service\PayReminderService; diff --git a/Gateway/Response/RefundHandler.php b/Gateway/Response/RefundHandler.php index a2c117e22..ef9465db6 100644 --- a/Gateway/Response/RefundHandler.php +++ b/Gateway/Response/RefundHandler.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Gateway\Helper\SubjectReader; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log as BuckarooLog; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface as BuckarooLog; use Buckaroo\Magento2\Model\Push; use Buckaroo\Magento2\Model\Push\DefaultProcessor; use Buckaroo\Transaction\Response\TransactionResponse; diff --git a/Gateway/Validator/PosPaymentValidator.php b/Gateway/Validator/PosPaymentValidator.php index b77982d3d..dc58cecf8 100644 --- a/Gateway/Validator/PosPaymentValidator.php +++ b/Gateway/Validator/PosPaymentValidator.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Gateway\Validator; -use Buckaroo\Magento2\Logging\Log as BuckarooLog; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface as BuckarooLog; use Magento\Framework\HTTP\Header; use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Payment\Gateway\Validator\AbstractValidator; diff --git a/Helper/Data.php b/Helper/Data.php index ba74f72dd..644fb443c 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Helper; use Buckaroo\Magento2\Exception as BuckarooException; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Config\Source\Business; use Buckaroo\Magento2\Service\CheckPaymentType; use Buckaroo\Magento2\Model\ConfigProvider\Account; @@ -120,9 +120,9 @@ class Data extends AbstractHelper protected $groupTransaction; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var CustomerRepositoryInterface @@ -166,7 +166,7 @@ class Data extends AbstractHelper * @param Header $httpHeader * @param CheckoutSession $checkoutSession * @param PaymentGroupTransaction $groupTransaction - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param CustomerRepositoryInterface $customerRepository * @param StoreManagerInterface $storeManager * @param ScopeDefiner $scopeDefiner @@ -183,7 +183,7 @@ public function __construct( Header $httpHeader, CheckoutSession $checkoutSession, PaymentGroupTransaction $groupTransaction, - Log $logger, + BuckarooLoggerInterface $logger, CustomerRepositoryInterface $customerRepository, StoreManagerInterface $storeManager, ScopeDefiner $scopeDefiner, diff --git a/Helper/PaymentGroupTransaction.php b/Helper/PaymentGroupTransaction.php index 8b75f9d56..f3158ebba 100644 --- a/Helper/PaymentGroupTransaction.php +++ b/Helper/PaymentGroupTransaction.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Helper; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\GroupTransactionFactory; use Buckaroo\Magento2\Model\ResourceModel\GroupTransaction; use Buckaroo\Magento2\Model\ResourceModel\GroupTransaction\CollectionFactory as GroupTransactionCollectionFactory; @@ -51,9 +51,9 @@ class PaymentGroupTransaction extends AbstractHelper protected $resourceModel; /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logging; + private BuckarooLoggerInterface $logger; /** * Constructor @@ -61,7 +61,7 @@ class PaymentGroupTransaction extends AbstractHelper * @param Context $context * @param GroupTransactionFactory $groupTransactionFactory * @param DateTime $dateTime - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param GroupTransactionCollectionFactory $grTrCollectionFactory * @param GroupTransaction $resourceModel */ @@ -69,7 +69,7 @@ public function __construct( Context $context, GroupTransactionFactory $groupTransactionFactory, DateTime $dateTime, - Log $logging, + BuckarooLoggerInterface $logger, GroupTransactionCollectionFactory $grTrCollectionFactory, GroupTransaction $resourceModel ) { @@ -77,7 +77,7 @@ public function __construct( $this->groupTransactionFactory = $groupTransactionFactory; $this->dateTime = $dateTime; - $this->logging = $logging; + $this->logger = $logger; $this->grTrCollectionFactory = $grTrCollectionFactory; $this->resourceModel = $resourceModel; } @@ -90,7 +90,7 @@ public function __construct( */ public function saveGroupTransaction($response) { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($response, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($response, true)); $groupTransaction = $this->groupTransactionFactory->create(); $data['order_id'] = $response['Invoice']; $data['transaction_id'] = $response['Key']; diff --git a/Logging/BuckarooLoggerInterface.php b/Logging/BuckarooLoggerInterface.php new file mode 100644 index 000000000..546e9acaa --- /dev/null +++ b/Logging/BuckarooLoggerInterface.php @@ -0,0 +1,33 @@ +addRecord(Logger::ERROR, $message); } + /** + * Logs a warning message. + * + * @param string $message + * @return bool + */ + public function addWarning(string $message): bool + { + return $this->addRecord(Logger::WARNING, $message); + } + /** * @inheritdoc */ diff --git a/Logging/SimplifiedLog.php b/Logging/SimplifiedLog.php new file mode 100644 index 000000000..72ee4e5fd --- /dev/null +++ b/Logging/SimplifiedLog.php @@ -0,0 +1,116 @@ +debugConfiguration = $debugConfiguration; + + parent::__construct($name, $handlers, $processors); + } + + /** + * @inheritdoc + */ + public function addRecord( + int $level, + string $message, + array $context = [], + DateTimeImmutable $datetime = null + ): bool { + if (!$this->debugConfiguration->canLog($level)) { + return false; + } + + return parent::addRecord($level, $message, $context); + } + + /** + * Logs a debug message. + * + * @param string $message + * @return bool + */ + public function addDebug(string $message): bool + { + return $this->addRecord(Logger::DEBUG, $message); + } + + /** + * Logs an error message. + * + * @param string $message + * @return bool + */ + public function addError(string $message): bool + { + return $this->addRecord(Logger::ERROR, $message); + } + + /** + * Logs a warning message. + * + * @param string $message + * @return bool + */ + public function addWarning(string $message): bool + { + return $this->addRecord(Logger::WARNING, $message); + } + + /** + * @inheritdoc + */ + public function debug($message, array $context = []): void + { + $this->addRecord(Logger::DEBUG, (string) $message, $context); + } +} diff --git a/Model/Adapter/BuckarooAdapter.php b/Model/Adapter/BuckarooAdapter.php index 3283dc873..d958d599e 100644 --- a/Model/Adapter/BuckarooAdapter.php +++ b/Model/Adapter/BuckarooAdapter.php @@ -27,7 +27,7 @@ use Buckaroo\Exceptions\BuckarooException; use Buckaroo\Handlers\Reply\ReplyHandler; use Buckaroo\Magento2\Gateway\Request\CreditManagement\BuilderComposite; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Service\Software\Data; use Buckaroo\Transaction\Response\TransactionResponse; @@ -51,9 +51,9 @@ class BuckarooAdapter protected Encryptor $encryptor; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var array|null @@ -63,7 +63,7 @@ class BuckarooAdapter /** * @param Account $configProviderAccount * @param Encryptor $encryptor - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param ProductMetadataInterface $productMetadata * @param Resolver $localeResolver * @param array|null $mapPaymentMethods @@ -72,7 +72,7 @@ class BuckarooAdapter public function __construct( Account $configProviderAccount, Encryptor $encryptor, - Log $logger, + BuckarooLoggerInterface $logger, ProductMetadataInterface $productMetadata, Resolver $localeResolver, array $mapPaymentMethods = null diff --git a/Model/Giftcard/Response/Giftcard.php b/Model/Giftcard/Response/Giftcard.php index 6eb3a1bc7..cdacf527a 100644 --- a/Model/Giftcard/Response/Giftcard.php +++ b/Model/Giftcard/Response/Giftcard.php @@ -30,7 +30,7 @@ use Magento\Framework\Model\AbstractExtensibleModel; use Magento\Framework\Pricing\PriceCurrencyInterface; use Buckaroo\Magento2\Model\Giftcard\Remove as GiftcardRemove; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Sales\Api\Data\OrderInterface; /** @@ -81,7 +81,7 @@ public function __construct( QuoteManagement $quoteManagement, OrderManagementInterface $orderManagement, GiftcardRemove $giftcardRemoveService, - Log $logger + BuckarooLoggerInterface $logger ) { $this->priceCurrency = $priceCurrency; $this->groupTransaction = $groupTransaction; diff --git a/Model/Order/CreditmemoFactory.php b/Model/Order/CreditmemoFactory.php index 28d629e30..37fafca66 100644 --- a/Model/Order/CreditmemoFactory.php +++ b/Model/Order/CreditmemoFactory.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Model\Order; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\Unserialize\Unserialize; use Magento\Sales\Model\Convert\Order as ConvertOrder; @@ -55,22 +55,22 @@ class CreditmemoFactory extends MagentoCreditmemoFactory protected $unserialize; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * Factory constructor * * @param OrderFactory $convertOrderFactory * @param Config $taxConfig - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Json|null $serializer */ public function __construct( OrderFactory $convertOrderFactory, Config $taxConfig, - Log $logger, + BuckarooLoggerInterface $logger, Json $serializer = null ) { $this->logger = $logger; diff --git a/Model/PaypalExpress/OrderCreate.php b/Model/PaypalExpress/OrderCreate.php index cdd64a73c..c0a469f0d 100644 --- a/Model/PaypalExpress/OrderCreate.php +++ b/Model/PaypalExpress/OrderCreate.php @@ -22,7 +22,7 @@ use Buckaroo\Magento2\Api\Data\PaypalExpress\OrderCreateResponseInterfaceFactory; use Buckaroo\Magento2\Api\PaypalExpressOrderCreateInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\PaypalExpress\OrderUpdateShippingFactory; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session as CustomerSession; @@ -81,9 +81,9 @@ class OrderCreate implements PaypalExpressOrderCreateInterface protected $orderUpdateShippingFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @param OrderCreateResponseInterfaceFactory $responseFactory @@ -94,7 +94,7 @@ class OrderCreate implements PaypalExpressOrderCreateInterface * @param CartRepositoryInterface $quoteRepository * @param OrderRepositoryInterface $orderRepository * @param OrderUpdateShippingFactory $orderUpdateShippingFactory - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( OrderCreateResponseInterfaceFactory $responseFactory, @@ -105,7 +105,7 @@ public function __construct( CartRepositoryInterface $quoteRepository, OrderRepositoryInterface $orderRepository, OrderUpdateShippingFactory $orderUpdateShippingFactory, - Log $logger + BuckarooLoggerInterface $logger ) { $this->responseFactory = $responseFactory; $this->quoteManagement = $quoteManagement; diff --git a/Model/PaypalExpress/QuoteCreate.php b/Model/PaypalExpress/QuoteCreate.php index 287604ca8..97d4238dd 100644 --- a/Model/PaypalExpress/QuoteCreate.php +++ b/Model/PaypalExpress/QuoteCreate.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Model\PaypalExpress; use Buckaroo\Magento2\Model\Service\QuoteService; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Paypal; use Buckaroo\Magento2\Api\PaypalExpressQuoteCreateInterface; use Buckaroo\Magento2\Api\Data\ExpressMethods\ShippingAddressRequestInterface; @@ -38,9 +38,9 @@ class QuoteCreate implements PaypalExpressQuoteCreateInterface protected $responseFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var QuoteService @@ -50,12 +50,12 @@ class QuoteCreate implements PaypalExpressQuoteCreateInterface /** * @param QuoteCreateResponseInterfaceFactory $responseFactory * @param QuoteService $quoteService - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( QuoteCreateResponseInterfaceFactory $responseFactory, QuoteService $quoteService, - Log $logger + BuckarooLoggerInterface $logger ) { $this->responseFactory = $responseFactory; $this->quoteService = $quoteService; diff --git a/Model/Push.php b/Model/Push.php index b78f941b4..e4a74e9e4 100644 --- a/Model/Push.php +++ b/Model/Push.php @@ -24,7 +24,7 @@ use Buckaroo\Magento2\Api\PushInterface; use Buckaroo\Magento2\Api\PushRequestInterface; use Buckaroo\Magento2\Exception as BuckarooException; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Push\PushProcessorsFactory; use Buckaroo\Magento2\Model\Push\PushTransactionType; use Buckaroo\Magento2\Model\RequestPush\RequestPushFactory; @@ -33,9 +33,9 @@ class Push implements PushInterface { /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public Log $logging; + public BuckarooLoggerInterface $logger; /** * @var PushRequestInterface @@ -58,20 +58,20 @@ class Push implements PushInterface private PushTransactionType $pushTransactionType; /** - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param RequestPushFactory $requestPushFactory * @param PushProcessorsFactory $pushProcessorsFactory * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType */ public function __construct( - Log $logging, + BuckarooLoggerInterface $logger, RequestPushFactory $requestPushFactory, PushProcessorsFactory $pushProcessorsFactory, OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType ) { - $this->logging = $logging; + $this->logger = $logger; $this->pushRequst = $requestPushFactory->create(); $this->pushProcessorsFactory = $pushProcessorsFactory; $this->orderRequestService = $orderRequestService; @@ -87,7 +87,11 @@ public function __construct( public function receivePush(): bool { // Log the push request - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($this->pushRequst->getOriginalRequest(), true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s] - Original Request | originalRequest: %s', + __METHOD__, + var_export($this->pushRequst->getOriginalRequest(), true) + )); // Load Order $order = $this->orderRequestService->getOrderByRequest($this->pushRequst); @@ -97,7 +101,7 @@ public function receivePush(): bool $validSignature = $this->pushRequst->validate($store); if (!$validSignature) { - $this->logging->addDebug('Invalid push signature'); + $this->logger->addDebug('Invalid push signature'); throw new BuckarooException(__('Signature from push is incorrect')); } diff --git a/Model/Push/AfterpayProcessor.php b/Model/Push/AfterpayProcessor.php index f03576c30..6c05a8972 100644 --- a/Model/Push/AfterpayProcessor.php +++ b/Model/Push/AfterpayProcessor.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay20; @@ -41,7 +41,7 @@ class AfterpayProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -55,7 +55,7 @@ class AfterpayProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -64,7 +64,7 @@ public function __construct( Account $configAccount, Afterpay20 $afterpayConfig ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode, $orderStatusFactory, $configAccount); $this->afterpayConfig = $afterpayConfig; } @@ -81,7 +81,7 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool $this->pushRequest->hasAdditionalInformation('service_action_from_magento', 'capture') && $this->afterpayConfig->isInvoiceCreatedAfterShipment() )) { - $this->logging->addDebug(__METHOD__ . '|5_1|'); + $this->logger->addDebug(__METHOD__ . '|5_1|'); $this->dontSaveOrderUponSuccessPush = true; return false; } diff --git a/Model/Push/CancelAuthorizeProcessor.php b/Model/Push/CancelAuthorizeProcessor.php index 7e216c0a2..64c024e00 100644 --- a/Model/Push/CancelAuthorizeProcessor.php +++ b/Model/Push/CancelAuthorizeProcessor.php @@ -17,10 +17,10 @@ public function processPush(PushRequestInterface $pushRequest): bool try { $this->setTransactionKey(); } catch (\Exception $e) { - $this->logging->addDebug($e->getLogMessage()); + $this->logger->addDebug($e->getLogMessage()); } - $this->logging->addDebug('Order autorize has been canceld, trying to update payment transactions'); + $this->logger->addDebug('Order autorize has been canceld, trying to update payment transactions'); return true; } diff --git a/Model/Push/DefaultProcessor.php b/Model/Push/DefaultProcessor.php index 50f242a71..041c6cfa2 100644 --- a/Model/Push/DefaultProcessor.php +++ b/Model/Push/DefaultProcessor.php @@ -26,7 +26,7 @@ use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay; @@ -82,9 +82,9 @@ class DefaultProcessor implements PushProcessorInterface */ protected ?OrderPayment $payment; /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - protected Log $logging; + protected BuckarooLoggerInterface $logger; /** * @var Data */ @@ -117,7 +117,7 @@ class DefaultProcessor implements PushProcessorInterface /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -128,7 +128,7 @@ class DefaultProcessor implements PushProcessorInterface public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -138,7 +138,7 @@ public function __construct( ) { $this->pushTransactionType = $pushTransactionType; $this->orderRequestService = $orderRequestService; - $this->logging = $logging; + $this->logger = $logger; $this->helper = $helper; $this->transaction = $transaction; $this->groupTransaction = $groupTransaction; @@ -168,7 +168,7 @@ public function processPush(PushRequestInterface $pushRequest): bool // Check if the order can be updated if (!$this->canUpdateOrderStatus()) { - $this->logging->addDebug('Order can not receive updates'); + $this->logger->addDebug('Order can not receive updates'); $this->orderRequestService->setOrderNotificationNote(__('The order has already been processed.')); throw new BuckarooException( __('Signature from push is correct but the order can not receive updates') @@ -195,9 +195,9 @@ public function processPush(PushRequestInterface $pushRequest): bool $this->processPushByStatus(); - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); if (!$this->dontSaveOrderUponSuccessPush) { - $this->logging->addDebug(__METHOD__ . '|5-1|'); + $this->logger->addDebug(__METHOD__ . '|5-1|'); $this->order->save(); } @@ -264,7 +264,7 @@ protected function skipKlarnaCapture(): bool */ protected function skipSpecificTypesOfRequsts(): bool { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); $types = ['capture', 'cancelauthorize', 'cancelreservation']; if ($this->pushRequest->hasAdditionalInformation('initiated_by_magento', 1) @@ -287,7 +287,7 @@ protected function skipSpecificTypesOfRequsts(): bool protected function skipFirstPush(): bool { $skipFirstPush = $this->payment->getAdditionalInformation('skip_push'); - $this->logging->addDebug(__METHOD__ . '|1_20|' . var_export($skipFirstPush, true)); + $this->logger->addDebug(__METHOD__ . '|1_20|' . var_export($skipFirstPush, true)); if ($skipFirstPush > 0) { @@ -338,12 +338,12 @@ protected function receivePushCheckDuplicates(int $receivedStatusCode = null, st && ($this->pushTransactionType->getPushType() == PushTransactionType::BUCK_PUSH_TYPE_TRANSACTION) && (!in_array($this->payment->getMethod(), $ignoredPaymentMethods)) ) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); $receivedTrxStatuses = $this->payment->getAdditionalInformation( self::BUCKAROO_RECEIVED_TRANSACTIONS_STATUSES ); - $this->logging->addDebug(__METHOD__ . '|10|' . + $this->logger->addDebug(__METHOD__ . '|10|' . var_export([$receivedTrxStatuses, $receivedStatusCode], true)); if ($receivedTrxStatuses && is_array($receivedTrxStatuses) @@ -357,20 +357,20 @@ protected function receivePushCheckDuplicates(int $receivedStatusCode = null, st && ($receivedStatusCode == BuckarooStatusCode::SUCCESS) ) { //allow duplicated pushes for 190 statuses in case if order stills to be new/pending - $this->logging->addDebug(__METHOD__ . '|13|'); + $this->logger->addDebug(__METHOD__ . '|13|'); return false; } - $this->logging->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); return true; } if ($save) { - $this->logging->addDebug(__METHOD__ . '|17|'); + $this->logger->addDebug(__METHOD__ . '|17|'); $this->setReceivedTransactionStatuses(); $this->payment->save(); } } - $this->logging->addDebug(__METHOD__ . '|20|'); + $this->logger->addDebug(__METHOD__ . '|20|'); return false; } @@ -418,7 +418,7 @@ protected function canUpdateOrderStatus(): bool * Get current state and status of order */ $currentStateAndStatus = [$this->order->getState(), $this->order->getStatus()]; - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($currentStateAndStatus, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($currentStateAndStatus, true)); /** * If the types are not the same and the order can receive an invoice the order can be udpated by BPE. @@ -436,7 +436,7 @@ protected function canUpdateOrderStatus(): bool && ($this->pushTransactionType->getStatusKey() === 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS') && $this->pushRequest->getRelatedtransactionPartialpayment() == null ) { - $this->logging->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(__METHOD__ . '|2|'); $this->order->setState(Order::STATE_NEW); $this->order->setStatus('pending'); @@ -668,7 +668,7 @@ protected function getNewStatus() */ public function processSucceededPush(string $newStatus, string $message): bool { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); $this->setBuckarooReservationNumber(); @@ -691,7 +691,7 @@ public function processSucceededPush(string $newStatus, string $message): bool $paymentDetails['forceState'] = true; } - $this->logging->addDebug(__METHOD__ . '|8|'); + $this->logger->addDebug(__METHOD__ . '|8|'); $this->processSucceededPushAuthorization(); @@ -703,7 +703,7 @@ public function processSucceededPush(string $newStatus, string $message): bool $this->dontSaveOrderUponSuccessPush ); - $this->logging->addDebug(__METHOD__ . '|9|'); + $this->logger->addDebug(__METHOD__ . '|9|'); return true; } @@ -732,7 +732,7 @@ private function processSucceededPushAuthorization(): void ) && !empty($this->pushRequest->getStatusCode()) && ($this->pushRequest->getStatusCode() == 190) ) { - $this->logging->addDebug(__METHOD__ . '|88|' . var_export($this->payment->getMethod(), true)); + $this->logger->addDebug(__METHOD__ . '|88|' . var_export($this->payment->getMethod(), true)); $this->order->setState(Order::STATE_PROCESSING); $this->order->save(); } @@ -765,7 +765,7 @@ protected function sendOrderEmail(): void || $paymentMethod->getConfigData('order_email', $store) ) ) { - $this->logging->addDebug(__METHOD__ . '|sendemail|' . + $this->logger->addDebug(__METHOD__ . '|sendemail|' . var_export($this->configAccount->getOrderConfirmationEmailSync($store), true)); $this->orderRequestService->sendOrderEmail( $this->order, @@ -805,16 +805,16 @@ protected function canPushInvoice(): bool */ protected function saveInvoice(): bool { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); if (!$this->forceInvoice && (!$this->order->canInvoice() || $this->order->hasInvoices())) { - $this->logging->addDebug('Order can not be invoiced'); + $this->logger->addDebug('Order can not be invoiced'); return false; } $this->addTransactionData(); - $this->logging->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); //Fix for suspected fraud when the order currency does not match with the payment's currency $amount = ($this->payment->isSameCurrency() && $this->payment->isCaptureFinal($this->order->getGrandTotal())) ? @@ -828,7 +828,7 @@ protected function saveInvoice(): bool return true; } - $this->logging->addDebug(__METHOD__ . '|25|'); + $this->logger->addDebug(__METHOD__ . '|25|'); /** @var Invoice $invoice */ foreach ($this->order->getInvoiceCollection() as $invoice) { @@ -836,17 +836,17 @@ protected function saveInvoice(): bool if (!empty($this->pushRequest->getInvoiceNumber()) && $this->groupTransaction->isGroupTransaction($this->pushRequest->getInvoiceNumber())) { - $this->logging->addDebug(__METHOD__ . '|27|'); + $this->logger->addDebug(__METHOD__ . '|27|'); $invoice->setState(2); } if (!$invoice->getEmailSent() && $this->configAccount->getInvoiceEmail($this->order->getStore())) { - $this->logging->addDebug(__METHOD__ . '|30|sendinvoiceemail'); + $this->logger->addDebug(__METHOD__ . '|30|sendinvoiceemail'); $this->orderRequestService->sendInvoiceEmail($invoice, true); } } - $this->logging->addDebug(__METHOD__ . '|35|'); + $this->logger->addDebug(__METHOD__ . '|35|'); $this->order->setIsInProcess(true); $this->order->save(); @@ -911,13 +911,13 @@ public function addTransactionData(bool $transactionKey = false, bool $data = fa */ public function processFailedPush(string $newStatus, string $message): bool { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); if (($this->order->getState() === Order::STATE_PROCESSING) && ($this->order->getStatus() === Order::STATE_PROCESSING) ) { //do not update to failed if we had a success already - $this->logging->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(__METHOD__ . '|2|'); return false; } @@ -938,7 +938,7 @@ public function processFailedPush(string $newStatus, string $message): bool $payment = $this->order->getPayment(); if ($buckarooCancelOnFailed && $this->order->canCancel()) { - $this->logging->addDebug(__METHOD__ . '|' . 'Buckaroo push failed : ' . $message . ' : Cancel order.'); + $this->logger->addDebug(__METHOD__ . '|' . 'Buckaroo push failed : ' . $message . ' : Cancel order.'); // BUCKM2-78: Never automatically cancelauthorize via push for afterpay // setting parameter which will cause to stop the cancel process on @@ -959,13 +959,13 @@ public function processFailedPush(string $newStatus, string $message): bool try { $this->order->cancel()->save(); } catch (\Throwable $t) { - $this->logging->addDebug(__METHOD__ . '|3|'); + $this->logger->addDebug(__METHOD__ . '|3|'); // SignifydGateway/Gateway error on line 208" } return true; } - $this->logging->addDebug(__METHOD__ . '|4|'); + $this->logger->addDebug(__METHOD__ . '|4|'); $force = false; if (($payment->getMethodInstance()->getCode() == 'buckaroo_magento2_mrcash') && ($this->order->getState() === Order::STATE_NEW) @@ -1024,7 +1024,7 @@ protected function getPaymentDetails($message) $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; - $this->logging->addDebug(__METHOD__ . '|4|'); + $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) diff --git a/Model/Push/GroupTransactionPushProcessor.php b/Model/Push/GroupTransactionPushProcessor.php index 5661a9779..37c2ae368 100644 --- a/Model/Push/GroupTransactionPushProcessor.php +++ b/Model/Push/GroupTransactionPushProcessor.php @@ -25,7 +25,7 @@ use Buckaroo\Magento2\Api\PushProcessorInterface; use Buckaroo\Magento2\Api\PushRequestInterface; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log as BuckarooLogger; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface as BuckarooLogger; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Service\Push\OrderRequestService; use Magento\Framework\Exception\LocalizedException; @@ -51,7 +51,7 @@ class GroupTransactionPushProcessor implements PushProcessorInterface /** * @var BuckarooLogger */ - private BuckarooLogger $logging; + private BuckarooLogger $logger; /** * @var PaymentGroupTransaction @@ -95,7 +95,7 @@ class GroupTransactionPushProcessor implements PushProcessorInterface /** * @param PaymentGroupTransaction $groupTransaction - * @param BuckarooLogger $logging + * @param BuckarooLogger $logger * @param OrderRequestService $orderRequestService * @param OrderManagementInterface $orderManagement * @param QuoteManagement $quoteManagement @@ -105,7 +105,7 @@ class GroupTransactionPushProcessor implements PushProcessorInterface */ public function __construct( PaymentGroupTransaction $groupTransaction, - BuckarooLogger $logging, + BuckarooLogger $logger, OrderRequestService $orderRequestService, OrderManagementInterface $orderManagement, QuoteManagement $quoteManagement, @@ -114,7 +114,7 @@ public function __construct( DefaultProcessor $defaultProcessor ) { $this->groupTransaction = $groupTransaction; - $this->logging = $logging; + $this->logger = $logger; $this->orderRequestService = $orderRequestService; $this->orderManagement = $orderManagement; $this->quoteManagement = $quoteManagement; @@ -203,7 +203,7 @@ protected function handleGroupTransactionFailed() $this->savePartGroupTransaction(); } catch (\Throwable $th) { - $this->logging->addDebug(__METHOD__ . '|' . (string)$th); + $this->logger->addDebug(__METHOD__ . '|' . (string)$th); } } diff --git a/Model/Push/IdealProcessor.php b/Model/Push/IdealProcessor.php index 53a0d48d7..2d42e38e2 100644 --- a/Model/Push/IdealProcessor.php +++ b/Model/Push/IdealProcessor.php @@ -25,7 +25,7 @@ use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\OrderStatusFactory; @@ -49,7 +49,7 @@ class IdealProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -63,7 +63,7 @@ class IdealProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -72,7 +72,7 @@ public function __construct( Account $configAccount, LockerProcess $lockerProcess ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode, $orderStatusFactory, $configAccount); $this->lockerProcess = $lockerProcess; diff --git a/Model/Push/KlarnaKpProcessor.php b/Model/Push/KlarnaKpProcessor.php index d46401776..00091b3d8 100644 --- a/Model/Push/KlarnaKpProcessor.php +++ b/Model/Push/KlarnaKpProcessor.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Klarnakp; @@ -41,7 +41,7 @@ class KlarnaKpProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -55,7 +55,7 @@ class KlarnaKpProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -64,7 +64,7 @@ public function __construct( Account $configAccount, Klarnakp $klarnakpConfig ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode, $orderStatusFactory, $configAccount); $this->klarnakpConfig = $klarnakpConfig; } @@ -129,7 +129,7 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool empty($this->pushRequest->getServiceKlarnakpReservationnumber()) && $this->klarnakpConfig->isInvoiceCreatedAfterShipment() )) { - $this->logging->addDebug(__METHOD__ . '|5_1|'); + $this->logger->addDebug(__METHOD__ . '|5_1|'); $this->dontSaveOrderUponSuccessPush = true; return false; } diff --git a/Model/Push/KlarnaProcessor.php b/Model/Push/KlarnaProcessor.php index e0a5f7072..8d013ce07 100644 --- a/Model/Push/KlarnaProcessor.php +++ b/Model/Push/KlarnaProcessor.php @@ -5,7 +5,7 @@ use Buckaroo\Magento2\Api\PushRequestInterface; use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Service\LockerProcess; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; diff --git a/Model/Push/PayPerEmailProcessor.php b/Model/Push/PayPerEmailProcessor.php index 54479bee2..6ad13307b 100644 --- a/Model/Push/PayPerEmailProcessor.php +++ b/Model/Push/PayPerEmailProcessor.php @@ -25,7 +25,7 @@ use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Giftcards; @@ -63,7 +63,7 @@ class PayPerEmailProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -78,7 +78,7 @@ class PayPerEmailProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -88,7 +88,7 @@ public function __construct( LockerProcess $lockerProcess, PayPerEmail $configPayPerEmail ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode, $orderStatusFactory, $configAccount); $this->lockerProcess = $lockerProcess; $this->configPayPerEmail = $configPayPerEmail; @@ -129,14 +129,14 @@ public function processPush(PushRequestInterface $pushRequest): bool // Check if the order can be updated if (!$this->canUpdateOrderStatus()) { if ($isDifferentPaymentMethod && $this->configPayPerEmail->isEnabledB2B()) { - $this->logging->addDebug(__METHOD__ . '|$this->order->getState()|' . $this->order->getState()); + $this->logger->addDebug(__METHOD__ . '|$this->order->getState()|' . $this->order->getState()); if ($this->order->getState() === Order::STATE_COMPLETE) { $this->order->setState(Order::STATE_PROCESSING); $this->order->save(); } return true; } - $this->logging->addDebug('Order can not receive updates'); + $this->logger->addDebug('Order can not receive updates'); $this->orderRequestService->setOrderNotificationNote(__('The order has already been processed.')); throw new BuckarooException( __('Signature from push is correct but the order can not receive updates') @@ -164,9 +164,9 @@ public function processPush(PushRequestInterface $pushRequest): bool $this->processPushByStatus(); - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); if (!$this->dontSaveOrderUponSuccessPush) { - $this->logging->addDebug(__METHOD__ . '|5-1|'); + $this->logger->addDebug(__METHOD__ . '|5-1|'); $this->order->save(); } @@ -316,7 +316,7 @@ public function isPayPerEmailB2BModePush(): bool && !empty($this->pushRequest->getTransactionMethod()) && ($this->pushRequest->getTransactionMethod() == 'payperemail') && $this->configPayPerEmail->isEnabledB2B()) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); $this->isPayPerEmailB2BModePushInitial = true; } } else { @@ -345,12 +345,12 @@ public function isPayPerEmailB2BModePushInitial(): bool protected function getNewStatus() { $newStatus = $this->orderStatusFactory->get($this->pushRequest->getStatusCode(), $this->order); - $this->logging->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); + $this->logger->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); if ($this->isPayPerEmailB2BModePushInitial()) { $this->pushTransactionType->setStatusKey('BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS'); $newStatus = $this->configAccount->getOrderStatusSuccess(); - $this->logging->addDebug(__METHOD__ . '|15|' . var_export( + $this->logger->addDebug(__METHOD__ . '|15|' . var_export( [$this->pushTransactionType->getStatusKey(), $newStatus], true ) @@ -381,7 +381,7 @@ protected function getPaymentDetails($message) $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; - $this->logging->addDebug(__METHOD__ . '|4|'); + $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) @@ -408,7 +408,7 @@ protected function getPaymentDetails($message) protected function invoiceShouldBeSaved(array &$paymentDetails): bool { if (!$this->isPayPerEmailB2BModePushInitial && $this->isPayPerEmailB2BModePush()) { - $this->logging->addDebug(__METHOD__ . '|4_1|'); + $this->logger->addDebug(__METHOD__ . '|4_1|'); //Fix for suspected fraud when the order currency does not match with the payment's currency $amount = $this->payment->isSameCurrency() && $this->payment->isCaptureFinal($this->order->getGrandTotal()) ? $this->order->getGrandTotal() diff --git a/Model/Push/PaypalProcessor.php b/Model/Push/PaypalProcessor.php index 916b5e4f0..be51231bd 100644 --- a/Model/Push/PaypalProcessor.php +++ b/Model/Push/PaypalProcessor.php @@ -24,7 +24,7 @@ use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Paypal as PaypalConfig; @@ -40,7 +40,7 @@ class PaypalProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -54,7 +54,7 @@ class PaypalProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -63,7 +63,7 @@ public function __construct( Account $configAccount, PaypalConfig $paypalConfig ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode, $orderStatusFactory, $configAccount); $this->paypalConfig = $paypalConfig; @@ -77,7 +77,7 @@ public function __construct( protected function getNewStatus() { $newStatus = $this->orderStatusFactory->get($this->pushRequest->getStatusCode(), $this->order); - $this->logging->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); + $this->logger->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); if ($this->pushTransactionType->getStatusKey() == 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS' && $this->order->getPayment()->getMethod() == PaypalConfig::CODE) { diff --git a/Model/Push/RefundProcessor.php b/Model/Push/RefundProcessor.php index ccf34a2a6..31c6ef53a 100644 --- a/Model/Push/RefundProcessor.php +++ b/Model/Push/RefundProcessor.php @@ -25,7 +25,7 @@ use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\BuckarooStatusCode; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\OrderStatusFactory; @@ -46,7 +46,7 @@ class RefundProcessor extends DefaultProcessor /** * @param OrderRequestService $orderRequestService * @param PushTransactionType $pushTransactionType - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper * @param TransactionInterface $transaction * @param PaymentGroupTransaction $groupTransaction @@ -60,7 +60,7 @@ class RefundProcessor extends DefaultProcessor public function __construct( OrderRequestService $orderRequestService, PushTransactionType $pushTransactionType, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper, TransactionInterface $transaction, PaymentGroupTransaction $groupTransaction, @@ -69,7 +69,7 @@ public function __construct( Account $configAccount, RefundPush $refundPush ) { - parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, + parent::__construct($orderRequestService, $pushTransactionType, $logger, $helper, $transaction, $groupTransaction, $buckarooStatusCode,$orderStatusFactory, $configAccount); $this->refundPush = $refundPush; } @@ -91,7 +91,7 @@ public function processPush(PushRequestInterface $pushRequest): bool if ($this->pushTransactionType->getStatusKey() !== 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS') { if ($this->order->hasInvoices()) { //don't proceed failed refund push - $this->logging->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); $this->orderRequestService->setOrderNotificationNote( __('Push notification for refund has no success status, ignoring.') ); @@ -119,7 +119,7 @@ private function skipPendingRefundPush(PushRequestInterface $pushRequest): bool if (!$pushRequest->hasAdditionalInformation('initiated_by_magento', 1) || !$pushRequest->hasAdditionalInformation('service_action_from_magento', ['refund']) ) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); return false; } @@ -129,7 +129,7 @@ private function skipPendingRefundPush(PushRequestInterface $pushRequest): bool BuckarooStatusCode::PENDING_APPROVAL, $pushRequest->getRelatedtransactionRefund() )) { - $this->logging->addDebug(__METHOD__ . '|4|'); + $this->logger->addDebug(__METHOD__ . '|4|'); return false; } diff --git a/Model/Push/TransferProcessor.php b/Model/Push/TransferProcessor.php index 4152ee8be..a2ee1aae7 100644 --- a/Model/Push/TransferProcessor.php +++ b/Model/Push/TransferProcessor.php @@ -29,7 +29,7 @@ protected function getPaymentDetails($message) //keep amount fetched from brq_amount $description .= 'Amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; } - $this->logging->addDebug(__METHOD__ . '|4|'); + $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) @@ -53,7 +53,7 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool { $amount = $paymentDetails['amount']; //invoice only in case of full or last remained amount - $this->logging->addDebug(__METHOD__ . '|61|' . var_export([ + $this->logger->addDebug(__METHOD__ . '|61|' . var_export([ $this->order->getId(), $paymentDetails['amount'], $this->order->getTotalDue(), @@ -65,11 +65,11 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool if (($paymentDetails['amount'] < $this->order->getTotalDue()) || (($paymentDetails['amount'] == $this->order->getTotalDue()) && ($this->order->getTotalPaid() > 0)) ) { - $this->logging->addDebug(__METHOD__ . '|64|'); + $this->logger->addDebug(__METHOD__ . '|64|'); $paymentDetails['forceState'] = true; if ($amount < $this->order->getTotalDue()) { - $this->logging->addDebug(__METHOD__ . '|65|'); + $this->logger->addDebug(__METHOD__ . '|65|'); $paymentDetails['state'] = Order::STATE_NEW; $paymentDetails['newStatus'] = $this->orderStatusFactory->get( BuckarooStatusCode::PENDING_PROCESSING, diff --git a/Model/Refund/Push.php b/Model/Refund/Push.php index 1d259410a..0613a659b 100644 --- a/Model/Refund/Push.php +++ b/Model/Refund/Push.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Api\PushRequestInterface; use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Refund; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\LocalizedException; @@ -76,9 +76,9 @@ class Push public $helper; /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public $logging; + public BuckarooLoggerInterface $logger; /** * @var ScopeConfigInterface @@ -96,7 +96,7 @@ class Push * @param CreditmemoSender $creditEmailSender * @param Refund $configRefund * @param Data $helper - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param ScopeConfigInterface $scopeConfig */ public function __construct( @@ -105,14 +105,14 @@ public function __construct( CreditmemoSender $creditEmailSender, Refund $configRefund, Data $helper, - Log $logging, + BuckarooLoggerInterface $logger, ScopeConfigInterface $scopeConfig ) { $this->creditmemoFactory = $creditmemoFactory; $this->creditmemoManagement = $creditmemoManagement; $this->creditEmailSender = $creditEmailSender; $this->helper = $helper; - $this->logging = $logging; + $this->logger = $logger; $this->configRefund = $configRefund; $this->scopeConfig = $scopeConfig; } @@ -133,12 +133,12 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur $this->postData = $postData; $this->order = $order; - $this->logging->addDebug( + $this->logger->addDebug( __METHOD__ . '|1|Trying to refund order ' . $this->order->getId() . ' out of paymentplaza. ' ); if (!$this->configRefund->getAllowPush()) { - $this->logging->addDebug( + $this->logger->addDebug( __METHOD__ . '|5|But failed, the configuration is set not to accept refunds out of Payment Plaza' ); //phpcs:ignore:Magento2.Exceptions.DirectThrow @@ -157,7 +157,7 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur ], true ); - $this->logging->addDebug($debugMessage); + $this->logger->addDebug($debugMessage); //phpcs:ignore:Magento2.Exceptions.DirectThrow throw new Exception( __('Buckaroo refund push validation failed') @@ -170,13 +170,13 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur $this->postData->getTransactions() ); if (count($creditmemosByTransactionId) > 0) { - $this->logging->addDebug(__METHOD__ . '|15|The transaction has already been refunded.'); + $this->logger->addDebug(__METHOD__ . '|15|The transaction has already been refunded.'); return false; } $creditmemo = $this->createCreditmemo(); - $this->logging->addDebug(__METHOD__ . '|20|Order successful refunded = ' . $creditmemo); + $this->logger->addDebug(__METHOD__ . '|20|Order successful refunded = ' . $creditmemo); return $creditmemo; } @@ -189,7 +189,7 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur */ public function createCreditmemo(): bool { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); $creditData = $this->getCreditmemoData(); $creditmemo = $this->initCreditmemo($creditData); @@ -201,43 +201,43 @@ public function createCreditmemo(): bool && !empty($this->postData->getTransactionType()) && ($this->postData->getTransactionType() == 'C041') ) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); $creditmemo->setBaseGrandTotal($this->totalAmountToRefund()); $creditmemo->setGrandTotal($this->totalAmountToRefund()); } if (!$creditmemo->isValidGrandTotal()) { - $this->logging->addDebug(__METHOD__ . '|10|The credit memo\'s total must be positive.'); + $this->logger->addDebug(__METHOD__ . '|10|The credit memo\'s total must be positive.'); throw new LocalizedException( __('The credit memo\'s total must be positive.') ); } $creditmemo->setTransactionId($this->postData->getTransactions()); - $this->logging->addDebug(__METHOD__ . '|20'); + $this->logger->addDebug(__METHOD__ . '|20'); $this->creditmemoManagement->refund( $creditmemo, (bool)$creditData['do_offline'], !empty($creditData['order_email']) ); - $this->logging->addDebug(__METHOD__ . '|25'); + $this->logger->addDebug(__METHOD__ . '|25'); $this->creditEmailSender->send($creditmemo); return true; } else { $debugMessage = 'Failed to create the creditmemo, method saveCreditmemo return value: ' . PHP_EOL; //phpcs:ignore:Magento2.Functions.DiscouragedFunction $debugMessage .= print_r($creditmemo, true); - $this->logging->addDebug(__METHOD__ . '|30|' . $debugMessage); + $this->logger->addDebug(__METHOD__ . '|30|' . $debugMessage); //phpcs:ignore:Magento2.Exceptions.DirectThrow throw new BuckarooException( __('Failed to create the creditmemo') ); } } catch (LocalizedException $e) { - $this->logging->addDebug( + $this->logger->addDebug( __METHOD__ . '|35|Buckaroo failed to create the credit memo\'s { ' . $e->getLogMessage() . ' }' ); } - $this->logging->addDebug(__METHOD__ . '|40'); + $this->logger->addDebug(__METHOD__ . '|40'); return false; } @@ -257,21 +257,21 @@ public function getCreditmemoData(): array $totalAmountToRefund = $this->totalAmountToRefund(); $this->creditAmount = $totalAmountToRefund + $this->order->getBaseTotalRefunded(); - $this->logging->addDebug(__METHOD__ . '|1|' . var_export([ + $this->logger->addDebug(__METHOD__ . '|1|' . var_export([ $this->creditAmount, $this->order->getBaseGrandTotal(), ], true)); if (!$this->helper->areEqualAmounts($this->creditAmount, $this->order->getBaseGrandTotal())) { $adjustment = $this->getAdjustmentRefundData(); - $this->logging->addDebug('This is an adjustment refund of ' . $totalAmountToRefund); + $this->logger->addDebug('This is an adjustment refund of ' . $totalAmountToRefund); $data['shipping_amount'] = '0'; $data['adjustment_negative'] = '0'; $data['adjustment_positive'] = $adjustment; $data['items'] = $this->getCreditmemoDataItems(); $data['qtys'] = $this->setCreditQtys($data['items']); } else { - $this->logging->addDebug( + $this->logger->addDebug( 'With this refund of ' . $this->creditAmount . ' the grand total will be refunded.' ); $data['shipping_amount'] = $this->caluclateShippingCostToRefund(); @@ -284,7 +284,7 @@ public function getCreditmemoData(): array $debugMessage = 'Data used for credit nota: ' . PHP_EOL; //phpcs:ignore:Magento2.Functions.DiscouragedFunction $debugMessage .= print_r($data, true); - $this->logging->addDebug($debugMessage); + $this->logger->addDebug($debugMessage); return $data; } @@ -355,7 +355,7 @@ public function getCreditmemoDataItems(): array $debugMessage = 'Total items to be refunded: ' . PHP_EOL; //phpcs:ignore:Magento2.Functions.DiscouragedFunction $debugMessage .= print_r($items, true); - $this->logging->addDebug($debugMessage); + $this->logger->addDebug($debugMessage); return $items; } @@ -392,11 +392,11 @@ public function caluclateShippingCostToRefund(): float ); if ($includesTax) { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); return ($this->order->getBaseShippingAmount() + $this->order->getBaseShippingTaxAmount()) - ($this->order->getBaseShippingRefunded() + $this->order->getBaseShippingTaxRefunded()); } else { - $this->logging->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(__METHOD__ . '|2|'); return $this->order->getBaseShippingAmount() - $this->order->getBaseShippingRefunded(); } @@ -439,19 +439,19 @@ public function calculateRemainder() - $baseTotalToBeRefunded - $this->order->getBaseTotalRefunded(); - $this->logging->addDebug(__METHOD__ . '|5|' . var_export([ + $this->logger->addDebug(__METHOD__ . '|5|' . var_export([ $this->totalAmountToRefund(), $this->order->getBaseGrandTotal(), $remainderToRefund ], true)); if ($this->totalAmountToRefund() == $this->order->getBaseGrandTotal()) { - $this->logging->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); $remainderToRefund = 0; } if ($remainderToRefund < 0.01) { - $this->logging->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); $remainderToRefund = 0; } @@ -479,7 +479,7 @@ public function initCreditmemo(array $creditData) return $creditmemo; } catch (LocalizedException $e) { - $this->logging + $this->logger ->addDebug('Buckaroo can not initialize the credit memo\'s by order { ' . $e->getLogMessage() . ' }'); } return false; diff --git a/Model/RequestPush/RequestPushFactory.php b/Model/RequestPush/RequestPushFactory.php index 0bdb1e404..eb48b53f5 100644 --- a/Model/RequestPush/RequestPushFactory.php +++ b/Model/RequestPush/RequestPushFactory.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Model\RequestPush; use Buckaroo\Magento2\Api\PushRequestInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Webapi\Rest\Request; @@ -39,23 +39,23 @@ class RequestPushFactory private Request $request; /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logging; + private BuckarooLoggerInterface $logger; /** * @param ObjectManagerInterface $objectManager * @param Request $request - * @param Log $logging + * @param BuckarooLoggerInterface $logger */ public function __construct( ObjectManagerInterface $objectManager, Request $request, - Log $logging + BuckarooLoggerInterface $logger ) { $this->objectManager = $objectManager; $this->request = $request; - $this->logging = $logging; + $this->logger = $logger; } /** @@ -67,7 +67,7 @@ public function create(): PushRequestInterface { try { if (strpos($this->request->getContentType(), 'application/json') !== false) { - $this->logging->addDebug(__METHOD__ . '|Create json object|' . var_export( + $this->logger->addDebug(__METHOD__ . '|Create json object|' . var_export( $this->request->getRequestData(), true )); @@ -77,10 +77,10 @@ public function create(): PushRequestInterface ); } } catch (\Exception $exception) { - $this->logging->addDebug(__METHOD__ . '|EXCEPTION|' . var_export($exception->getMessage(), true)); + $this->logger->addDebug(__METHOD__ . '|EXCEPTION|' . var_export($exception->getMessage(), true)); } - $this->logging->addDebug(__METHOD__ . '|Create httppost object|' . var_export( + $this->logger->addDebug(__METHOD__ . '|Create httppost object|' . var_export( $this->request->getRequestData(), true )); diff --git a/Model/ResourceModel/Order/Handler/State.php b/Model/ResourceModel/Order/Handler/State.php index 6f1fd6323..7bc02f0fb 100644 --- a/Model/ResourceModel/Order/Handler/State.php +++ b/Model/ResourceModel/Order/Handler/State.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Model\ResourceModel\Order\Handler; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory; use Buckaroo\Magento2\Model\ConfigProvider\Method\PayPerEmail; use Magento\Sales\Model\Order; @@ -34,22 +34,22 @@ class State extends \Magento\Sales\Model\ResourceModel\Order\Handler\State public Factory $configProviderMethodFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logging; + private BuckarooLoggerInterface $logger; /** * State constructor * * @param Factory $configProviderMethodFactory - * @param Log $logging + * @param BuckarooLoggerInterface $logger */ public function __construct( Factory $configProviderMethodFactory, - Log $logging + BuckarooLoggerInterface $logger ) { $this->configProviderMethodFactory = $configProviderMethodFactory; - $this->logging = $logging; + $this->logger = $logger; } public function check(Order $order): State @@ -63,7 +63,7 @@ public function check(Order $order): State && $order->getInvoiceCollection() && $order->getInvoiceCollection()->getFirstItem() && $order->getInvoiceCollection()->getFirstItem()->getState() == 1 ) { - $this->logging->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); return $this; } } diff --git a/Model/Service/Order.php b/Model/Service/Order.php index fcfa27952..20dc76b14 100644 --- a/Model/Service/Order.php +++ b/Model/Service/Order.php @@ -29,7 +29,7 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Store\Api\Data\StoreInterface; use Magento\Store\Api\StoreRepositoryInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; use Buckaroo\Magento2\Helper\Data; use Magento\Framework\App\ResourceConnection; @@ -70,9 +70,9 @@ class Order protected $helper; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logging; + protected BuckarooLoggerInterface $logger; /** * @var ResourceConnection @@ -92,7 +92,7 @@ class Order * @param CollectionFactory $orderFactory * @param OrderStatusFactory $orderStatusFactory * @param Data $helper - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param ResourceConnection $resourceConnection */ public function __construct( @@ -103,7 +103,7 @@ public function __construct( CollectionFactory $orderFactory, OrderStatusFactory $orderStatusFactory, Data $helper, - Log $logging, + BuckarooLoggerInterface $logger, ResourceConnection $resourceConnection ) { $this->accountConfig = $accountConfig; @@ -113,7 +113,7 @@ public function __construct( $this->orderFactory = $orderFactory; $this->orderStatusFactory = $orderStatusFactory; $this->helper = $helper; - $this->logging = $logging; + $this->logger = $logger; $this->resourceConnection = $resourceConnection; } @@ -142,12 +142,12 @@ public function cancelExpiredTransferOrders() */ protected function cancelExpiredTransferOrdersPerStore(StoreInterface $store) { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); $statesConfig = $this->configProviderFactory->get('states'); $state = $statesConfig->getOrderStateNew($store); if ($transferConfig = $this->configProviderMethodFactory->get('transfer')) { if ($dueDays = abs($transferConfig->getDueDate())) { - $this->logging->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); + $this->logger->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); $orderCollection = $this->orderFactory->create()->addFieldToSelect(['*']); $orderCollection ->addFieldToFilter( @@ -175,7 +175,7 @@ protected function cancelExpiredTransferOrdersPerStore(StoreInterface $store) ) ->where('p.method = ?', Transfer::CODE); - $this->logging->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); + $this->logger->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); if ($orderCollection->count()) { foreach ($orderCollection as $order) { @@ -214,13 +214,13 @@ public function cancelExpiredPPEOrders(): Order */ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); $statesConfig = $this->configProviderFactory->get('states'); $state = $statesConfig->getOrderStateNew($store); if ($ppeConfig = $this->configProviderMethodFactory->get('payperemail')) { if ($ppeConfig->getEnabledCronCancelPPE()) { if ($dueDays = abs($ppeConfig->getExpireDays())) { - $this->logging->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); + $this->logger->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); $orderCollection = $this->orderFactory->create()->addFieldToSelect(['*']); $orderCollection ->addFieldToFilter( @@ -249,11 +249,11 @@ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) ->where('p.additional_information like "%isPayPerEmail%"' . ' OR p.method ="buckaroo_magento2_payperemail"'); - $this->logging->addDebug( + $this->logger->addDebug( __METHOD__ . '|PPEOrders query|' . $orderCollection->getSelect()->__toString() ); - $this->logging->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); + $this->logger->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); if ($orderCollection->count()) { foreach ($orderCollection as $order) { @@ -278,11 +278,11 @@ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) */ public function cancel($order, $statusCode) { - $this->logging->addDebug(__METHOD__ . '|1|' . var_export($order->getIncrementId(), true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export($order->getIncrementId(), true)); // Mostly the push api already canceled the order, so first check in wich state the order is. if ($order->getState() == \Magento\Sales\Model\Order::STATE_CANCELED) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); return true; } @@ -292,16 +292,16 @@ public function cancel($order, $statusCode) * @noinspection PhpUndefinedMethodInspection */ if (!$this->accountConfig->getCancelOnFailed($store)) { - $this->logging->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); return true; } - $this->logging->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); if ($order->canCancel() || in_array($order->getPayment()->getMethodInstance()->buckarooPaymentMethodCode, ['payperemail']) ) { - $this->logging->addDebug(__METHOD__ . '|20|'); + $this->logger->addDebug(__METHOD__ . '|20|'); if (in_array($order->getPayment()->getMethodInstance()->buckarooPaymentMethodCode, ['klarnakp'])) { $methodInstanceClass = get_class($order->getPayment()->getMethodInstance()); @@ -310,7 +310,7 @@ public function cancel($order, $statusCode) $order->cancel(); - $this->logging->addDebug(__METHOD__ . '|30|'); + $this->logger->addDebug(__METHOD__ . '|30|'); $failedStatus = $this->orderStatusFactory->get( $statusCode, @@ -324,7 +324,7 @@ public function cancel($order, $statusCode) return true; } - $this->logging->addDebug(__METHOD__ . '|40|'); + $this->logger->addDebug(__METHOD__ . '|40|'); return false; } diff --git a/Model/Service/QuoteAddressService.php b/Model/Service/QuoteAddressService.php index cae894da7..feb9edf2a 100644 --- a/Model/Service/QuoteAddressService.php +++ b/Model/Service/QuoteAddressService.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Model\Service; use Buckaroo\Magento2\Api\Data\ExpressMethods\ShippingAddressRequestInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Model\Session as CustomerSession; use Magento\Framework\Exception\LocalizedException; @@ -49,9 +49,9 @@ class QuoteAddressService */ protected CustomerRepositoryInterface $customerRepository; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var Quote @@ -68,14 +68,14 @@ class QuoteAddressService * @param CustomerRepositoryInterface $customerRepository * @param QuoteRepository $quoteRepository * @param ShippingAddressManagementInterface $shippingAddressManagement - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( CustomerSession $customerSession, CustomerRepositoryInterface $customerRepository, QuoteRepository $quoteRepository, ShippingAddressManagementInterface $shippingAddressManagement, - Log $logger + BuckarooLoggerInterface $logger ) { $this->customerSession = $customerSession; $this->customerRepository = $customerRepository; diff --git a/Model/Service/QuoteService.php b/Model/Service/QuoteService.php index 7cdba2662..66a54e848 100644 --- a/Model/Service/QuoteService.php +++ b/Model/Service/QuoteService.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Model\Service; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Service\QuoteBuilderInterfaceFactory; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Framework\DataObject; @@ -38,9 +38,9 @@ class QuoteService { /** - * @var \Buckaroo\Magento2\Logging\Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var \Buckaroo\Magento2\Model\Service\QuoteBuilderInterfaceFactory */ @@ -79,7 +79,7 @@ class QuoteService protected $quote; /** - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param CartRepositoryInterface $cartRepository * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId * @param AddProductToCartService $addProductToCartService @@ -89,7 +89,7 @@ class QuoteService * @param QuoteBuilderInterfaceFactory $quoteBuilderInterfaceFactory */ public function __construct( - Log $logger, + BuckarooLoggerInterface $logger, CartRepositoryInterface $cartRepository, MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, AddProductToCartService $addProductToCartService, diff --git a/Model/Total/Quote/BuckarooFee.php b/Model/Total/Quote/BuckarooFee.php index d24d7a69a..efdfc37f9 100644 --- a/Model/Total/Quote/BuckarooFee.php +++ b/Model/Total/Quote/BuckarooFee.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Config\Source\TaxClass\Calculation; use Buckaroo\Magento2\Model\ConfigProvider\Account as ConfigProviderAccount; use Buckaroo\Magento2\Model\ConfigProvider\BuckarooFee as ConfigProviderBuckarooFee; @@ -75,9 +75,9 @@ class BuckarooFee extends AbstractTotal protected $taxCalculation; /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - protected $logging; + protected BuckarooLoggerInterface $logger; /** * @param ConfigProviderAccount $configProviderAccount @@ -86,7 +86,7 @@ class BuckarooFee extends AbstractTotal * @param PriceCurrencyInterface $priceCurrency * @param Data $catalogHelper * @param PaymentGroupTransaction $groupTransaction - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param TaxModelCalculation $taxCalculation */ public function __construct( @@ -96,7 +96,7 @@ public function __construct( PriceCurrencyInterface $priceCurrency, Data $catalogHelper, PaymentGroupTransaction $groupTransaction, - Log $logging, + BuckarooLoggerInterface $logger, TaxModelCalculation $taxCalculation ) { $this->setCode('buckaroo_fee'); @@ -108,7 +108,7 @@ public function __construct( $this->catalogHelper = $catalogHelper; $this->groupTransaction = $groupTransaction; - $this->logging = $logging; + $this->logger = $logger; $this->taxCalculation = $taxCalculation; } diff --git a/Model/Total/Quote/Tax/BuckarooFee.php b/Model/Total/Quote/Tax/BuckarooFee.php index 5e3680203..5b4a35582 100644 --- a/Model/Total/Quote/Tax/BuckarooFee.php +++ b/Model/Total/Quote/Tax/BuckarooFee.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account as ConfigProviderAccount; use Buckaroo\Magento2\Model\ConfigProvider\BuckarooFee as ConfigProviderBuckarooFee; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory; @@ -50,7 +50,7 @@ class BuckarooFee extends \Buckaroo\Magento2\Model\Total\Quote\BuckarooFee * @param PriceCurrencyInterface $priceCurrency * @param Data $catalogHelper * @param PaymentGroupTransaction $groupTransaction - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param TaxModelCalculation $taxCalculation */ public function __construct( @@ -60,7 +60,7 @@ public function __construct( PriceCurrencyInterface $priceCurrency, Data $catalogHelper, PaymentGroupTransaction $groupTransaction, - Log $logging, + BuckarooLoggerInterface $logger, TaxModelCalculation $taxCalculation ) { parent::__construct( @@ -70,7 +70,7 @@ public function __construct( $priceCurrency, $catalogHelper, $groupTransaction, - $logging, + $logger, $taxCalculation ); $this->setCode('pretax_buckaroo_fee'); diff --git a/Model/Validator/Push.php b/Model/Validator/Push.php index 205006fb0..19501ff82 100644 --- a/Model/Validator/Push.php +++ b/Model/Validator/Push.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Model\Validator; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ValidatorInterface; use Magento\Framework\Encryption\Encryptor; @@ -40,9 +40,9 @@ class Push implements ValidatorInterface public Data $helper; /** - * @var Log + * @var BuckarooLoggerInterface */ - public Log $logging; + public BuckarooLoggerInterface $logger; /** * @var Encryptor @@ -69,18 +69,18 @@ class Push implements ValidatorInterface /** * @param Data $helper * @param Account $configProviderAccount - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Encryptor $encryptor */ public function __construct( Data $helper, Account $configProviderAccount, - Log $logging, + BuckarooLoggerInterface $logger, Encryptor $encryptor ) { $this->helper = $helper; $this->configProviderAccount = $configProviderAccount; - $this->logging = $logging; + $this->logger = $logger; $this->encryptor = $encryptor; } @@ -176,7 +176,7 @@ public function calculateSignature(array $postData, $store = null): string $signature = SHA1($signatureString); - $this->logging->addDebug($signature); + $this->logger->addDebug($signature); return $signature; } diff --git a/Model/Voucher/ApplyVoucher.php b/Model/Voucher/ApplyVoucher.php index 409b85c62..e44a15fa7 100644 --- a/Model/Voucher/ApplyVoucher.php +++ b/Model/Voucher/ApplyVoucher.php @@ -24,7 +24,7 @@ use Buckaroo\Magento2\Api\ApplyVoucherInterface; use Buckaroo\Magento2\Api\Data\Giftcard\PayResponseInterface; use Buckaroo\Magento2\Api\Data\Giftcard\PayResponseSetInterfaceFactory; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Giftcard\Api\ApiException; use Buckaroo\Magento2\Model\Giftcard\Api\NoQuoteException; use Buckaroo\Magento2\Model\Giftcard\Response\Giftcard as GiftcardResponse; @@ -74,9 +74,9 @@ class ApplyVoucher implements ApplyVoucherInterface private GiftcardResponse $giftcardResponse; /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logger; + private BuckarooLoggerInterface $logger; /** * @param ApplyVoucherRequestInterface $voucherRequest @@ -85,7 +85,7 @@ class ApplyVoucher implements ApplyVoucherInterface * @param CartRepositoryInterface $cartRepository * @param PayResponseSetInterfaceFactory $payResponseFactory * @param Session $checkoutSession - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( ApplyVoucherRequestInterface $voucherRequest, @@ -94,7 +94,7 @@ public function __construct( CartRepositoryInterface $cartRepository, PayResponseSetInterfaceFactory $payResponseFactory, Session $checkoutSession, - Log $logger + BuckarooLoggerInterface $logger ) { $this->voucherRequest = $voucherRequest; $this->giftcardResponse = $giftcardResponse; diff --git a/Observer/GroupTransactionRegister.php b/Observer/GroupTransactionRegister.php index 652c60638..4c6dea0f7 100644 --- a/Observer/GroupTransactionRegister.php +++ b/Observer/GroupTransactionRegister.php @@ -25,7 +25,7 @@ use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; use Magento\Sales\Model\Order\Invoice; use Buckaroo\Magento2\Model\ConfigProvider\Account; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Helper\PaymentGroupTransaction; @@ -42,9 +42,9 @@ class GroupTransactionRegister implements ObserverInterface private $invoiceSender; /** - * @var Log + * @var BuckarooLoggerInterface */ - private $logger; + private BuckarooLoggerInterface $logger; /** * @var Data @@ -60,14 +60,14 @@ class GroupTransactionRegister implements ObserverInterface * @param Account $accountConfig * @param InvoiceSender $invoiceSender * @param PaymentGroupTransaction $groupTransaction - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param Data $helper */ public function __construct( Account $accountConfig, InvoiceSender $invoiceSender, PaymentGroupTransaction $groupTransaction, - Log $logger, + BuckarooLoggerInterface $logger, Data $helper ) { $this->accountConfig = $accountConfig; diff --git a/Observer/HandleFailedQuoteOrder.php b/Observer/HandleFailedQuoteOrder.php index c55ffc635..1c9b32ed7 100644 --- a/Observer/HandleFailedQuoteOrder.php +++ b/Observer/HandleFailedQuoteOrder.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Observer; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Session as BuckarooSession; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; @@ -38,9 +38,9 @@ class HandleFailedQuoteOrder implements ObserverInterface protected $buckarooSession; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logging; + protected BuckarooLoggerInterface $logger; /** * @var Manager @@ -54,18 +54,18 @@ class HandleFailedQuoteOrder implements ObserverInterface /** * @param BuckarooSession $buckarooSession - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Manager $moduleManager * @param OrderManagementInterface $orderManagement */ public function __construct( BuckarooSession $buckarooSession, - Log $logging, + BuckarooLoggerInterface $logger, Manager $moduleManager, OrderManagementInterface $orderManagement ) { $this->buckarooSession = $buckarooSession; - $this->logging = $logging; + $this->logger = $logger; $this->moduleManager = $moduleManager; $this->orderManagement = $orderManagement; } @@ -109,9 +109,9 @@ public function execute(Observer $observer) } try { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); if ($this->moduleManager->isEnabled('Magento_Inventory')) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); $this->buckarooSession->setData('flagHandleFailedQuote', 1); } $this->orderManagement->cancel($order->getId()); diff --git a/Observer/OrderCancelAfter.php b/Observer/OrderCancelAfter.php index f79373bdc..62f41fccb 100644 --- a/Observer/OrderCancelAfter.php +++ b/Observer/OrderCancelAfter.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Gateway\Http\Client\Json; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\Method\BuckarooAdapter; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\PayPerEmail; @@ -62,9 +62,9 @@ class OrderCancelAfter implements ObserverInterface protected $configProviderPPE; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logging; + protected BuckarooLoggerInterface $logger; /** * @param ScopeConfigInterface $scopeConfig @@ -72,7 +72,7 @@ class OrderCancelAfter implements ObserverInterface * @param Encryptor $encryptor * @param Account $configProviderAccount * @param PayPerEmail $configProviderPPE - * @param Log $logging + * @param BuckarooLoggerInterface $logger */ public function __construct( ScopeConfigInterface $scopeConfig, @@ -80,14 +80,14 @@ public function __construct( Encryptor $encryptor, Account $configProviderAccount, PayPerEmail $configProviderPPE, - Log $logging + BuckarooLoggerInterface $logger ) { $this->scopeConfig = $scopeConfig; $this->client = $client; $this->encryptor = $encryptor; $this->configProviderAccount = $configProviderAccount; $this->configProviderPPE = $configProviderPPE; - $this->logging = $logging; + $this->logger = $logger; } /** @@ -113,7 +113,7 @@ public function execute(Observer $observer) if ($cancelPPE && in_array($payment->getMethodInstance()->getCode(), ['buckaroo_magento2_payperemail'])) { try { - $this->logging->addDebug(__METHOD__ . '|sendCancelResponse|'); + $this->logger->addDebug(__METHOD__ . '|sendCancelResponse|'); $this->sendCancelResponse($originalKey); //phpcs:ignore: Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (\Exception $e) { diff --git a/Observer/SalesOrderShipmentAfter.php b/Observer/SalesOrderShipmentAfter.php index 3ec972fbb..cfdc6257e 100644 --- a/Observer/SalesOrderShipmentAfter.php +++ b/Observer/SalesOrderShipmentAfter.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Observer; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay20; use Buckaroo\Magento2\Model\ConfigProvider\Method\Klarnakp; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -72,9 +72,9 @@ class SalesOrderShipmentAfter implements ObserverInterface */ protected $transactionFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @var Klarnakp */ @@ -92,7 +92,7 @@ class SalesOrderShipmentAfter implements ObserverInterface * @param Klarnakp $klarnakpConfig * @param Afterpay20 $afterpayConfig * @param Data $helper - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( CollectionFactory $invoiceCollectionFactory, @@ -102,7 +102,7 @@ public function __construct( Klarnakp $klarnakpConfig, Afterpay20 $afterpayConfig, Data $helper, - Log $logger + BuckarooLoggerInterface $logger ) { $this->invoiceCollectionFactory = $invoiceCollectionFactory; $this->invoiceService = $invoiceService; diff --git a/Observer/SendInvoiceMail.php b/Observer/SendInvoiceMail.php index cde0c02f4..e6cb22a91 100644 --- a/Observer/SendInvoiceMail.php +++ b/Observer/SendInvoiceMail.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Observer; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay20; use Magento\Framework\Event\Observer; @@ -33,9 +33,9 @@ class SendInvoiceMail implements ObserverInterface { /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public $logging; + public BuckarooLoggerInterface $logger; /** * @var Data */ @@ -52,18 +52,18 @@ class SendInvoiceMail implements ObserverInterface /** * @param Account $accountConfig * @param InvoiceSender $invoiceSender - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper */ public function __construct( Account $accountConfig, InvoiceSender $invoiceSender, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper ) { $this->accountConfig = $accountConfig; $this->invoiceSender = $invoiceSender; - $this->logging = $logging; + $this->logger = $logger; $this->helper = $helper; } @@ -78,7 +78,7 @@ public function __construct( */ public function execute(Observer $observer) { - $this->logging->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(__METHOD__ . '|1|'); /** @var Invoice $invoice */ $invoice = $observer->getEvent()->getInvoice(); @@ -94,13 +94,13 @@ public function execute(Observer $observer) if (!$invoice->getEmailSent() && $invoice->getIsPaid() && $canCapture && $sendInvoiceEmail) { $invoice->save(); - $this->logging->addDebug(__METHOD__ . '|10|sendinvoiceemail'); + $this->logger->addDebug(__METHOD__ . '|10|sendinvoiceemail'); $orderBaseSubtotal = $order->getBaseSubtotal(); $orderBaseTaxAmount = $order->getBaseTaxAmount(); $orderBaseShippingAmount = $order->getBaseShippingAmount(); $this->invoiceSender->send($invoice, true); if (($orderBaseShippingAmount > 0) && ($order->getBaseShippingAmount() == 0)) { - $this->logging->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug(__METHOD__ . '|15|'); $invoice->getOrder()->setBaseShippingAmount($orderBaseShippingAmount); } $order->setBaseSubtotal($orderBaseSubtotal); @@ -111,7 +111,7 @@ public function execute(Observer $observer) && !$this->helper->areEqualAmounts($order->getBaseTotalPaid(), $order->getTotalPaid()) && ($order->getBaseCurrencyCode() == $order->getOrderCurrencyCode()) ) { - $this->logging->addDebug(__METHOD__ . '|25|'); + $this->logger->addDebug(__METHOD__ . '|25|'); $order->setBaseTotalPaid($order->getTotalPaid()); } } diff --git a/Observer/SendOrderConfirmation.php b/Observer/SendOrderConfirmation.php index dc1cee3c1..51927b964 100644 --- a/Observer/SendOrderConfirmation.php +++ b/Observer/SendOrderConfirmation.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Observer; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; @@ -31,9 +31,9 @@ class SendOrderConfirmation implements ObserverInterface { /** - * @var Log + * @var BuckarooLoggerInterface */ - public $logging; + public BuckarooLoggerInterface $logger; /** * @var Account */ @@ -46,16 +46,16 @@ class SendOrderConfirmation implements ObserverInterface /** * @param Account $accountConfig * @param OrderSender $orderSender - * @param Log $logging + * @param BuckarooLoggerInterface $logger */ public function __construct( Account $accountConfig, OrderSender $orderSender, - Log $logging + BuckarooLoggerInterface $logger ) { $this->accountConfig = $accountConfig; $this->orderSender = $orderSender; - $this->logging = $logging; + $this->logger = $logger; } /** @@ -96,7 +96,7 @@ public function execute(Observer $observer) && $order->getIncrementId() && !$createOrderBeforeTransaction ) { - $this->logging->addDebug(__METHOD__ . '|sendemail|'); + $this->logger->addDebug(__METHOD__ . '|sendemail|'); $this->orderSender->send($order, true); } } diff --git a/Plugin/CommandInterface.php b/Plugin/CommandInterface.php index e0ab23fa2..42bba93a0 100644 --- a/Plugin/CommandInterface.php +++ b/Plugin/CommandInterface.php @@ -23,7 +23,7 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory; use Buckaroo\Magento2\Model\ConfigProvider\Method\PayPerEmail; use Magento\Payment\Model\MethodInterface; @@ -35,9 +35,9 @@ class CommandInterface { /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public Log $logging; + public BuckarooLoggerInterface $logger; /** * @var Factory @@ -51,16 +51,16 @@ class CommandInterface /** * @param Factory $configProviderMethodFactory - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param Data $helper */ public function __construct( Factory $configProviderMethodFactory, - Log $logging, + BuckarooLoggerInterface $logger, Data $helper ) { $this->configProviderMethodFactory = $configProviderMethodFactory; - $this->logging = $logging; + $this->logger = $logger; $this->helper = $helper; } @@ -91,13 +91,13 @@ public function aroundExecute( $paymentAction = $methodInstance->getConfigPaymentAction(); $paymentCode = substr($methodInstance->getCode(), 0, 18); - $this->logging->addDebug(__METHOD__ . '|1|' . var_export([$methodInstance->getCode(), $paymentAction], true)); + $this->logger->addDebug(__METHOD__ . '|1|' . var_export([$methodInstance->getCode(), $paymentAction], true)); if ($paymentCode == 'buckaroo_magento2_' && $paymentAction) { if (($methodInstance->getCode() == PayPerEmail::CODE) && ($paymentAction == 'order')) { $config = $this->configProviderMethodFactory->get(PayPerEmail::CODE); if ($config->isEnabledB2B()) { - $this->logging->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(__METHOD__ . '|5|'); return $message; } } @@ -119,7 +119,7 @@ private function updateOrderStateAndStatus(OrderInterface $order, MethodInterfac $orderState = Order::STATE_NEW; $orderStatus = $this->helper->getOrderStatusByState($order, $orderState); - $this->logging->addDebug(__METHOD__ . '|5|' . var_export($orderStatus, true)); + $this->logger->addDebug(__METHOD__ . '|5|' . var_export($orderStatus, true)); if (( ( @@ -135,7 +135,7 @@ private function updateOrderStateAndStatus(OrderInterface $order, MethodInterfac && ($order->getState() === Order::STATE_PROCESSING) && ($order->getStatus() === Order::STATE_PROCESSING) ) { - $this->logging->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(__METHOD__ . '|10|'); return false; } diff --git a/Plugin/FixSession.php b/Plugin/FixSession.php index dc209b4e0..1aa723781 100644 --- a/Plugin/FixSession.php +++ b/Plugin/FixSession.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Plugin; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\HTTP\Header; use Magento\Framework\Session\SessionManager; use Magento\Framework\Stdlib\Cookie\PhpCookieManager; @@ -35,9 +35,9 @@ class FixSession protected Header $header; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var SessionManager @@ -46,12 +46,12 @@ class FixSession /** * @param Header $header - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param SessionManager $sessionManager */ public function __construct( Header $header, - Log $logger, + BuckarooLoggerInterface $logger, SessionManager $sessionManager ) { $this->header = $header; diff --git a/Plugin/GuestSaveManager.php b/Plugin/GuestSaveManager.php index f21026cf4..335324779 100644 --- a/Plugin/GuestSaveManager.php +++ b/Plugin/GuestSaveManager.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Plugin; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; // @codingStandardsIgnoreStart @@ -39,9 +39,9 @@ class GuestSaveManager extends \Onestepcheckout\Iosc\Plugin\GuestSaveManager protected $cartRepository; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected $logger; + protected BuckarooLoggerInterface $logger; /** * @param \Onestepcheckout\Iosc\Model\DataManager $dataManager @@ -51,7 +51,7 @@ class GuestSaveManager extends \Onestepcheckout\Iosc\Plugin\GuestSaveManager * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory * @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( \Onestepcheckout\Iosc\Model\DataManager $dataManager, /** @phpstan-ignore-line */ @@ -61,7 +61,7 @@ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory, \Magento\Quote\Api\CartRepositoryInterface $cartRepository, - Log $logger + BuckarooLoggerInterface $logger ) { $this->quoteIdMaskFactory = $quoteIdMaskFactory; $this->cartRepository = $cartRepository; diff --git a/Plugin/MyParcelNLBuckarooPlugin.php b/Plugin/MyParcelNLBuckarooPlugin.php index 6b6a20b4a..958cc885d 100644 --- a/Plugin/MyParcelNLBuckarooPlugin.php +++ b/Plugin/MyParcelNLBuckarooPlugin.php @@ -20,7 +20,7 @@ namespace Buckaroo\Magento2\Plugin; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Checkout\Model\Session; use Magento\Framework\App\RequestInterface; use Magento\Framework\Serialize\Serializer\Json; @@ -43,21 +43,21 @@ class MyParcelNLBuckarooPlugin protected Json $json; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @param Session $checkoutSession * @param RequestInterface $request * @param Json $json - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( Session $checkoutSession, RequestInterface $request, Json $json, - Log $logger + BuckarooLoggerInterface $logger ) { $this->checkoutSession = $checkoutSession; $this->request = $request; diff --git a/Plugin/Onepage/Success.php b/Plugin/Onepage/Success.php index a0b39fbd4..0238f51e7 100644 --- a/Plugin/Onepage/Success.php +++ b/Plugin/Onepage/Success.php @@ -22,7 +22,7 @@ namespace Buckaroo\Magento2\Plugin\Onepage; use Buckaroo\Magento2\Helper\Data as BuckarooDataHelper; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Service\CheckPaymentType; use Magento\Checkout\Controller\Onepage\Success as ControllerOnePageSuccess; use Magento\Framework\App\Action\Context; @@ -42,9 +42,9 @@ class Success protected RedirectFactory $resultRedirectFactory; /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var CheckPaymentType @@ -53,12 +53,12 @@ class Success /** * @param Context $context - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param CheckPaymentType $checkPaymentType */ public function __construct( Context $context, - Log $logger, + BuckarooLoggerInterface $logger, CheckPaymentType $checkPaymentType ) { $this->resultRedirectFactory = $context->getResultRedirectFactory(); diff --git a/Service/Applepay/Add.php b/Service/Applepay/Add.php index cc30feeb3..c4f49846f 100644 --- a/Service/Applepay/Add.php +++ b/Service/Applepay/Add.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Service\Applepay; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay; use Buckaroo\Magento2\Model\Service\ApplePayFormatData; use Buckaroo\Magento2\Model\Service\QuoteService; @@ -29,9 +29,9 @@ class Add { /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logger; + private BuckarooLoggerInterface $logger; /** * @var QuoteService @@ -44,12 +44,12 @@ class Add private ApplePayFormatData $applePayFormatData; /** - * @param Log $logger + * @param BuckarooLoggerInterface $logger * @param QuoteService $quoteService * @param ApplePayFormatData $applePayFormatData */ public function __construct( - Log $logger, + BuckarooLoggerInterface $logger, QuoteService $quoteService, ApplePayFormatData $applePayFormatData ) { diff --git a/Service/Formatter/Address/PhoneFormatter.php b/Service/Formatter/Address/PhoneFormatter.php index a9231fcca..44195b317 100644 --- a/Service/Formatter/Address/PhoneFormatter.php +++ b/Service/Formatter/Address/PhoneFormatter.php @@ -22,14 +22,14 @@ namespace Buckaroo\Magento2\Service\Formatter\Address; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; class PhoneFormatter { /** - * @var Log + * @var BuckarooLoggerInterface */ - private Log $logger; + private BuckarooLoggerInterface $logger; /** * @var array[] @@ -60,10 +60,10 @@ class PhoneFormatter ]; /** - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( - Log $logger + BuckarooLoggerInterface $logger ) { $this->logger = $logger; } diff --git a/Service/Push/OrderRequestService.php b/Service/Push/OrderRequestService.php index 6373e72f6..19224a2b7 100644 --- a/Service/Push/OrderRequestService.php +++ b/Service/Push/OrderRequestService.php @@ -23,7 +23,7 @@ use Buckaroo\Exceptions\BuckarooException; use Buckaroo\Magento2\Api\PushRequestInterface; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Phrase; use Magento\Sales\Api\Data\TransactionInterface; @@ -42,9 +42,9 @@ class OrderRequestService public $order = null; /** - * @var Log $logging + * @var BuckarooLoggerInterface $logger */ - public Log $logging; + public BuckarooLoggerInterface $logger; /** * @var Transaction @@ -68,7 +68,7 @@ class OrderRequestService /** * @param Order $order - * @param Log $logging + * @param BuckarooLoggerInterface $logger * @param TransactionInterface $transaction * @param OrderSender $orderSender * @param InvoiceSender $invoiceSender @@ -76,14 +76,14 @@ class OrderRequestService */ public function __construct( Order $order, - Log $logging, + BuckarooLoggerInterface $logger, TransactionInterface $transaction, OrderSender $orderSender, InvoiceSender $invoiceSender, ResourceConnection $resourceConnection ) { $this->order = $order; - $this->logging = $logging; + $this->logger = $logger; $this->transaction = $transaction; $this->orderSender = $orderSender; $this->invoiceSender = $invoiceSender; @@ -107,7 +107,7 @@ public function getOrderByRequest(?PushRequestInterface $pushRequest = null) $this->order->loadByIncrementId((string)$brqOrderId); if (!$this->order->getId()) { - $this->logging->addDebug('Order could not be loaded by Invoice Number or Order Number'); + $this->logger->addDebug('Order could not be loaded by Invoice Number or Order Number'); // Try to get order by transaction id on payment. $this->order = $this->getOrderByTransactionKey($pushRequest); } @@ -196,7 +196,7 @@ public function setOrderNotificationNote($message): void $this->order->addStatusToHistory($note); $this->order->save(); } catch (\Exception $e) { - $this->logging->addDebug($e->getLogMessage()); + $this->logger->addDebug($e->getLogMessage()); } } @@ -218,10 +218,10 @@ public function updateOrderStatus( bool $force = false, bool $dontSaveOrderUponSuccessPush = false ): void { - $this->logging->addDebug(__METHOD__ . '|0|' . var_export([$orderState, $newStatus, $description], true)); + $this->logger->addDebug(__METHOD__ . '|0|' . var_export([$orderState, $newStatus, $description], true)); if ($this->order->getState() == $orderState || $force) { - $this->logging->addDebug(__METHOD__ . '|1|'); - $this->logging->addDebug('||| $orderState: ' . '|1|' . $orderState); + $this->logger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug('||| $orderState: ' . '|1|' . $orderState); if ($dontSaveOrderUponSuccessPush) { $this->order->addCommentToStatusHistory($description) ->setIsCustomerNotified(false) @@ -232,8 +232,8 @@ public function updateOrderStatus( $this->order->addCommentToStatusHistory($description, $newStatus); } } else { - $this->logging->addDebug(__METHOD__ . '|2|'); - $this->logging->addDebug('||| $orderState: ' . '|2|' . $orderState); + $this->logger->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug('||| $orderState: ' . '|2|' . $orderState); if ($dontSaveOrderUponSuccessPush) { $this->order->addCommentToStatusHistory($description) ->setIsCustomerNotified(false) @@ -319,7 +319,7 @@ public function loadOrder() $this->order->loadByIncrementId((string)$brqOrderId); if (!$this->order->getId()) { - $this->logging->addDebug('Order could not be loaded by Invoice Number or Order Number'); + $this->logger->addDebug('Order could not be loaded by Invoice Number or Order Number'); // try to get order by transaction id on payment. $this->order = $this->getOrderByTransactionKey(); } diff --git a/Service/RefundGroupTransactionService.php b/Service/RefundGroupTransactionService.php index 9e8a2d014..cb0bfaf44 100644 --- a/Service/RefundGroupTransactionService.php +++ b/Service/RefundGroupTransactionService.php @@ -31,7 +31,7 @@ use Magento\Payment\Gateway\Http\TransferFactoryInterface; use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Response\HandlerInterface; -use Buckaroo\Magento2\Logging\Log as BuckarooLog; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface as BuckarooLog; class RefundGroupTransactionService { diff --git a/Service/Sales/Quote/Recreate.php b/Service/Sales/Quote/Recreate.php index 142b0bf41..2d81bfb8c 100644 --- a/Service/Sales/Quote/Recreate.php +++ b/Service/Sales/Quote/Recreate.php @@ -21,7 +21,7 @@ namespace Buckaroo\Magento2\Service\Sales\Quote; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Magento\Checkout\Model\Cart; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\Quote; @@ -29,9 +29,9 @@ class Recreate { /** - * @var Log + * @var BuckarooLoggerInterface */ - protected Log $logger; + protected BuckarooLoggerInterface $logger; /** * @var Cart */ @@ -39,11 +39,11 @@ class Recreate /** * @param Cart $cart - * @param Log $logger + * @param BuckarooLoggerInterface $logger */ public function __construct( Cart $cart, - Log $logger + BuckarooLoggerInterface $logger ) { $this->cart = $cart; $this->logger = $logger; diff --git a/Test/Unit/Model/PushTest.php b/Test/Unit/Model/PushTest.php index ff7186f4e..4eb36c801 100644 --- a/Test/Unit/Model/PushTest.php +++ b/Test/Unit/Model/PushTest.php @@ -31,7 +31,7 @@ use Magento\Sales\Model\Order\Payment; use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\Method\BuckarooAdapter; -use Buckaroo\Magento2\Logging\Log; +use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Model\Push; @@ -188,7 +188,7 @@ public function testLoadOrderWillThrowException() $transactionMock->expects($this->once())->method('load')->with('', 'txn_id'); $transactionMock->expects($this->once())->method('getOrder')->willReturn(null); - $instance = $this->getInstance(['transaction' => $transactionMock, 'logging' => $debuggerMock]); + $instance = $this->getInstance(['transaction' => $transactionMock, 'logger' => $debuggerMock]); $this->expectException(Exception::class); $this->invoke('loadOrder', $instance); diff --git a/etc/di.xml b/etc/di.xml index 8ec1b9098..f88cd6f5e 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -32,7 +32,7 @@ - + @@ -357,6 +357,16 @@ + + + buckaroo_log + + Buckaroo\Magento2\Logging\CriticalHandler + Buckaroo\Magento2\Logging\DebugHandler + + + + Buckaroo\Magento2\Model\RefundFieldsFactory From 9d547bd0db76c3e9c51267ffd492e1f7d9480820 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Mon, 21 Aug 2023 16:00:16 +0300 Subject: [PATCH 2/6] BP-2433 - Add Logging more descriptive for redirect and refactor the class --- .../Notification/MarkUserNotified.php | 10 +- Controller/Applepay/Add.php | 16 +- Controller/Applepay/GetShippingMethods.php | 25 +- Controller/Applepay/SaveOrder.php | 41 +-- Controller/Checkout/Giftcard.php | 18 +- Controller/Checkout/Idin.php | 6 +- Controller/Payconiq/Process.php | 11 +- Controller/Pos/CheckOrderStatus.php | 10 - Controller/Pos/SetTerminal.php | 10 +- Controller/Redirect/IdinProcess.php | 15 +- Controller/Redirect/Process.php | 234 +++++++++++------- Helper/Data.php | 6 +- Model/GuestPaymentInformationManagement.php | 8 +- Model/PaymentInformationManagement.php | 8 +- Model/Push.php | 2 +- Plugin/MyParcelNLBuckarooPlugin.php | 8 +- 16 files changed, 264 insertions(+), 164 deletions(-) diff --git a/Controller/Adminhtml/Notification/MarkUserNotified.php b/Controller/Adminhtml/Notification/MarkUserNotified.php index 9197d1a5b..9e63927a7 100644 --- a/Controller/Adminhtml/Notification/MarkUserNotified.php +++ b/Controller/Adminhtml/Notification/MarkUserNotified.php @@ -32,12 +32,12 @@ class MarkUserNotified extends Action /** * @var FlagManager $flagManager */ - private $flagManager; + private FlagManager $flagManager; /** * @var LoggerInterface $logger */ - private $logger; + private LoggerInterface $logger; /** * @param Context $context @@ -68,7 +68,11 @@ public function execute() 'error_message' => '' ]; } catch (\Exception $e) { - $this->logger->error($e->getMessage()); + $this->logger->error(sprintf( + '[ReleaseNotification] | [Controller] | [%s] - Failed to set flag release notification | [ERROR]: %s', + __METHOD__, + $e->getMessage() + )); $responseContent = [ 'success' => false, 'error_message' => __('Failed to set flag that user has seen screen') diff --git a/Controller/Applepay/Add.php b/Controller/Applepay/Add.php index 2e7b57df5..5c80a486e 100644 --- a/Controller/Applepay/Add.php +++ b/Controller/Applepay/Add.php @@ -32,7 +32,7 @@ class Add extends AbstractApplepay /** * @var AddService */ - protected $addService; + protected AddService $addService; /** * @param JsonFactory $resultJsonFactory @@ -61,10 +61,20 @@ public function __construct( */ public function execute() { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($this->getParams(), true)); + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Add Product to Cart | request: %s', + __METHOD__, __LINE__, + var_export($this->getParams(), true) + )); + $data = $this->addService->process($this->getParams()); $errorMessage = $data['error'] ?? false; - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($data, true)); + + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Add Product to Cart | response: %s', + __METHOD__, __LINE__, + var_export($data, true) + )); return $this->commonResponse($data, $errorMessage); } diff --git a/Controller/Applepay/GetShippingMethods.php b/Controller/Applepay/GetShippingMethods.php index 1b48834d1..c11038e9d 100644 --- a/Controller/Applepay/GetShippingMethods.php +++ b/Controller/Applepay/GetShippingMethods.php @@ -37,12 +37,12 @@ class GetShippingMethods extends AbstractApplepay /** * @var QuoteService */ - private $quoteService; + private QuoteService $quoteService; /** * @var ApplePayFormatData */ - private $applePayFormatData; + private ApplePayFormatData $applePayFormatData; /** * @param JsonFactory $resultJsonFactory @@ -75,7 +75,12 @@ public function __construct( public function execute() { $postValues = $this->getParams(); - $this->logger->addDebug(__METHOD__ . '|1| post Values: ' . var_export($postValues, true)); + + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Get Shipping Methods | request: %s', + __METHOD__, __LINE__, + var_export($postValues, true) + )); $data = []; $errorMessage = false; @@ -114,15 +119,15 @@ public function execute() 'totals' => $totals ]; } catch (\Exception $exception) { - $this->logger->addDebug(__METHOD__ . '|exception|' . $exception->getMessage()); - $errorMessage = __( - 'Get shipping methods failed' - ); + $this->logger->addError(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Get Shipping Methods | [ERROR]: %s', + __METHOD__, __LINE__, + $exception->getMessage() + )); + $errorMessage = __('Get shipping methods failed'); } } else { - $errorMessage = __( - 'Details from Wallet ApplePay are not received.' - ); + $errorMessage = __('Details from Wallet ApplePay are not received.'); } return $this->commonResponse($data, $errorMessage); diff --git a/Controller/Applepay/SaveOrder.php b/Controller/Applepay/SaveOrder.php index e3edcf4c9..95a00e004 100644 --- a/Controller/Applepay/SaveOrder.php +++ b/Controller/Applepay/SaveOrder.php @@ -167,9 +167,11 @@ public function execute() && ($payment = $isPost['payment']) && ($extra = $isPost['extra']) ) { - $this->logger->addDebug(__METHOD__ . '|1|'); - $this->logger->addDebug(var_export($payment, true)); - $this->logger->addDebug(var_export($extra, true)); + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Save Order | request: %s', + __METHOD__, __LINE__, + var_export($isPost, true) + )); // Get Cart $quote = $this->checkoutSession->getQuote(); @@ -202,8 +204,6 @@ public function execute() */ private function submitQuote($quote, $extra) { - $this->logger->addDebug(__METHOD__ . '|2|'); - try { if (!($this->customerSession->getCustomer() && $this->customerSession->getCustomer()->getId())) { $quote->setCheckoutMethod('guest') @@ -222,7 +222,11 @@ private function submitQuote($quote, $extra) $this->quoteManagement->submit($quote); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . '|exception|' . var_export($th->getMessage(), true)); + $this->logger->addError(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Submit Quote | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); } } @@ -236,20 +240,22 @@ private function handleResponse() $data = []; if ($this->registry && $this->registry->registry('buckaroo_response')) { $data = $this->registry->registry('buckaroo_response')[0]; - $this->logger->addDebug(__METHOD__ . '|4|' . var_export($data, true)); + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Save Order Handle Response | buckarooResponse: %s', + __METHOD__, __LINE__, + var_export($data, true) + )); if (!empty($data->RequiredAction->RedirectURL)) { //test mode - $this->logger->addDebug(__METHOD__ . '|5|'); $data = [ 'RequiredAction' => $data->RequiredAction ]; } else { //live mode - $this->logger->addDebug(__METHOD__ . '|6|'); if (isset($data['Status']['Code']['Code']) && $data['Status']['Code']['Code'] == '190' && isset($data['Order']) ) { - $this->processBuckarooResponse($data); + $data = $this->processBuckarooResponse($data); } } } @@ -261,12 +267,11 @@ private function handleResponse() * Set Order and Quote Data on Checkout Session * * @param array|object $data - * @return void + * @return array|object */ - private function processBuckarooResponse(&$data) + private function processBuckarooResponse($data) { - $searchCriteria = $this->searchCriteriaBuilder - ->addFilter('increment_id', $data['Order'], 'eq')->create(); + $searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', $data['Order'])->create(); $order = $this->orderRepository->getList($searchCriteria)->getFirstItem(); if ($order->getId()) { @@ -279,12 +284,18 @@ private function processBuckarooResponse(&$data) $store = $order->getStore(); $url = $store->getBaseUrl() . '/' . $this->accountConfig->getSuccessRedirect($store); - $this->logger->addDebug(__METHOD__ . '|7|' . var_export($url, true)); + $this->logger->addDebug(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Save Order - Redirect URL | redirectURL: %s', + __METHOD__, __LINE__, + $url + )); $data = [ 'RequiredAction' => [ 'RedirectURL' => $url ] ]; } + + return $data; } } diff --git a/Controller/Checkout/Giftcard.php b/Controller/Checkout/Giftcard.php index 4d26ec3cb..79e898957 100644 --- a/Controller/Checkout/Giftcard.php +++ b/Controller/Checkout/Giftcard.php @@ -45,17 +45,17 @@ class Giftcard extends Action implements HttpPostActionInterface, HttpGetActionI /** * @var GiftcardInterface */ - protected $giftcardRequest; + protected GiftcardInterface $giftcardRequest; /** * @var GiftcardResponse */ - protected $giftcardResponse; + protected GiftcardResponse $giftcardResponse; /** * @var Session */ - protected $checkoutSession; + protected Session $checkoutSession; /** * @param Context $context @@ -106,10 +106,18 @@ public function execute() $this->build($quote)->send() ); } catch (ApiException $th) { - $this->logger->addDebug(__METHOD__ . (string)$th); + $this->logger->addError(sprintf( + '[Giftcard] | [Controller] | [%s:%s] - Apply Inline Giftcard | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); return $this->displayError($th->getMessage()); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . (string)$th); + $this->logger->addError(sprintf( + '[Giftcard] | [Controller] | [%s:%s] - Apply Inline Giftcard | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); return $this->displayError(__('Unknown buckaroo error has occurred')); } } diff --git a/Controller/Checkout/Idin.php b/Controller/Checkout/Idin.php index 6f7f48288..da8837e48 100644 --- a/Controller/Checkout/Idin.php +++ b/Controller/Checkout/Idin.php @@ -108,7 +108,11 @@ public function execute() ); } } catch (\Throwable $th) { - $this->logger->addError($th->getMessage()); + $this->logger->addError(sprintf( + '[iDIN] | [Controller] | [%s:%s] - Validate iDIN | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); return $this->json( ['error' => 'Unknown buckaroo error occurred'] ); diff --git a/Controller/Payconiq/Process.php b/Controller/Payconiq/Process.php index 66c53d4b4..030cb4fa5 100644 --- a/Controller/Payconiq/Process.php +++ b/Controller/Payconiq/Process.php @@ -125,10 +125,13 @@ public function execute() $this->order = $transaction->getOrder()->getOrder(); if ($this->customerSession->getCustomerId() == $this->order->getCustomerId()) { - $this->logger->addError('Customer is different then the customer that start payconiq process request.'); - $this->messageManager->addErrorMessage( - 'Customer is different then the customer that start payconiq process request.' - ); + $errorMessage = 'Customer is different then the customer that start Payconiq process request.'; + $this->logger->addError(sprintf( + '[REDIRECT - Payconiq] | [Controller] | [%s:%s] - %s', + __METHOD__, __LINE__, + $errorMessage + )); + $this->messageManager->addErrorMessage($errorMessage); return $this->handleProcessedResponse( 'checkout', [ diff --git a/Controller/Pos/CheckOrderStatus.php b/Controller/Pos/CheckOrderStatus.php index c5da97a6c..8f28e5c83 100644 --- a/Controller/Pos/CheckOrderStatus.php +++ b/Controller/Pos/CheckOrderStatus.php @@ -22,7 +22,6 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\Data; -use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Factory; use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Customer\Model\Session; @@ -40,11 +39,6 @@ */ class CheckOrderStatus extends Action { - /** - * @var BuckarooLoggerInterface - */ - protected BuckarooLoggerInterface $logger; - /** * @var Order $order */ @@ -87,7 +81,6 @@ class CheckOrderStatus extends Action /** * @param Context $context - * @param BuckarooLoggerInterface $logger * @param Order $order * @param JsonFactory $resultJsonFactory * @param Factory $configProviderFactory @@ -102,7 +95,6 @@ class CheckOrderStatus extends Action */ public function __construct( Context $context, - BuckarooLoggerInterface $logger, Order $order, JsonFactory $resultJsonFactory, Factory $configProviderFactory, @@ -113,7 +105,6 @@ public function __construct( Session $customerSession ) { parent::__construct($context); - $this->logger = $logger; $this->order = $order; $this->resultJsonFactory = $resultJsonFactory; $this->accountConfig = $configProviderFactory->get('account'); @@ -132,7 +123,6 @@ public function __construct( */ public function execute() { - $this->logger->addDebug(__METHOD__ . '|1|'); $response = ['success' => 'false', 'redirect' => '']; if (($params = $this->getRequest()->getParams()) && !empty($params['orderId'])) { diff --git a/Controller/Pos/SetTerminal.php b/Controller/Pos/SetTerminal.php index d9d0c1830..0577d996a 100644 --- a/Controller/Pos/SetTerminal.php +++ b/Controller/Pos/SetTerminal.php @@ -96,9 +96,14 @@ public function __construct( */ public function execute() { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($this->getRequest()->getParams(), true)); + $params = $this->getRequest()->getParams(); + $this->logger->addDebug(sprintf( + '[POS] | [Controller] | [%s:%s] - Set Terminal | request: %s', + __METHOD__, __LINE__, + var_export($params, true) + )); - if (($params = $this->getRequest()->getParams()) && !empty($params['id'])) { + if (!empty($params['id'])) { $metadata = $this->cookieMetadataFactory ->createPublicCookieMetadata() ->setPath('/') @@ -108,7 +113,6 @@ public function execute() $params['id'], $metadata ); - $this->logger->addDebug(__METHOD__ . '|2|'); } $redirectUrl = $this->storemanager->getStore()->getBaseUrl(); diff --git a/Controller/Redirect/IdinProcess.php b/Controller/Redirect/IdinProcess.php index e89139be8..1157a3fef 100644 --- a/Controller/Redirect/IdinProcess.php +++ b/Controller/Redirect/IdinProcess.php @@ -131,7 +131,11 @@ private function setCustomerIDIN(): bool $customerNew = $this->customerRepository->getById((int)$idinCid); } catch (\Exception $e) { $this->addErrorMessage(__('Unfortunately customer was not find by IDIN id: "%1"!', $idinCid)); - $this->logger->addError(__METHOD__ . ' | ' . $e->getMessage()); + $this->logger->addError(sprintf( + '[REDIRECT - iDIN] | [Controller] | [%s:%s] - Customer was not find by IDIN id | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); return false; } $customerData = $customerNew->getDataModel(); @@ -155,12 +159,17 @@ private function setCustomerIDIN(): bool */ protected function redirectToCheckout(): ResponseInterface { - $this->logger->addDebug('start redirectToCheckout'); + $this->logger->addDebug('[REDIRECT - iDIN] | [Controller] | ['.__METHOD__.'] - start redirectToCheckout'); + try { $this->checkoutSession->restoreQuote(); } catch (\Exception $e) { - $this->logger->addError('Could not restore the quote.'); + $this->logger->addError(sprintf( + '[REDIRECT - iDIN] | [Controller] | [%s:%s] - Could not restore the quote | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } return $this->handleProcessedResponse('checkout', ['_query' => ['bk_e' => 1]]); diff --git a/Controller/Redirect/Process.php b/Controller/Redirect/Process.php index cfa8c38c4..436fdbc6c 100644 --- a/Controller/Redirect/Process.php +++ b/Controller/Redirect/Process.php @@ -189,7 +189,11 @@ public function __construct( */ public function execute() { - $this->logger->addDebug(__METHOD__ . '|' . var_export($this->redirectRequest->getOriginalRequest(), true)); + $this->logger->addDebug(sprintf( + '[REDIRECT] | [Controller] | [%s:%s] - Original Request | originalRequest: %s', + __METHOD__, __LINE__, + var_export($this->redirectRequest->getOriginalRequest(), true) + )); if (count($this->redirectRequest->getData()) === 0 || empty($this->redirectRequest->getStatusCode())) { return $this->handleProcessedResponse('/'); @@ -215,15 +219,19 @@ public function execute() return $this->handleProcessedResponse('/'); } - $this->logger->addDebug(__METHOD__ . '|2|' . var_export($statusCode, true)); - if (($this->payment->getMethodInstance()->getCode() == 'buckaroo_magento2_paypal') && ($statusCode == BuckarooStatusCode::PENDING_PROCESSING) ) { $statusCode = BuckarooStatusCode::CANCELLED_BY_USER; - $this->logger->addDebug(__METHOD__ . '|22|' . var_export($statusCode, true)); } + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Status Code | statusCode: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $statusCode + )); + return $this->processRedirectByStatus($statusCode); } @@ -237,7 +245,6 @@ public function execute() */ public function handleProcessedResponse(string $path, array $arguments = []): ResponseInterface { - $this->logger->addDebug(__METHOD__ . '|15|'); return $this->_redirect($path, $arguments); } @@ -360,7 +367,11 @@ private function sendKlarnaKpOrderConfirmation(int $statusCode): void && $isKlarnaKpReserve && $statusCode == BuckarooStatusCode::SUCCESS) ) { - $this->logger->addDebug(__METHOD__ . '|sendemail|'); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Send Klarna Reservation Mail', + $this->payment->getMethod(), + __METHOD__, __LINE__ + )); $this->orderRequestService->sendOrderEmail($this->order, true); } } @@ -377,7 +388,11 @@ private function sendKlarnaKpOrderConfirmation(int $statusCode): void */ private function setLastQuoteOrder(): void { - $this->logger->addDebug(__METHOD__ . '|51|' . var_export([ + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Set Last Quote Order | currentQuoteOrder: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + var_export([ $this->checkoutSession->getLastSuccessQuoteId(), $this->checkoutSession->getLastQuoteId(), $this->checkoutSession->getLastOrderId(), @@ -385,22 +400,19 @@ private function setLastQuoteOrder(): void $this->order->getQuoteId(), $this->order->getId(), $this->order->getIncrementId(), - ], true)); + ], true) + )); if (!$this->checkoutSession->getLastSuccessQuoteId() && $this->order->getQuoteId()) { - $this->logger->addDebug(__METHOD__ . '|52|'); $this->checkoutSession->setLastSuccessQuoteId($this->order->getQuoteId()); } if (!$this->checkoutSession->getLastQuoteId() && $this->order->getQuoteId()) { - $this->logger->addDebug(__METHOD__ . '|53|'); $this->checkoutSession->setLastQuoteId($this->order->getQuoteId()); } if (!$this->checkoutSession->getLastOrderId() && $this->order->getId()) { - $this->logger->addDebug(__METHOD__ . '|54|'); $this->checkoutSession->setLastOrderId($this->order->getId()); } if (!$this->checkoutSession->getLastRealOrderId() && $this->order->getIncrementId()) { - $this->logger->addDebug(__METHOD__ . '|55|'); $this->checkoutSession->setLastRealOrderId($this->order->getIncrementId()); } } @@ -412,8 +424,6 @@ private function setLastQuoteOrder(): void */ protected function redirectSuccess(): ResponseInterface { - $this->logger->addDebug(__METHOD__ . '|1|'); - $this->eventManager->dispatch('buckaroo_process_redirect_success_before'); $store = $this->order->getStore(); @@ -429,7 +439,12 @@ protected function redirectSuccess(): ResponseInterface $this->redirectSuccessApplePay(); - $this->logger->addDebug(__METHOD__ . '|2|' . var_export($url, true)); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect Success | redirectURL: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $url, + )); return $this->handleProcessedResponse($url); } @@ -457,8 +472,6 @@ protected function redirectSuccessApplePay(): void && $this->redirectRequest->hasPostData('status_code', '190') && $this->redirectRequest->hasPostData('test', 'true') ) { - $this->logger->addDebug(__METHOD__); - $this->checkoutSession ->setLastQuoteId($this->order->getQuoteId()) ->setLastSuccessQuoteId($this->order->getQuoteId()) @@ -486,13 +499,17 @@ protected function redirectSuccessApplePay(): void private function processPendingRedirect($statusCode): ResponseInterface { if ($this->order->canInvoice()) { - $this->logger->addDebug(__METHOD__ . '|33|'); $pendingStatus = $this->orderStatusFactory->get( BuckarooStatusCode::PENDING_PROCESSING, $this->order ); if ($pendingStatus) { - $this->logger->addDebug(__METHOD__ . '|34|' . var_export($pendingStatus, true)); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect Pending Set Status | pendingStatus: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + var_export($pendingStatus, true), + )); $this->order->setStatus($pendingStatus); $this->order->save(); } @@ -501,10 +518,12 @@ private function processPendingRedirect($statusCode): ResponseInterface $this->sendKlarnaKpOrderConfirmation($statusCode); if (!$this->redirectRequest->hasPostData('payment_method', 'sofortueberweisung')) { - $this->addErrorMessage( - __(self::GENERAL_ERROR_MESSAGE) - ); - $this->logger->addDebug(__METHOD__ . '|5|'); + $this->addErrorMessage(__(self::GENERAL_ERROR_MESSAGE)); + + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect Pending NOT Sofort - Remove Coupon & Giftcard', + $this->payment->getMethod(), + __METHOD__, __LINE__)); $this->removeCoupon(); $this->removeAmastyGiftcardOnFailed(); @@ -529,6 +548,32 @@ public function addErrorMessage($message): void $this->messageManager->addErrorMessage($message); } + /** + * Remove coupon from failed order if magento enterprise + * + * @return void + */ + protected function removeCoupon() + { + if (method_exists($this->order, 'getCouponCode')) { + $couponCode = $this->order->getCouponCode(); + $couponFactory = $this->_objectManager->get(\Magento\SalesRule\Model\CouponFactory::class); + if (!(is_object($couponFactory) && method_exists($couponFactory, 'load'))) { + return; + } + + $coupon = $couponFactory->load($couponCode, 'code'); + $resourceModel = $this->_objectManager->get(\Magento\SalesRule\Model\Spi\CouponResourceInterface::class); + if (!(is_object($resourceModel) && method_exists($resourceModel, 'delete'))) { + return; + } + + if (is_int($coupon->getCouponId())) { + $resourceModel->delete($coupon); + } + } + } + /** * Remove amasty giftcard from failed order * @@ -557,7 +602,12 @@ protected function removeAmastyGiftcardOnFailed(): void $giftcardAccountRepository->save($giftcard); } } catch (\Throwable $th) { - $this->logger->addDebug($th->getMessage()); + $this->logger->addError(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Remove Amasty Giftcard | [ERROR]: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $th->getMessage() + )); return; } } @@ -572,15 +622,17 @@ protected function removeAmastyGiftcardOnFailed(): void */ protected function handleFailed($statusCode): ResponseInterface { - $this->logger->addDebug(__METHOD__ . '|7|'); - $this->eventManager->dispatch('buckaroo_process_handle_failed_before'); $this->removeAmastyGiftcardOnFailed(); if (!$this->getSkipHandleFailedRecreate() && (!$this->quoteRecreate->recreate($this->quote))) { - $this->logger->addError('Could not recreate the quote.'); + + $this->logger->addError(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Could not Recreate Quote on Failed ', + $this->payment->getMethod(), + __METHOD__, __LINE__)); } /* @@ -597,10 +649,17 @@ protected function handleFailed($statusCode): ResponseInterface } if (!$this->cancelOrder($statusCode)) { - $this->logger->addError('Could not cancel the order.'); + $this->logger->addError(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Could not Cancel the Order.', + $this->payment->getMethod(), + __METHOD__, __LINE__)); } - $this->logger->addDebug(__METHOD__ . '|8|'); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect Failure', + $this->payment->getMethod(), + __METHOD__, __LINE__)); + return $this->redirectFailure(); } @@ -629,11 +688,7 @@ public function addErrorMessageByStatus(int $statusCode): void $statusCodeAddErrorMessage[BuckarooStatusCode::CANCELLED_BY_USER] = __('According to our system, you have canceled the payment. If this is not the case, please contact us.'); - $this->addErrorMessage( - __( - $statusCodeAddErrorMessage[$statusCode] - ) - ); + $this->addErrorMessage(__($statusCodeAddErrorMessage[$statusCode])); } /** @@ -645,14 +700,10 @@ public function addErrorMessageByStatus(int $statusCode): void protected function redirectFailure(): ResponseInterface { $store = $this->order->getStore(); - $this->logger->addDebug('start redirectFailure'); if ($this->accountConfig->getFailureRedirectToCheckout($store)) { return $this->redirectOnCheckoutForFailedTransaction(); } - /** - * @noinspection PhpUndefinedMethodInspection - */ $url = $this->accountConfig->getFailureRedirect($store); return $this->handleProcessedResponse($url); @@ -674,29 +725,60 @@ protected function redirectFailure(): ResponseInterface */ private function redirectOnCheckoutForFailedTransaction(): ResponseInterface { - $this->logger->addDebug('getFailureRedirectToCheckout'); - if (!$this->customerSession->isLoggedIn() && ($this->order->getCustomerId() > 0)) { - $this->logger->addDebug('not isLoggedIn'); - $this->logger->addDebug('getCustomerId > 0'); + $this->setCustomerAndRestoreQuote('failed'); + + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect Failure To Checkout', + $this->payment->getMethod(), + __METHOD__, __LINE__)); + + return $this->handleProcessedResponse('checkout', ['_fragment' => 'payment', '_query' => ['bk_e' => 1]]); + } + + /** + * Set customer if it is set on order and not on session and restore quote + * + * @param string $status + * @return void + */ + protected function setCustomerAndRestoreQuote(string $status): void + { + if (!$this->customerSession->isLoggedIn() && $this->order->getCustomerId() > 0) { + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect %s To Checkout - Customer is not logged in', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $status + ) + ); try { $customer = $this->customerRepository->getById($this->order->getCustomerId()); $this->customerSession->setCustomerDataAsLoggedIn($customer); if (!$this->checkoutSession->getLastRealOrderId() && $this->order->getIncrementId()) { $this->checkoutSession->setLastRealOrderId($this->order->getIncrementId()); - $this->logger->addDebug(__METHOD__ . '|setLastRealOrderId|'); - if (!$this->getSkipHandleFailedRecreate()) { + if ($status == 'success' || !$this->getSkipHandleFailedRecreate()) { $this->checkoutSession->restoreQuote(); - $this->logger->addDebug(__METHOD__ . '|restoreQuote|'); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect %s To Checkout - Restore Quote', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $status)); + } + if ($status == 'failed') { + $this->setSkipHandleFailedRecreate(); } } - $this->setSkipHandleFailedRecreate(); } catch (\Exception $e) { - $this->logger->addError('Could not load customer'); + $this->logger->addError(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect %s To Checkout ' . + '- Could not load customer | [ERROR]: %s', + $this->payment->getMethod(), + __METHOD__, __LINE__, + $status, + $e->getMessage())); } } - $this->logger->addDebug('ready for redirect'); - return $this->handleProcessedResponse('checkout', ['_fragment' => 'payment', '_query' => ['bk_e' => 1]]); } /** @@ -731,32 +813,6 @@ public function getOrder() return $this->order; } - /** - * Remove coupon from failed order if magento enterprise - * - * @return void - */ - protected function removeCoupon() - { - if (method_exists($this->order,'getCouponCode')) { - $couponCode = $this->order->getCouponCode(); - $couponFactory = $this->_objectManager->get(\Magento\SalesRule\Model\CouponFactory::class); - if (!(is_object($couponFactory) && method_exists($couponFactory, 'load'))) { - return; - } - - $coupon = $couponFactory->load($couponCode, 'code'); - $resourceModel = $this->_objectManager->get(\Magento\SalesRule\Model\Spi\CouponResourceInterface::class); - if (!(is_object($resourceModel) && method_exists($resourceModel, 'delete'))) { - return; - } - - if (is_int($coupon->getCouponId())) { - $resourceModel->delete($coupon); - } - } - } - /** * Get Response Parameters * @@ -774,27 +830,13 @@ public function getResponseParameters() */ protected function redirectToCheckout(): ResponseInterface { - $this->logger->addDebug('start redirectToCheckout'); - if (!$this->customerSession->isLoggedIn()) { - $this->logger->addDebug('not isLoggedIn'); - if ($this->order->getCustomerId() > 0) { - $this->logger->addDebug('getCustomerId > 0'); - try { - $customer = $this->customerRepository->getById($this->order->getCustomerId()); - $this->customerSession->setCustomerDataAsLoggedIn($customer); - - if (!$this->checkoutSession->getLastRealOrderId() && $this->order->getIncrementId()) { - $this->checkoutSession->setLastRealOrderId($this->order->getIncrementId()); - $this->logger->addDebug(__METHOD__ . '|setLastRealOrderId|'); - $this->checkoutSession->restoreQuote(); - $this->logger->addDebug(__METHOD__ . '|restoreQuote|'); - } - } catch (\Exception $e) { - $this->logger->addError('Could not load customer'); - } - } - } - $this->logger->addDebug('ready for redirect'); + $this->logger->addDebug(sprintf( + '[REDIRECT - %s] | [Controller] | [%s:%s] - Redirect To Checkout', + $this->payment->getMethod(), + __METHOD__, __LINE__)); + + $this->setCustomerAndRestoreQuote('success'); + return $this->handleProcessedResponse('checkout', ['_query' => ['bk_e' => 1]]); } } diff --git a/Helper/Data.php b/Helper/Data.php index 644fb443c..abad08ecf 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -400,7 +400,11 @@ public function getStore(): ?StoreInterface try { return $this->storeManager->getStore(); } catch (\Exception $e) { - $this->logger->addDebug(__METHOD__ . $e); + $this->logger->addError(sprintf( + '[Helper] | [Helper] | [%s:%s] - %s', + __METHOD__, __LINE__, + $e->getMessage() + )); return null; } } diff --git a/Model/GuestPaymentInformationManagement.php b/Model/GuestPaymentInformationManagement.php index 40ee52730..393c71edb 100644 --- a/Model/GuestPaymentInformationManagement.php +++ b/Model/GuestPaymentInformationManagement.php @@ -148,10 +148,12 @@ public function buckarooSavePaymentInformationAndPlaceOrder( $orderId = $this->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMethod, $billingAddress); - $this->logger->debug('-[RESULT]----------------------------------------'); //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $this->logger->debug(print_r($this->registry->registry('buckaroo_response'), true)); - $this->logger->debug('-------------------------------------------------'); + $this->logger->debug(sprintf( + '[PLACE_ORDER] | [Webapi] | [%s:%s] - Guest Users | buckarooResponse: %s', + __METHOD__, __LINE__, + print_r($this->registry->registry('buckaroo_response'), true) + )); if ($this->registry && $this->registry->registry('buckaroo_response')) { return \json_encode($this->registry->registry('buckaroo_response')[0]); diff --git a/Model/PaymentInformationManagement.php b/Model/PaymentInformationManagement.php index 5ec86c863..7d8bdfa31 100644 --- a/Model/PaymentInformationManagement.php +++ b/Model/PaymentInformationManagement.php @@ -125,10 +125,12 @@ public function buckarooSavePaymentInformationAndPlaceOrder( $orderId = $this->savePaymentInformationAndPlaceOrder($cartId, $paymentMethod, $billingAddress); - $this->logger->debug('-[RESULT]----------------------------------------'); //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $this->logger->debug(print_r($this->registry->registry('buckaroo_response'), true)); - $this->logger->debug('-------------------------------------------------'); + $this->logger->addDebug(sprintf( + '[PLACE_ORDER] | [Webapi] | [%s:%s] - Logged In Users | buckarooResponse: %s', + __METHOD__, __LINE__, + print_r($this->registry->registry('buckaroo_response'), true) + )); if ($this->registry && $this->registry->registry('buckaroo_response')) { return \json_encode($this->registry->registry('buckaroo_response')[0]); diff --git a/Model/Push.php b/Model/Push.php index e4a74e9e4..29d793a8b 100644 --- a/Model/Push.php +++ b/Model/Push.php @@ -101,7 +101,7 @@ public function receivePush(): bool $validSignature = $this->pushRequst->validate($store); if (!$validSignature) { - $this->logger->addDebug('Invalid push signature'); + $this->logger->addDebug('[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Invalid push signature'); throw new BuckarooException(__('Signature from push is incorrect')); } diff --git a/Plugin/MyParcelNLBuckarooPlugin.php b/Plugin/MyParcelNLBuckarooPlugin.php index 958cc885d..27b852f9c 100644 --- a/Plugin/MyParcelNLBuckarooPlugin.php +++ b/Plugin/MyParcelNLBuckarooPlugin.php @@ -73,11 +73,14 @@ public function __construct( */ public function beforeGetFromDeliveryOptions() { - $this->logger->addDebug(__METHOD__ . '|1|'); // @codingStandardsIgnoreLine if ($result = file_get_contents('php://input')) { if ($jsonDecoded = $this->json->unserialize($result)) { - $this->logger->addDebug(__METHOD__ . '|2|' . var_export($jsonDecoded, true)); + $this->logger->addDebug(sprintf( + '[MyParcelNL] | [Plugin] | [%s:%s] - Set Pickup Location | deliveryOptions: %s', + __METHOD__, __LINE__, + var_export($jsonDecoded, true) + )); if (!empty($jsonDecoded['deliveryOptions']) && !empty($jsonDecoded['deliveryOptions'][0]['deliveryType']) && ($jsonDecoded['deliveryOptions'][0]['deliveryType'] == 'pickup') && @@ -86,7 +89,6 @@ public function beforeGetFromDeliveryOptions() $this->checkoutSession->setMyParcelNLBuckarooData( $this->json->serialize($jsonDecoded['deliveryOptions'][0]['pickupLocation']) ); - $this->logger->addDebug(__METHOD__ . '|3|'); } } } From 0d4fa885dbdaaca9c748a17ff56c174a7a09e4b9 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Wed, 23 Aug 2023 11:10:03 +0300 Subject: [PATCH 3/6] BP-2433 - Add Logging more descriptive --- Gateway/Http/Client/Json.php | 28 ++-- Helper/Data.php | 24 ++-- Helper/PaymentGroupTransaction.php | 7 +- Model/Giftcard/Response/Giftcard.php | 5 +- Model/PaypalExpress/OrderCreate.php | 12 +- Model/PaypalExpress/QuoteCreate.php | 6 +- Model/Push/AfterpayProcessor.php | 1 - Model/Push/CancelAuthorizeProcessor.php | 12 +- Model/Push/KlarnaKpProcessor.php | 1 - Model/Push/PayPerEmailProcessor.php | 38 +++-- Model/Push/PaypalProcessor.php | 7 +- Model/Push/RefundProcessor.php | 5 +- Model/Refund/Push.php | 149 +++++++++++--------- Model/ResourceModel/Order/Handler/State.php | 17 ++- Model/Service/Order.php | 74 ++++++---- Observer/GroupTransactionRegister.php | 10 +- Observer/HandleFailedQuoteOrder.php | 31 ++-- Observer/OrderCancelAfter.php | 8 +- Service/Sales/Quote/Recreate.php | 10 +- 19 files changed, 269 insertions(+), 176 deletions(-) diff --git a/Gateway/Http/Client/Json.php b/Gateway/Http/Client/Json.php index 0166bdc1f..d8817542b 100644 --- a/Gateway/Http/Client/Json.php +++ b/Gateway/Http/Client/Json.php @@ -69,7 +69,11 @@ public function doRequest(array $data, $mode) { $urls = $this->getUrls($mode); - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($data, true)); + $this->logger->addDebug(sprintf( + '[HTTP_JSON] | [Gateway] | [%s:%s] - Create post request to payment engine | request: %s', + __METHOD__, __LINE__, + var_export($data, true) + )); $options = $this->getOptions($urls['uri'], $urls['uri2'], $data, 'POST'); $this->client->setOptions($options); @@ -108,7 +112,11 @@ public function doStatusRequest($transactionId, $mode) $options = $this->getOptions($urls['uri'], $urls['uri2'], [], 'GET'); $this->client->setOptions($options); - $this->logger->addDebug(__METHOD__ . '|10|' . var_export($options, true)); + $this->logger->addDebug(sprintf( + '[HTTP_JSON] | [Gateway] | [%s:%s] - Create a status request by transaction_id | request: %s', + __METHOD__, __LINE__, + var_export($options, true) + )); return $this->getResponse($urls['uri']); } @@ -224,16 +232,18 @@ public function getResponse(string $uri, array $data = []) $response = json_decode($this->client->getBody(), true); } catch (\Exception $e) { - $this->logger->addDebug(__METHOD__ . '|10|' . var_export($e->getMessage(), true)); + $this->logger->addError(sprintf( + '[HTTP_JSON] | [Gateway] | [%s:%s] - Get Response after JSON request | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); return false; } - $this->logger->addDebug(__METHOD__ . '|15|' . var_export( - [ - $response, - $this->client->getStatus(), - ], - true + $this->logger->addDebug(sprintf( + '[HTTP_JSON] | [Gateway] | [%s:%s] - Get Response after JSON request | response: %s', + __METHOD__, __LINE__, + var_export(['response' => $response, 'clientStatus' => $this->client->getStatus()], true) )); return $response; diff --git a/Helper/Data.php b/Helper/Data.php index abad08ecf..69e4b3ab2 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -400,11 +400,9 @@ public function getStore(): ?StoreInterface try { return $this->storeManager->getStore(); } catch (\Exception $e) { - $this->logger->addError(sprintf( - '[Helper] | [Helper] | [%s:%s] - %s', - __METHOD__, __LINE__, - $e->getMessage() - )); + $this->logger->addError( + '[Helper] | [Helper] | [' . __METHOD__ . ':' . __LINE__ . '] - Get Store | [ERROR]: ' . $e->getMessage() + ); return null; } } @@ -450,13 +448,15 @@ public function getConfigGiftCardsSort() //phpcs:ignore:Generic.Metrics.NestingLevel public function getPPeCustomerDetails(): ?array { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($this->_getRequest()->getParams(), true)); + $this->logger->addDebug(sprintf( + '[Helper - PayPerEmail] | [Helper] | [%s:%s] - Get PPE Customer details | originalRequest: %s', + __METHOD__, __LINE__, + var_export($this->_getRequest()->getParams(), true) + )); if (($customerId = $this->_getRequest()->getParam('customer_id')) && ((int)$customerId > 0)) { - $this->logger->addDebug(__METHOD__ . '|5|'); if (!isset($this->staticCache['getPPeCustomerDetails']) && ($customer = $this->customerRepository->getById((int)$customerId)) ) { - $this->logger->addDebug(__METHOD__ . '|15|'); $billingAddress = null; if ($addresses = $customer->getAddresses()) { foreach ($addresses as $address) { @@ -466,7 +466,11 @@ public function getPPeCustomerDetails(): ?array } } } - $this->logger->addDebug(var_export([$customer->getEmail()], true)); + $this->logger->addDebug(sprintf( + '[Helper - PayPerEmail] | [Helper] | [%s:%s] - Get PPE Customer details | customerEmail: %s', + __METHOD__, __LINE__, + $customer->getEmail() + )); $this->staticCache['getPPeCustomerDetails'] = [ 'email' => $customer->getEmail(), 'firstName' => $billingAddress ? $billingAddress->getFirstName() : '', @@ -478,7 +482,6 @@ public function getPPeCustomerDetails(): ?array if ($order = $this->_getRequest()->getParam('order')) { if (isset($order['billing_address'])) { - $this->logger->addDebug(__METHOD__ . '|30|'); $this->staticCache['getPPeCustomerDetails'] = [ 'email' => !empty($this->staticCache['getPPeCustomerDetails']['email']) ? $this->staticCache['getPPeCustomerDetails']['email'] : '', @@ -492,7 +495,6 @@ public function getPPeCustomerDetails(): ?array if (($payment = $this->_getRequest()->getParam('payment')) && ($payment['method'] == 'buckaroo_magento2_payperemail') ) { - $this->logger->addDebug(__METHOD__ . '|40|'); $this->staticCache['getPPeCustomerDetails'] = [ 'email' => $payment['customer_email'], 'firstName' => $payment['customer_billingFirstName'], diff --git a/Helper/PaymentGroupTransaction.php b/Helper/PaymentGroupTransaction.php index f3158ebba..ca744f9b3 100644 --- a/Helper/PaymentGroupTransaction.php +++ b/Helper/PaymentGroupTransaction.php @@ -90,7 +90,12 @@ public function __construct( */ public function saveGroupTransaction($response) { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($response, true)); + $this->logger->addDebug(sprintf( + '[GROUP_TRANSACTION] | [Helper] | [%s:%s] - Save group transaction in database | response: %s', + __METHOD__, __LINE__, + var_export($response, true) + )); + $groupTransaction = $this->groupTransactionFactory->create(); $data['order_id'] = $response['Invoice']; $data['transaction_id'] = $response['Key']; diff --git a/Model/Giftcard/Response/Giftcard.php b/Model/Giftcard/Response/Giftcard.php index cdacf527a..f9f67fc87 100644 --- a/Model/Giftcard/Response/Giftcard.php +++ b/Model/Giftcard/Response/Giftcard.php @@ -233,7 +233,10 @@ public function rollbackAllPartialPayments($order) $this->giftcardRemoveService->remove($transaction->getTransactionId(), $order->getIncrementId()); } } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . (string)$th); + $this->logger->addDebug(sprintf( + '[GIFTCARD] | [Model] | [%s:%s] - Rollback all Partial Payment | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage())); } } diff --git a/Model/PaypalExpress/OrderCreate.php b/Model/PaypalExpress/OrderCreate.php index c0a469f0d..b29f5314a 100644 --- a/Model/PaypalExpress/OrderCreate.php +++ b/Model/PaypalExpress/OrderCreate.php @@ -128,10 +128,18 @@ public function execute( try { $orderId = $this->createOrder($paypalOrderId, $cartId); } catch (NoSuchEntityException $th) { - $this->logger->addDebug(__METHOD__ . $th->getMessage()); + $this->logger->addError(sprintf( + '[CREATE_ORDER - PayPal Express] | [Model] | [%s:%s] - Create Order - No such entity | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); throw new PaypalExpressException(__("Failed to create order"), 1, $th); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . $th->getMessage()); + $this->logger->addError(sprintf( + '[CREATE_ORDER - PayPal Express] | [Model] | [%s:%s] - Create Order | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); throw $th; } diff --git a/Model/PaypalExpress/QuoteCreate.php b/Model/PaypalExpress/QuoteCreate.php index 97d4238dd..dabad6de2 100644 --- a/Model/PaypalExpress/QuoteCreate.php +++ b/Model/PaypalExpress/QuoteCreate.php @@ -83,7 +83,11 @@ public function execute( $this->quoteService->addFirstShippingMethod(); $this->quoteService->setPaymentMethod(Paypal::CODE); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . $th->getMessage()); + $this->logger->addError(sprintf( + '[CREATE_QUOTE - PayPal Express] | [Model] | [%s:%s] - Create Quote | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); throw new PaypalExpressException(__("Failed to add address quote"), 1, $th); } diff --git a/Model/Push/AfterpayProcessor.php b/Model/Push/AfterpayProcessor.php index 6c05a8972..1de3157a4 100644 --- a/Model/Push/AfterpayProcessor.php +++ b/Model/Push/AfterpayProcessor.php @@ -81,7 +81,6 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool $this->pushRequest->hasAdditionalInformation('service_action_from_magento', 'capture') && $this->afterpayConfig->isInvoiceCreatedAfterShipment() )) { - $this->logger->addDebug(__METHOD__ . '|5_1|'); $this->dontSaveOrderUponSuccessPush = true; return false; } diff --git a/Model/Push/CancelAuthorizeProcessor.php b/Model/Push/CancelAuthorizeProcessor.php index 64c024e00..1849c5652 100644 --- a/Model/Push/CancelAuthorizeProcessor.php +++ b/Model/Push/CancelAuthorizeProcessor.php @@ -17,10 +17,18 @@ public function processPush(PushRequestInterface $pushRequest): bool try { $this->setTransactionKey(); } catch (\Exception $e) { - $this->logger->addDebug($e->getLogMessage()); + $this->logger->addError(sprintf( + '[PUSH_CANCEL_AUTHORIZE] | [Webapi] | [%s:%s] - cancelled order authorization | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getLogMessage() + )); } - $this->logger->addDebug('Order autorize has been canceld, trying to update payment transactions'); + $this->logger->addDebug(sprintf( + '[PUSH_CANCEL_AUTHORIZE] | [Webapi] | [%s:%s] - Order autorize has been canceld,' . + ' trying to update payment transactions', + __METHOD__, __LINE__, + )); return true; } diff --git a/Model/Push/KlarnaKpProcessor.php b/Model/Push/KlarnaKpProcessor.php index 00091b3d8..14c6a7e9d 100644 --- a/Model/Push/KlarnaKpProcessor.php +++ b/Model/Push/KlarnaKpProcessor.php @@ -129,7 +129,6 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool empty($this->pushRequest->getServiceKlarnakpReservationnumber()) && $this->klarnakpConfig->isInvoiceCreatedAfterShipment() )) { - $this->logger->addDebug(__METHOD__ . '|5_1|'); $this->dontSaveOrderUponSuccessPush = true; return false; } diff --git a/Model/Push/PayPerEmailProcessor.php b/Model/Push/PayPerEmailProcessor.php index 6ad13307b..fb50d42cc 100644 --- a/Model/Push/PayPerEmailProcessor.php +++ b/Model/Push/PayPerEmailProcessor.php @@ -129,14 +129,20 @@ public function processPush(PushRequestInterface $pushRequest): bool // Check if the order can be updated if (!$this->canUpdateOrderStatus()) { if ($isDifferentPaymentMethod && $this->configPayPerEmail->isEnabledB2B()) { - $this->logger->addDebug(__METHOD__ . '|$this->order->getState()|' . $this->order->getState()); + $this->logger->addDebug(sprintf( + '[PUSH - PayPerEmail] | [Webapi] | [%s:%s] - Update Order State | currentState: %s', + __METHOD__, __LINE__, + $this->order->getState() + )); if ($this->order->getState() === Order::STATE_COMPLETE) { $this->order->setState(Order::STATE_PROCESSING); $this->order->save(); } return true; } - $this->logger->addDebug('Order can not receive updates'); + $this->logger->addDebug( + '[PUSH - PayPerEmail] | [Webapi] | ['.__METHOD__.':'.__LINE__.'] - Order can not receive updates' + ); $this->orderRequestService->setOrderNotificationNote(__('The order has already been processed.')); throw new BuckarooException( __('Signature from push is correct but the order can not receive updates') @@ -153,7 +159,6 @@ public function processPush(PushRequestInterface $pushRequest): bool return true; } - if (!$this->canProcessPostData()) { return true; } @@ -164,9 +169,7 @@ public function processPush(PushRequestInterface $pushRequest): bool $this->processPushByStatus(); - $this->logger->addDebug(__METHOD__ . '|5|'); if (!$this->dontSaveOrderUponSuccessPush) { - $this->logger->addDebug(__METHOD__ . '|5-1|'); $this->order->save(); } @@ -316,7 +319,10 @@ public function isPayPerEmailB2BModePush(): bool && !empty($this->pushRequest->getTransactionMethod()) && ($this->pushRequest->getTransactionMethod() == 'payperemail') && $this->configPayPerEmail->isEnabledB2B()) { - $this->logger->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(sprintf( + '[PUSH - PayPerEmail] | [Webapi] | [%s:%s] - The transaction is PayPerEmail B2B', + __METHOD__, __LINE__ + )); $this->isPayPerEmailB2BModePushInitial = true; } } else { @@ -345,16 +351,21 @@ public function isPayPerEmailB2BModePushInitial(): bool protected function getNewStatus() { $newStatus = $this->orderStatusFactory->get($this->pushRequest->getStatusCode(), $this->order); - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); + + $this->logger->addDebug(sprintf( + '[PUSH - PayPerEmail] | [Webapi] | [%s:%s] - Get New Status | newStatus: %s', + __METHOD__, __LINE__, + var_export($newStatus, true) + )); if ($this->isPayPerEmailB2BModePushInitial()) { $this->pushTransactionType->setStatusKey('BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS'); $newStatus = $this->configAccount->getOrderStatusSuccess(); - $this->logger->addDebug(__METHOD__ . '|15|' . var_export( - [$this->pushTransactionType->getStatusKey(), $newStatus], - true - ) - ); + $this->logger->addDebug(sprintf( + '[PUSH - PayPerEmail] | [Webapi] | [%s:%s] - Get New Status | newStatus: %s', + __METHOD__, __LINE__, + var_export([$this->pushTransactionType->getStatusKey(), $newStatus], true) + )); } return $newStatus; @@ -380,8 +391,6 @@ protected function getPaymentDetails($message) $amount = $this->order->getBaseTotalDue(); $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; - - $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) @@ -408,7 +417,6 @@ protected function getPaymentDetails($message) protected function invoiceShouldBeSaved(array &$paymentDetails): bool { if (!$this->isPayPerEmailB2BModePushInitial && $this->isPayPerEmailB2BModePush()) { - $this->logger->addDebug(__METHOD__ . '|4_1|'); //Fix for suspected fraud when the order currency does not match with the payment's currency $amount = $this->payment->isSameCurrency() && $this->payment->isCaptureFinal($this->order->getGrandTotal()) ? $this->order->getGrandTotal() diff --git a/Model/Push/PaypalProcessor.php b/Model/Push/PaypalProcessor.php index be51231bd..a58435853 100644 --- a/Model/Push/PaypalProcessor.php +++ b/Model/Push/PaypalProcessor.php @@ -77,7 +77,6 @@ public function __construct( protected function getNewStatus() { $newStatus = $this->orderStatusFactory->get($this->pushRequest->getStatusCode(), $this->order); - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($newStatus, true)); if ($this->pushTransactionType->getStatusKey() == 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS' && $this->order->getPayment()->getMethod() == PaypalConfig::CODE) { @@ -87,6 +86,12 @@ protected function getNewStatus() } } + $this->logger->addDebug(sprintf( + '[PUSH - PayPerEmail] | [Webapi] | [%s:%s] - Get New Status | newStatus: %s', + __METHOD__, __LINE__, + var_export($newStatus, true) + )); + return $newStatus; } } \ No newline at end of file diff --git a/Model/Push/RefundProcessor.php b/Model/Push/RefundProcessor.php index 31c6ef53a..259a3a89a 100644 --- a/Model/Push/RefundProcessor.php +++ b/Model/Push/RefundProcessor.php @@ -90,8 +90,7 @@ public function processPush(PushRequestInterface $pushRequest): bool if ($this->pushTransactionType->getStatusKey() !== 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS') { if ($this->order->hasInvoices()) { - //don't proceed failed refund push - $this->logger->addDebug(__METHOD__ . '|10|'); + //don't proceed failed refund push if order has invoices $this->orderRequestService->setOrderNotificationNote( __('Push notification for refund has no success status, ignoring.') ); @@ -119,7 +118,6 @@ private function skipPendingRefundPush(PushRequestInterface $pushRequest): bool if (!$pushRequest->hasAdditionalInformation('initiated_by_magento', 1) || !$pushRequest->hasAdditionalInformation('service_action_from_magento', ['refund']) ) { - $this->logger->addDebug(__METHOD__ . '|5|'); return false; } @@ -129,7 +127,6 @@ private function skipPendingRefundPush(PushRequestInterface $pushRequest): bool BuckarooStatusCode::PENDING_APPROVAL, $pushRequest->getRelatedtransactionRefund() )) { - $this->logger->addDebug(__METHOD__ . '|4|'); return false; } diff --git a/Model/Refund/Push.php b/Model/Refund/Push.php index 0613a659b..55ee36ec4 100644 --- a/Model/Refund/Push.php +++ b/Model/Refund/Push.php @@ -133,35 +133,32 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur $this->postData = $postData; $this->order = $order; - $this->logger->addDebug( - __METHOD__ . '|1|Trying to refund order ' . $this->order->getId() . ' out of paymentplaza. ' - ); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Trying to refund order out of paymentplaza | orderId: %s', + __METHOD__, __LINE__, + $this->order->getId() + )); if (!$this->configRefund->getAllowPush()) { - $this->logger->addDebug( - __METHOD__ . '|5|But failed, the configuration is set not to accept refunds out of Payment Plaza' - ); - //phpcs:ignore:Magento2.Exceptions.DirectThrow - throw new BuckarooException( - __('Buckaroo refund is disabled') - ); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Refund order failed - ' . + 'the configuration is set not to accept refunds out of Payment Plaza | orderId: %s', + __METHOD__, __LINE__, + $this->order->getId() + )); + throw new BuckarooException(__('Buckaroo refund is disabled')); } if (!$signatureValidation && !$this->order->canCreditmemo()) { - $debugMessage = 'Validation incorrect: ' . PHP_EOL; - //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $debugMessage .= print_r( - [ + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Refund order failed - validation incorrect | signature: %s', + __METHOD__, __LINE__, + var_export([ 'signature' => $signatureValidation, 'canOrderCredit' => $this->order->canCreditmemo() - ], - true - ); - $this->logger->addDebug($debugMessage); - //phpcs:ignore:Magento2.Exceptions.DirectThrow - throw new Exception( - __('Buckaroo refund push validation failed') - ); + ], true) + )); + throw new BuckarooException(__('Buckaroo refund push validation failed')); } $creditmemoCollection = $this->order->getCreditmemosCollection(); @@ -170,13 +167,20 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur $this->postData->getTransactions() ); if (count($creditmemosByTransactionId) > 0) { - $this->logger->addDebug(__METHOD__ . '|15|The transaction has already been refunded.'); - + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - The transaction has already been refunded', + __METHOD__, __LINE__ + )); return false; } $creditmemo = $this->createCreditmemo(); - $this->logger->addDebug(__METHOD__ . '|20|Order successful refunded = ' . $creditmemo); + + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Order successful refunded | creditmemo: %s', + __METHOD__, __LINE__, + $creditmemo ? 'success' : 'false' + )); return $creditmemo; } @@ -189,7 +193,6 @@ public function receiveRefundPush(PushRequestInterface $postData, bool $signatur */ public function createCreditmemo(): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); $creditData = $this->getCreditmemoData(); $creditmemo = $this->initCreditmemo($creditData); @@ -201,43 +204,46 @@ public function createCreditmemo(): bool && !empty($this->postData->getTransactionType()) && ($this->postData->getTransactionType() == 'C041') ) { - $this->logger->addDebug(__METHOD__ . '|5|'); $creditmemo->setBaseGrandTotal($this->totalAmountToRefund()); $creditmemo->setGrandTotal($this->totalAmountToRefund()); } if (!$creditmemo->isValidGrandTotal()) { - $this->logger->addDebug(__METHOD__ . '|10|The credit memo\'s total must be positive.'); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - The credit memo\'s total must be positive', + __METHOD__, __LINE__ + )); throw new LocalizedException( __('The credit memo\'s total must be positive.') ); } $creditmemo->setTransactionId($this->postData->getTransactions()); - $this->logger->addDebug(__METHOD__ . '|20'); $this->creditmemoManagement->refund( $creditmemo, (bool)$creditData['do_offline'], !empty($creditData['order_email']) ); - $this->logger->addDebug(__METHOD__ . '|25'); $this->creditEmailSender->send($creditmemo); return true; } else { - $debugMessage = 'Failed to create the creditmemo, method saveCreditmemo return value: ' . PHP_EOL; - //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $debugMessage .= print_r($creditmemo, true); - $this->logger->addDebug(__METHOD__ . '|30|' . $debugMessage); - //phpcs:ignore:Magento2.Exceptions.DirectThrow + $this->logger->addError(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Failed to create the creditmemo' . + 'method saveCreditmemo return value: %s', + __METHOD__, __LINE__, + print_r($creditmemo, true) + )); + throw new BuckarooException( __('Failed to create the creditmemo') ); } } catch (LocalizedException $e) { - $this->logger->addDebug( - __METHOD__ . '|35|Buckaroo failed to create the credit memo\'s { ' . $e->getLogMessage() . ' }' - ); + $this->logger->addError(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Buckaroo failed to create the credit memo\'s | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getLogMessage() + )); } - $this->logger->addDebug(__METHOD__ . '|40'); return false; } @@ -257,23 +263,24 @@ public function getCreditmemoData(): array $totalAmountToRefund = $this->totalAmountToRefund(); $this->creditAmount = $totalAmountToRefund + $this->order->getBaseTotalRefunded(); - $this->logger->addDebug(__METHOD__ . '|1|' . var_export([ - $this->creditAmount, - $this->order->getBaseGrandTotal(), - ], true)); - if (!$this->helper->areEqualAmounts($this->creditAmount, $this->order->getBaseGrandTotal())) { $adjustment = $this->getAdjustmentRefundData(); - $this->logger->addDebug('This is an adjustment refund of ' . $totalAmountToRefund); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - This is an adjustment refund of %s', + __METHOD__, __LINE__, + $totalAmountToRefund + )); $data['shipping_amount'] = '0'; $data['adjustment_negative'] = '0'; $data['adjustment_positive'] = $adjustment; $data['items'] = $this->getCreditmemoDataItems(); $data['qtys'] = $this->setCreditQtys($data['items']); } else { - $this->logger->addDebug( - 'With this refund of ' . $this->creditAmount . ' the grand total will be refunded.' - ); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - With this refund of %s the grand total will be refunded', + __METHOD__, __LINE__, + $this->creditAmount + )); $data['shipping_amount'] = $this->caluclateShippingCostToRefund(); $data['adjustment_negative'] = $this->getTotalCreditAdjustments(); $data['adjustment_positive'] = $this->calculateRemainder(); @@ -281,10 +288,11 @@ public function getCreditmemoData(): array $data['qtys'] = $this->setCreditQtys($data['items']); } - $debugMessage = 'Data used for credit nota: ' . PHP_EOL; - //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $debugMessage .= print_r($data, true); - $this->logger->addDebug($debugMessage); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - The credit memo data | data: %s', + __METHOD__, __LINE__, + print_r($data, true) + )); return $data; } @@ -340,9 +348,6 @@ public function getCreditmemoDataItems(): array $qty = 0; foreach ($this->order->getAllItems() as $orderItem) { - /** - * @var \Magento\Sales\Model\Order\Item $orderItem - */ if (!array_key_exists($orderItem->getId(), $items)) { if ($this->helper->areEqualAmounts($this->creditAmount, $this->order->getBaseGrandTotal())) { $qty = $orderItem->getQtyInvoiced() - $orderItem->getQtyRefunded(); @@ -352,10 +357,11 @@ public function getCreditmemoDataItems(): array } } - $debugMessage = 'Total items to be refunded: ' . PHP_EOL; - //phpcs:ignore:Magento2.Functions.DiscouragedFunction - $debugMessage .= print_r($items, true); - $this->logger->addDebug($debugMessage); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Total items to be refunded: %s', + __METHOD__, __LINE__, + print_r($items, true) + )); return $items; } @@ -392,11 +398,9 @@ public function caluclateShippingCostToRefund(): float ); if ($includesTax) { - $this->logger->addDebug(__METHOD__ . '|1|'); return ($this->order->getBaseShippingAmount() + $this->order->getBaseShippingTaxAmount()) - ($this->order->getBaseShippingRefunded() + $this->order->getBaseShippingTaxRefunded()); } else { - $this->logger->addDebug(__METHOD__ . '|2|'); return $this->order->getBaseShippingAmount() - $this->order->getBaseShippingRefunded(); } @@ -439,19 +443,21 @@ public function calculateRemainder() - $baseTotalToBeRefunded - $this->order->getBaseTotalRefunded(); - $this->logger->addDebug(__METHOD__ . '|5|' . var_export([ - $this->totalAmountToRefund(), - $this->order->getBaseGrandTotal(), - $remainderToRefund - ], true)); + $this->logger->addDebug(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Calculate the remainder | totals: %s', + __METHOD__, __LINE__, + var_export([ + 'totalAmountToRefund' => $this->totalAmountToRefund(), + 'orderBaseGrandTotal' => $this->order->getBaseGrandTotal(), + 'remainderToRefund' => $remainderToRefund + ], true) + )); if ($this->totalAmountToRefund() == $this->order->getBaseGrandTotal()) { - $this->logger->addDebug(__METHOD__ . '|10|'); $remainderToRefund = 0; } if ($remainderToRefund < 0.01) { - $this->logger->addDebug(__METHOD__ . '|15|'); $remainderToRefund = 0; } @@ -479,8 +485,11 @@ public function initCreditmemo(array $creditData) return $creditmemo; } catch (LocalizedException $e) { - $this->logger - ->addDebug('Buckaroo can not initialize the credit memo\'s by order { ' . $e->getLogMessage() . ' }'); + $this->logger->addError(sprintf( + '[PUSH_REFUND] | [Webapi] | [%s:%s] - Buckaroo can not initialize the credit memo\'s by order: %s', + __METHOD__, __LINE__, + $e->getLogMessage() + )); } return false; } diff --git a/Model/ResourceModel/Order/Handler/State.php b/Model/ResourceModel/Order/Handler/State.php index 7bc02f0fb..51ef841ce 100644 --- a/Model/ResourceModel/Order/Handler/State.php +++ b/Model/ResourceModel/Order/Handler/State.php @@ -24,6 +24,7 @@ use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory; use Buckaroo\Magento2\Model\ConfigProvider\Method\PayPerEmail; +use Magento\Framework\Exception\LocalizedException; use Magento\Sales\Model\Order; class State extends \Magento\Sales\Model\ResourceModel\Order\Handler\State @@ -52,10 +53,18 @@ public function __construct( $this->logger = $logger; } + /** + * Check order status and adjust the status before save + * + * @param Order $order + * @return $this + * + * @throws LocalizedException + */ public function check(Order $order): State { if ($order->getPayment() && - $order->getPayment()->getMethodInstance()->getCode() == 'buckaroo_magento2_payperemail' + $order->getPayment()->getMethod() == 'buckaroo_magento2_payperemail' ) { $config = $this->configProviderMethodFactory->get(PayPerEmail::CODE); if ($config->isEnabledB2B() @@ -63,7 +72,11 @@ public function check(Order $order): State && $order->getInvoiceCollection() && $order->getInvoiceCollection()->getFirstItem() && $order->getInvoiceCollection()->getFirstItem()->getState() == 1 ) { - $this->logger->addDebug(__METHOD__ . '|10|'); + $this->logger->addDebug(sprintf( + '[ORDER_STATUS] | [Handler] | [%s:%s] - Skip update order status for PayPerEmail | order: %s', + __METHOD__, __LINE__, + $order->getId() + )); return $this; } } diff --git a/Model/Service/Order.php b/Model/Service/Order.php index 20dc76b14..855d6da80 100644 --- a/Model/Service/Order.php +++ b/Model/Service/Order.php @@ -142,12 +142,10 @@ public function cancelExpiredTransferOrders() */ protected function cancelExpiredTransferOrdersPerStore(StoreInterface $store) { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); $statesConfig = $this->configProviderFactory->get('states'); $state = $statesConfig->getOrderStateNew($store); if ($transferConfig = $this->configProviderMethodFactory->get('transfer')) { if ($dueDays = abs($transferConfig->getDueDate())) { - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); $orderCollection = $this->orderFactory->create()->addFieldToSelect(['*']); $orderCollection ->addFieldToFilter( @@ -175,7 +173,15 @@ protected function cancelExpiredTransferOrdersPerStore(StoreInterface $store) ) ->where('p.method = ?', Transfer::CODE); - $this->logger->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER - Transfer] | [Service] | [%s:%s] - Cancel Expired Transfer Orders Per Store |' + . 'storeId:%s | dueDays: %s | orderCollectionCount: %s', + __METHOD__, __LINE__, + var_export($store->getId(), true), + var_export($dueDays, true), + var_export($orderCollection->count(), true) + )); + if ($orderCollection->count()) { foreach ($orderCollection as $order) { @@ -214,13 +220,11 @@ public function cancelExpiredPPEOrders(): Order */ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($store->getId(), true)); $statesConfig = $this->configProviderFactory->get('states'); $state = $statesConfig->getOrderStateNew($store); if ($ppeConfig = $this->configProviderMethodFactory->get('payperemail')) { if ($ppeConfig->getEnabledCronCancelPPE()) { if ($dueDays = abs($ppeConfig->getExpireDays())) { - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($dueDays, true)); $orderCollection = $this->orderFactory->create()->addFieldToSelect(['*']); $orderCollection ->addFieldToFilter( @@ -249,11 +253,14 @@ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) ->where('p.additional_information like "%isPayPerEmail%"' . ' OR p.method ="buckaroo_magento2_payperemail"'); - $this->logger->addDebug( - __METHOD__ . '|PPEOrders query|' . $orderCollection->getSelect()->__toString() - ); - - $this->logger->addDebug(__METHOD__ . '|10|' . var_export($orderCollection->count(), true)); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER - PayPerEmail] | [Service] | [%s:%s] - Cancel Expired PayPerEmail Orders |' + . 'storeId:%s | dueDays: %s | orderCollectionCount: %s', + __METHOD__, __LINE__, + var_export($store->getId(), true), + var_export($dueDays, true), + var_export($orderCollection->count(), true) + )); if ($orderCollection->count()) { foreach ($orderCollection as $order) { @@ -276,47 +283,54 @@ protected function cancelExpiredPPEOrdersPerStore(StoreInterface $store) * @return bool * @throws LocalizedException */ - public function cancel($order, $statusCode) + public function cancel(\Magento\Sales\Model\Order $order, string $statusCode) { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($order->getIncrementId(), true)); + $paymentMethodCode = $order->getPayment()->getMethod(); + $paymentMethodName = str_replace('buckaroo_magento2_', '',$paymentMethodCode); + + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER - %s] | [Service] | [%s:%s] - Cancel Order | orderIncrementId: %s', + $paymentMethodName, + __METHOD__, __LINE__, + var_export($order->getIncrementId(), true) + )); - // Mostly the push api already canceled the order, so first check in wich state the order is. if ($order->getState() == \Magento\Sales\Model\Order::STATE_CANCELED) { - $this->logger->addDebug(__METHOD__ . '|5|'); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER - %s] | [Service] | [%s:%s] - Cancel Order - already canceled', + $paymentMethodName, + __METHOD__, __LINE__ + )); return true; } $store = $order->getStore(); - /** - * @noinspection PhpUndefinedMethodInspection - */ if (!$this->accountConfig->getCancelOnFailed($store)) { - $this->logger->addDebug(__METHOD__ . '|10|'); return true; } - $this->logger->addDebug(__METHOD__ . '|15|'); - - if ($order->canCancel() - || in_array($order->getPayment()->getMethodInstance()->buckarooPaymentMethodCode, ['payperemail']) - ) { - $this->logger->addDebug(__METHOD__ . '|20|'); - - if (in_array($order->getPayment()->getMethodInstance()->buckarooPaymentMethodCode, ['klarnakp'])) { - $methodInstanceClass = get_class($order->getPayment()->getMethodInstance()); + if ($order->canCancel() || $paymentMethodName == 'payperemail') + { + if ($paymentMethodName == 'klarnakp') { + $methodInstanceClass = get_class($order->getPayment()->getMethodInstance()); $methodInstanceClass::$requestOnVoid = false; } $order->cancel(); - $this->logger->addDebug(__METHOD__ . '|30|'); - $failedStatus = $this->orderStatusFactory->get( $statusCode, $order ); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER - %s] | [Service] | [%s:%s] - Cancel Order - set status to: %s', + $paymentMethodName, + __METHOD__, __LINE__, + $failedStatus + )); + if ($failedStatus) { $order->setStatus($failedStatus); } @@ -324,8 +338,6 @@ public function cancel($order, $statusCode) return true; } - $this->logger->addDebug(__METHOD__ . '|40|'); - return false; } } diff --git a/Observer/GroupTransactionRegister.php b/Observer/GroupTransactionRegister.php index 4c6dea0f7..da9c237db 100644 --- a/Observer/GroupTransactionRegister.php +++ b/Observer/GroupTransactionRegister.php @@ -85,8 +85,6 @@ public function __construct( */ public function execute(Observer $observer) { - $this->logger->addDebug(__METHOD__ . '|1|'); - /** @var Invoice $invoice */ $invoice = $observer->getEvent()->getInvoice(); $payment = $invoice->getOrder()->getPayment(); @@ -99,19 +97,21 @@ public function execute(Observer $observer) $items = $this->groupTransaction->getGroupTransactionItems($order->getIncrementId()); foreach ($items as $item) { - $this->logger->addDebug(__METHOD__ . '|5|' . var_export([$order->getTotalPaid(), $item['amount']], true)); + $this->logger->addDebug(sprintf( + '[GROUP_TRANSACTION] | [Observer] | [%s:%s] - Set Order Total Paid | orderTotalPaid: %s', + __METHOD__, __LINE__, + var_export([$order->getTotalPaid(), $item['amount']], true) + )); $totalPaid = $order->getTotalPaid() + $item['amount']; $baseTotalPaid = $order->getBaseTotalPaid() + $item['amount']; if (($totalPaid < $order->getGrandTotal()) || ($this->helper->areEqualAmounts($totalPaid, $order->getGrandTotal())) ) { - $this->logger->addDebug(__METHOD__ . '|10|'); $order->setTotalPaid($totalPaid); } if (($baseTotalPaid < $order->getBaseGrandTotal()) || ($this->helper->areEqualAmounts($baseTotalPaid, $order->getBaseGrandTotal())) ) { - $this->logger->addDebug(__METHOD__ . '|15|'); $order->setBaseTotalPaid($baseTotalPaid); } } diff --git a/Observer/HandleFailedQuoteOrder.php b/Observer/HandleFailedQuoteOrder.php index 1c9b32ed7..06ddda4be 100644 --- a/Observer/HandleFailedQuoteOrder.php +++ b/Observer/HandleFailedQuoteOrder.php @@ -71,6 +71,7 @@ public function __construct( } /** + * Observes the event for a failed quote-to-order submission * Handle cancel order by sales_model_service_quote_submit_failure event * * @param Observer $observer @@ -79,14 +80,8 @@ public function __construct( */ public function execute(Observer $observer) { - /** - * @noinspection PhpUndefinedMethodInspection - */ /* @var $order Order */ $order = $observer->getEvent()->getOrder(); - /** - * @noinspection PhpUndefinedMethodInspection - */ if ($order->canCancel()) { // BUCKM2-78: Never automatically cancelauthorize via push for afterpay @@ -96,28 +91,36 @@ public function execute(Observer $observer) if (in_array( $payment->getMethodInstance()->getCode(), ['buckaroo_magento2_afterpay', 'buckaroo_magento2_afterpay2', 'buckaroo_magento2_klarnakp'] - ) - ) { + )) { try { $order->addCommentToStatusHistory('Buckaroo: failed to authorize an order'); $payment->setAdditionalInformation('buckaroo_failed_authorize', 1); $payment->save(); - //phpcs:ignore: Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (\Exception $e) { - // empty block + $this->logger->addError(sprintf( + '[CANCEL_ORDER] | [Observer] | [%s:%s] - Error when adding order comment | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } } try { - $this->logger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER] | [Observer] | [%s:%s] - Cancel order for failed quote-to-order | order: %s', + __METHOD__, __LINE__, + $order->getId() + )); if ($this->moduleManager->isEnabled('Magento_Inventory')) { - $this->logger->addDebug(__METHOD__ . '|5|'); $this->buckarooSession->setData('flagHandleFailedQuote', 1); } $this->orderManagement->cancel($order->getId()); - //phpcs:ignore: Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (\Exception $e) { - // empty block + $this->logger->addError(sprintf( + '[CANCEL_ORDER] | [Observer] | [%s:%s] - Error when canceling order | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } $this->buckarooSession->setData('flagHandleFailedQuote', 0); } diff --git a/Observer/OrderCancelAfter.php b/Observer/OrderCancelAfter.php index 62f41fccb..00674ed59 100644 --- a/Observer/OrderCancelAfter.php +++ b/Observer/OrderCancelAfter.php @@ -113,7 +113,13 @@ public function execute(Observer $observer) if ($cancelPPE && in_array($payment->getMethodInstance()->getCode(), ['buckaroo_magento2_payperemail'])) { try { - $this->logger->addDebug(__METHOD__ . '|sendCancelResponse|'); + $this->logger->addDebug(sprintf( + '[CANCEL_ORDER] | [Observer] | [%s:%s] - Send Cancel Order Request after order cancel |' . + ' originalKey: %s | order: %s', + __METHOD__, __LINE__, + var_export([$originalKey], true), + $order->getId() + )); $this->sendCancelResponse($originalKey); //phpcs:ignore: Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (\Exception $e) { diff --git a/Service/Sales/Quote/Recreate.php b/Service/Sales/Quote/Recreate.php index 2d81bfb8c..a4b81160d 100644 --- a/Service/Sales/Quote/Recreate.php +++ b/Service/Sales/Quote/Recreate.php @@ -58,7 +58,6 @@ public function __construct( */ public function recreate(Quote $quote) { - // @codingStandardsIgnoreStart try { $quote->setIsActive(true); $quote->setTriggerRecollect(1); @@ -74,10 +73,13 @@ public function recreate(Quote $quote) $this->cart->save(); return $quote; } catch (NoSuchEntityException $e) { - //No such entity - $this->logger->addError($e->getMessage()); + $this->logger->addError(sprintf( + '[RECREATE_QUOTE] | [Service] | [%s:%s] - Reintialize the quote | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } - // @codingStandardsIgnoreEnd + return false; } } From e4c2a5aacfce3e66f0dae8f1697a666726ee2cf2 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Wed, 23 Aug 2023 18:03:20 +0300 Subject: [PATCH 4/6] BP-2433 - Add Logging more descriptive on Push --- Model/Push/DefaultProcessor.php | 135 ++++++++++++------- Model/Push/TransferProcessor.php | 27 ++-- Model/RequestPush/RequestPushFactory.php | 22 ++- Model/Service/QuoteAddressService.php | 28 ++-- Model/Service/QuoteService.php | 6 +- Model/Validator/Push.php | 6 +- Observer/OrderCancelAfter.php | 19 ++- Observer/SalesOrderShipmentAfter.php | 20 ++- Observer/SendInvoiceMail.php | 8 +- Observer/SendOrderConfirmation.php | 6 +- Plugin/CommandInterface.php | 90 +++++++++---- Plugin/Onepage/Success.php | 11 +- Service/Applepay/Add.php | 6 +- Service/Formatter/Address/PhoneFormatter.php | 14 +- Service/Push/OrderRequestService.php | 10 +- 15 files changed, 254 insertions(+), 154 deletions(-) diff --git a/Model/Push/DefaultProcessor.php b/Model/Push/DefaultProcessor.php index 041c6cfa2..1f32c719c 100644 --- a/Model/Push/DefaultProcessor.php +++ b/Model/Push/DefaultProcessor.php @@ -168,7 +168,10 @@ public function processPush(PushRequestInterface $pushRequest): bool // Check if the order can be updated if (!$this->canUpdateOrderStatus()) { - $this->logger->addDebug('Order can not receive updates'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Order can not receive updates' + ); + $this->orderRequestService->setOrderNotificationNote(__('The order has already been processed.')); throw new BuckarooException( __('Signature from push is correct but the order can not receive updates') @@ -195,9 +198,7 @@ public function processPush(PushRequestInterface $pushRequest): bool $this->processPushByStatus(); - $this->logger->addDebug(__METHOD__ . '|5|'); if (!$this->dontSaveOrderUponSuccessPush) { - $this->logger->addDebug(__METHOD__ . '|5-1|'); $this->order->save(); } @@ -264,8 +265,6 @@ protected function skipKlarnaCapture(): bool */ protected function skipSpecificTypesOfRequsts(): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); - $types = ['capture', 'cancelauthorize', 'cancelreservation']; if ($this->pushRequest->hasAdditionalInformation('initiated_by_magento', 1) && $this->pushRequest->hasAdditionalInformation('service_action_from_magento', $types) @@ -287,8 +286,9 @@ protected function skipSpecificTypesOfRequsts(): bool protected function skipFirstPush(): bool { $skipFirstPush = $this->payment->getAdditionalInformation('skip_push'); - $this->logger->addDebug(__METHOD__ . '|1_20|' . var_export($skipFirstPush, true)); - + $this->logger->addDebug( + '[PUSH] | [Webapi] | [' . __METHOD__ . ':' . __LINE__ . '] - Skip First Push: ' . $skipFirstPush, + ); if ($skipFirstPush > 0) { $this->payment->setAdditionalInformation('skip_push', (int)$skipFirstPush - 1); @@ -338,13 +338,19 @@ protected function receivePushCheckDuplicates(int $receivedStatusCode = null, st && ($this->pushTransactionType->getPushType() == PushTransactionType::BUCK_PUSH_TYPE_TRANSACTION) && (!in_array($this->payment->getMethod(), $ignoredPaymentMethods)) ) { - $this->logger->addDebug(__METHOD__ . '|5|'); - $receivedTrxStatuses = $this->payment->getAdditionalInformation( self::BUCKAROO_RECEIVED_TRANSACTIONS_STATUSES ); - $this->logger->addDebug(__METHOD__ . '|10|' . - var_export([$receivedTrxStatuses, $receivedStatusCode], true)); + + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Check for duplicate transaction pushes | order: %s', + __METHOD__, __LINE__, + var_export([ + 'receivedTrxStatuses' => $receivedTrxStatuses, + 'receivedStatusCode' => $receivedStatusCode + ], true) + )); + if ($receivedTrxStatuses && is_array($receivedTrxStatuses) && !empty($trxId) @@ -356,21 +362,23 @@ protected function receivePushCheckDuplicates(int $receivedStatusCode = null, st && ($this->order->getStatus() == $orderStatus) && ($receivedStatusCode == BuckarooStatusCode::SUCCESS) ) { - //allow duplicated pushes for 190 statuses in case if order stills to be new/pending - $this->logger->addDebug(__METHOD__ . '|13|'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | [' . __METHOD__ . ':' . __LINE__ . '] - allow duplicated pushes ' + . 'for 190 statuses in case if order stills to be new/pending', + ); return false; } - $this->logger->addDebug(__METHOD__ . '|15|'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | [' . __METHOD__ . ':' . __LINE__ . '] - Skip Push the request is duplicate ' + ); return true; } if ($save) { - $this->logger->addDebug(__METHOD__ . '|17|'); $this->setReceivedTransactionStatuses(); $this->payment->save(); } } - $this->logger->addDebug(__METHOD__ . '|20|'); return false; } @@ -418,7 +426,11 @@ protected function canUpdateOrderStatus(): bool * Get current state and status of order */ $currentStateAndStatus = [$this->order->getState(), $this->order->getStatus()]; - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($currentStateAndStatus, true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Checks if the order can be updated | currentStateAndStatus: %s', + __METHOD__, __LINE__, + var_export($currentStateAndStatus, true) + )); /** * If the types are not the same and the order can receive an invoice the order can be udpated by BPE. @@ -436,7 +448,10 @@ protected function canUpdateOrderStatus(): bool && ($this->pushTransactionType->getStatusKey() === 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS') && $this->pushRequest->getRelatedtransactionPartialpayment() == null ) { - $this->logger->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Resetting from CANCELED to STATE_NEW/PENDING', + __METHOD__, __LINE__ + )); $this->order->setState(Order::STATE_NEW); $this->order->setStatus('pending'); @@ -668,7 +683,12 @@ protected function getNewStatus() */ public function processSucceededPush(string $newStatus, string $message): bool { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Process the successful push response from Buckaroo | newStatus: %s', + __METHOD__, __LINE__, + var_export($newStatus, true) + )); + $this->setBuckarooReservationNumber(); @@ -691,8 +711,6 @@ public function processSucceededPush(string $newStatus, string $message): bool $paymentDetails['forceState'] = true; } - $this->logger->addDebug(__METHOD__ . '|8|'); - $this->processSucceededPushAuthorization(); $this->orderRequestService->updateOrderStatus( @@ -703,8 +721,6 @@ public function processSucceededPush(string $newStatus, string $message): bool $this->dontSaveOrderUponSuccessPush ); - $this->logger->addDebug(__METHOD__ . '|9|'); - return true; } @@ -712,6 +728,7 @@ public function processSucceededPush(string $newStatus, string $message): bool * Process succeeded push authorization. * * @return void + * @throws \Exception */ private function processSucceededPushAuthorization(): void { @@ -732,7 +749,11 @@ private function processSucceededPushAuthorization(): void ) && !empty($this->pushRequest->getStatusCode()) && ($this->pushRequest->getStatusCode() == 190) ) { - $this->logger->addDebug(__METHOD__ . '|88|' . var_export($this->payment->getMethod(), true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Process succeeded push authorization | paymentMethod: %s', + __METHOD__, __LINE__, + var_export($this->payment->getMethod(), true) + )); $this->order->setState(Order::STATE_PROCESSING); $this->order->save(); } @@ -765,8 +786,12 @@ protected function sendOrderEmail(): void || $paymentMethod->getConfigData('order_email', $store) ) ) { - $this->logger->addDebug(__METHOD__ . '|sendemail|' . - var_export($this->configAccount->getOrderConfirmationEmailSync($store), true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Send Order Email | orderConfirmationEmail: %s', + __METHOD__, __LINE__, + var_export($this->configAccount->getOrderConfirmationEmail($store), true) + )); + $this->orderRequestService->sendOrderEmail( $this->order, (bool)$this->configAccount->getOrderConfirmationEmailSync($store) @@ -805,16 +830,19 @@ protected function canPushInvoice(): bool */ protected function saveInvoice(): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug('[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Save Invoice'); + if (!$this->forceInvoice && (!$this->order->canInvoice() || $this->order->hasInvoices())) { - $this->logger->addDebug('Order can not be invoiced'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Order can not be invoiced' + ); + return false; } $this->addTransactionData(); - $this->logger->addDebug(__METHOD__ . '|15|'); //Fix for suspected fraud when the order currency does not match with the payment's currency $amount = ($this->payment->isSameCurrency() && $this->payment->isCaptureFinal($this->order->getGrandTotal())) ? @@ -828,26 +856,26 @@ protected function saveInvoice(): bool return true; } - $this->logger->addDebug(__METHOD__ . '|25|'); - /** @var Invoice $invoice */ foreach ($this->order->getInvoiceCollection() as $invoice) { $invoice->setTransactionId($transactionKey)->save(); if (!empty($this->pushRequest->getInvoiceNumber()) && $this->groupTransaction->isGroupTransaction($this->pushRequest->getInvoiceNumber())) { - $this->logger->addDebug(__METHOD__ . '|27|'); - $invoice->setState(2); + $this->logger->addDebug( + '[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Set invoice state PAID group transaction' + ); + $invoice->setState(Invoice::STATE_PAID); } if (!$invoice->getEmailSent() && $this->configAccount->getInvoiceEmail($this->order->getStore())) { - $this->logger->addDebug(__METHOD__ . '|30|sendinvoiceemail'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Send Invoice Email ' + ); $this->orderRequestService->sendInvoiceEmail($invoice, true); } } - $this->logger->addDebug(__METHOD__ . '|35|'); - $this->order->setIsInProcess(true); $this->order->save(); @@ -911,13 +939,18 @@ public function addTransactionData(bool $transactionKey = false, bool $data = fa */ public function processFailedPush(string $newStatus, string $message): bool { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($newStatus, true)); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Process the failed push response from Buckaroo | newStatus: %s', + __METHOD__, __LINE__, + var_export($newStatus, true) + )); if (($this->order->getState() === Order::STATE_PROCESSING) && ($this->order->getStatus() === Order::STATE_PROCESSING) ) { - //do not update to failed if we had a success already - $this->logger->addDebug(__METHOD__ . '|2|'); + $this->logger->addDebug( + '[PUSH] | [Webapi] | ['. __METHOD__ .':'. __LINE__ . '] - Do not update to failed if we had a success' + ); return false; } @@ -925,10 +958,8 @@ public function processFailedPush(string $newStatus, string $message): bool if (!empty($this->pushRequest->getServiceAntifraudAction())) { $description .= $this->pushRequest->getServiceAntifraudAction() . - ' ' . - $this->pushRequest->getServiceAntifraudCheck() . - ' ' . - $this->pushRequest->getServiceAntifraudDetails(); + ' ' . $this->pushRequest->getServiceAntifraudCheck() . + ' ' . $this->pushRequest->getServiceAntifraudDetails(); } $store = $this->order->getStore(); @@ -938,7 +969,11 @@ public function processFailedPush(string $newStatus, string $message): bool $payment = $this->order->getPayment(); if ($buckarooCancelOnFailed && $this->order->canCancel()) { - $this->logger->addDebug(__METHOD__ . '|' . 'Buckaroo push failed : ' . $message . ' : Cancel order.'); + $this->logger->addDebug(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Process the failed push response from Buckaroo. Cancel Order: %s', + __METHOD__, __LINE__, + $message + )); // BUCKM2-78: Never automatically cancelauthorize via push for afterpay // setting parameter which will cause to stop the cancel process on @@ -958,14 +993,16 @@ public function processFailedPush(string $newStatus, string $message): bool try { $this->order->cancel()->save(); - } catch (\Throwable $t) { - $this->logger->addDebug(__METHOD__ . '|3|'); - // SignifydGateway/Gateway error on line 208" + } catch (\Throwable $th) { + $this->logger->addError(sprintf( + '[PUSH] | [Webapi] | [%s:%s] - Process failed push from Buckaroo. Cancel Order| [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); } return true; } - $this->logger->addDebug(__METHOD__ . '|4|'); $force = false; if (($payment->getMethodInstance()->getCode() == 'buckaroo_magento2_mrcash') && ($this->order->getState() === Order::STATE_NEW) @@ -1023,8 +1060,6 @@ protected function getPaymentDetails($message) $amount = $this->order->getBaseTotalDue(); $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; - - $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) diff --git a/Model/Push/TransferProcessor.php b/Model/Push/TransferProcessor.php index a2ee1aae7..354ca88a7 100644 --- a/Model/Push/TransferProcessor.php +++ b/Model/Push/TransferProcessor.php @@ -26,10 +26,8 @@ protected function getPaymentDetails($message) if ($this->canPushInvoice()) { $description = 'Payment status : ' . $message . "
"; if ($this->pushRequest->hasPostData('transaction_method', 'transfer')) { - //keep amount fetched from brq_amount $description .= 'Amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) . ' has been paid'; } - $this->logger->addDebug(__METHOD__ . '|4|'); } else { $description = 'Authorization status : ' . $message . "
"; $description .= 'Total amount of ' . $this->order->getBaseCurrency()->formatTxt($amount) @@ -45,6 +43,8 @@ protected function getPaymentDetails($message) } /** + * Create invoice only in case of full or last remained amount + * * @param array $paymentDetails * @return bool * @throws LocalizedException @@ -52,24 +52,25 @@ protected function getPaymentDetails($message) protected function invoiceShouldBeSaved(array &$paymentDetails): bool { $amount = $paymentDetails['amount']; - //invoice only in case of full or last remained amount - $this->logger->addDebug(__METHOD__ . '|61|' . var_export([ - $this->order->getId(), - $paymentDetails['amount'], - $this->order->getTotalDue(), - $this->order->getTotalPaid(), - ], true)); + + $this->logger->addDebug(sprintf( + '[PUSH - Transfer] | [Webapi] | [%s:%s] - Update totals by amount from request | order: %s', + __METHOD__, __LINE__, + var_export([ + 'orderId' => $this->order->getId(), + 'totalDue' => $this->order->getTotalDue(), + 'totalPaid' => $this->order->getTotalPaid(), + 'amount' => $amount, + ], true) + )); $saveInvoice = true; if (($paymentDetails['amount'] < $this->order->getTotalDue()) || (($paymentDetails['amount'] == $this->order->getTotalDue()) && ($this->order->getTotalPaid() > 0)) ) { - $this->logger->addDebug(__METHOD__ . '|64|'); - $paymentDetails['forceState'] = true; if ($amount < $this->order->getTotalDue()) { - $this->logger->addDebug(__METHOD__ . '|65|'); $paymentDetails['state'] = Order::STATE_NEW; $paymentDetails['newStatus'] = $this->orderStatusFactory->get( BuckarooStatusCode::PENDING_PROCESSING, @@ -78,8 +79,6 @@ protected function invoiceShouldBeSaved(array &$paymentDetails): bool $saveInvoice = false; } - $this->orderRequestService->saveAndReloadOrder(); - $this->order->setTotalDue($this->order->getTotalDue() - $amount); $this->order->setBaseTotalDue($this->order->getTotalDue() - $amount); diff --git a/Model/RequestPush/RequestPushFactory.php b/Model/RequestPush/RequestPushFactory.php index eb48b53f5..29e7ad21e 100644 --- a/Model/RequestPush/RequestPushFactory.php +++ b/Model/RequestPush/RequestPushFactory.php @@ -67,23 +67,31 @@ public function create(): PushRequestInterface { try { if (strpos($this->request->getContentType(), 'application/json') !== false) { - $this->logger->addDebug(__METHOD__ . '|Create json object|' . var_export( - $this->request->getRequestData(), - true + $this->logger->addDebug(sprintf( + '[PUSH] | [Factory] | [%s:%s] - Create Json Request Object | request: %s', + __METHOD__, __LINE__, + var_export($this->request->getRequestData(), true) )); + return $this->objectManager->create( JsonPushRequest::class, ['requestData' => $this->request->getRequestData()] ); } } catch (\Exception $exception) { - $this->logger->addDebug(__METHOD__ . '|EXCEPTION|' . var_export($exception->getMessage(), true)); + $this->logger->addError(sprintf( + '[PUSH] | [Factory] | [%s:%s] - Create Json Request Object | [ERROR]: %s', + __METHOD__, __LINE__, + $exception->getMessage() + )); } - $this->logger->addDebug(__METHOD__ . '|Create httppost object|' . var_export( - $this->request->getRequestData(), - true + $this->logger->addDebug(sprintf( + '[PUSH] | [Factory] | [%s:%s] - Create HTTP Post Request Object | request: %s', + __METHOD__, __LINE__, + var_export($this->request->getRequestData(), true) )); + return $this->objectManager->create( HttppostPushRequest::class, ['requestData' => $this->request->getPostValue()] diff --git a/Model/Service/QuoteAddressService.php b/Model/Service/QuoteAddressService.php index feb9edf2a..59feb18f6 100644 --- a/Model/Service/QuoteAddressService.php +++ b/Model/Service/QuoteAddressService.php @@ -156,7 +156,11 @@ protected function maybeFillShippingAddressFields(Quote $quote) */ public function setShippingAddress(Quote &$quote, array $data): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); + $this->logger->addDebug(sprintf( + '[SET_SHIPPING_ADDRESS] | [Service] | [%s:%s] - Set Shipping Address | data: %s', + __METHOD__, __LINE__, + var_export($data, true) + )); $shippingAddress = $this->processAddressFromWallet($data); $quote->getShippingAddress()->addData($shippingAddress); @@ -212,17 +216,19 @@ public function processAddressFromWallet(array $wallet, string $type = 'shipping */ protected function setCommonAddressProceed($errors, string $addressType): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); - $this->logger->addDebug(var_export($errors, true)); + $this->logger->addDebug(sprintf( + '[SET_SHIPPING_ADDRESS] | [Service] | [%s:%s] - Set Shipping Address | errors: %s', + __METHOD__, __LINE__, + var_export($errors, true) + )); if ($errors && is_array($errors)) { foreach ($errors as $error) { if (($arguments = $error->getArguments()) && !empty($arguments['fieldName'])) { if ($arguments['fieldName'] === 'postcode') { - $this->logger->addDebug(var_export($error->getArguments()['fieldName'], true)); - throw new ExpressMethodsException(__( + throw new ExpressMethodsException( 'Error: ' . $addressType . ' address: postcode is required.' - )); + ); } } } @@ -266,8 +272,6 @@ protected function maybeFillBillingAddressFields(ShippingAddressRequestInterface */ public function setBillingAddress(Quote &$quote, array $data): bool { - $this->logger->addDebug(__METHOD__ . '|1|'); - $billingAddress = $this->processAddressFromWallet($data, 'billing'); $quote->getBillingAddress()->addData($billingAddress); @@ -288,10 +292,12 @@ public function assignAddressToQuote(AddressInterface $shippingAddress, Quote $c try { $this->shippingAddressManagement->assign($cart->getId(), $shippingAddress); } catch (\Exception $e) { - $this->logger->addDebug(__METHOD__ . '|9.1|' . $e->getMessage()); - throw new ExpressMethodsException(__( - 'Assign Shipping Address to Quote failed.' + $this->logger->addError(sprintf( + '[SET_SHIPPING_ADDRESS] | [Service] | [%s:%s] - Set Shipping Address | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() )); + throw new ExpressMethodsException('Assign Shipping Address to Quote failed.'); } $this->quoteRepository->save($cart); diff --git a/Model/Service/QuoteService.php b/Model/Service/QuoteService.php index 66a54e848..8c520cdd3 100644 --- a/Model/Service/QuoteService.php +++ b/Model/Service/QuoteService.php @@ -170,7 +170,11 @@ public function createQuote(array $formData): Quote $this->quote = $quoteBuilder->build(); return $this->quote; } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . $th->getMessage()); + $this->logger->addError(sprintf( + '[CREATE_QUOTE] | [Service] | [%s:%s] - Create quote if in product page | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); throw new QuoteException(__("Failed to create quote"), 1, $th); } } diff --git a/Model/Validator/Push.php b/Model/Validator/Push.php index 19501ff82..e9a504a7a 100644 --- a/Model/Validator/Push.php +++ b/Model/Validator/Push.php @@ -171,12 +171,12 @@ public function calculateSignature(array $postData, $store = null): string } $digitalSignature = $this->encryptor->decrypt($this->configProviderAccount->getSecretKey($store)); - $signatureString .= $digitalSignature; - $signature = SHA1($signatureString); - $this->logger->addDebug($signature); + $this->logger->addDebug( + '[PUSH] | [Webapi] | [' . __METHOD__ . ':' . __LINE__ . '] - Calculated signature: ' . $signature, + ); return $signature; } diff --git a/Observer/OrderCancelAfter.php b/Observer/OrderCancelAfter.php index 00674ed59..9f55c97b4 100644 --- a/Observer/OrderCancelAfter.php +++ b/Observer/OrderCancelAfter.php @@ -99,31 +99,28 @@ public function __construct( */ public function execute(Observer $observer) { - /** - * @noinspection PhpUndefinedMethodInspection - */ /* @var $order Order */ $order = $observer->getEvent()->getOrder(); - $payment = $order->getPayment(); - $originalKey = $payment->getAdditionalInformation(BuckarooAdapter::BUCKAROO_ORIGINAL_TRANSACTION_KEY_KEY); - $cancelPPE = $this->configProviderPPE->getCancelPpe(); - if ($cancelPPE && in_array($payment->getMethodInstance()->getCode(), ['buckaroo_magento2_payperemail'])) { + if ($cancelPPE && $payment->getMethod() == PayPerEmail::CODE) { try { $this->logger->addDebug(sprintf( - '[CANCEL_ORDER] | [Observer] | [%s:%s] - Send Cancel Order Request after order cancel |' . - ' originalKey: %s | order: %s', + '[CANCEL_ORDER - PayPerEmail] | [Observer] | [%s:%s] - Send Cancel Order Request for PayPerEmail' . + 'to payment engine | originalKey: %s | order: %s', __METHOD__, __LINE__, var_export([$originalKey], true), $order->getId() )); $this->sendCancelResponse($originalKey); - //phpcs:ignore: Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (\Exception $e) { - // empty block + $this->logger->addError(sprintf( + '[CANCEL_ORDER - PayPerEmail] | [Observer] | [%s:%s] - Send Cancel Request for PPE | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } } } diff --git a/Observer/SalesOrderShipmentAfter.php b/Observer/SalesOrderShipmentAfter.php index cfdc6257e..1dd101f52 100644 --- a/Observer/SalesOrderShipmentAfter.php +++ b/Observer/SalesOrderShipmentAfter.php @@ -129,8 +129,6 @@ public function execute(Observer $observer) $order = $shipment->getOrder(); $payment = $order->getPayment(); - $this->logger->addDebug(__METHOD__ . '|1|'); - if (($payment->getMethodInstance()->getCode() == 'buckaroo_magento2_klarnakp') && $this->klarnakpConfig->isInvoiceCreatedAfterShipment() ) { @@ -156,7 +154,11 @@ public function execute(Observer $observer) */ private function createInvoice(Order $order, Shipment $shipment, bool $allowPartialsWithDiscount = false) { - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($order->getDiscountAmount(), true)); + $this->logger->addDebug(sprintf( + '[CREATE_INVOICE] | [Observer] | [%s:%s] - Create invoice after shipment | orderDiscountAmount: %s', + __METHOD__, __LINE__, + var_export($order->getDiscountAmount(), true) + )); try { if (!$order->canInvoice()) { @@ -182,7 +184,11 @@ private function createInvoice(Order $order, Shipment $shipment, bool $allowPart ); $transactionSave->save(); - $this->logger->addDebug(__METHOD__ . '|3|' . var_export($order->getStatus(), true)); + $this->logger->addDebug(sprintf( + '[CREATE_INVOICE] | [Observer] | [%s:%s] - Create invoice after shipment | orderStatus: %s', + __METHOD__, __LINE__, + var_export($order->getStatus(), true) + )); if ($order->getStatus() == 'complete') { $description = 'Total amount of ' @@ -192,8 +198,12 @@ private function createInvoice(Order $order, Shipment $shipment, bool $allowPart $order->save(); } - $this->logger->addDebug(__METHOD__ . '|4|'); } catch (\Exception $e) { + $this->logger->addDebug(sprintf( + '[CREATE_INVOICE] | [Observer] | [%s:%s] - Create invoice after shipment | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); $order->addStatusHistoryComment('Exception message: ' . $e->getMessage(), false); $order->save(); return null; diff --git a/Observer/SendInvoiceMail.php b/Observer/SendInvoiceMail.php index e6cb22a91..0dc9b0c7f 100644 --- a/Observer/SendInvoiceMail.php +++ b/Observer/SendInvoiceMail.php @@ -78,8 +78,6 @@ public function __construct( */ public function execute(Observer $observer) { - $this->logger->addDebug(__METHOD__ . '|1|'); - /** @var Invoice $invoice */ $invoice = $observer->getEvent()->getInvoice(); $payment = $invoice->getOrder()->getPayment(); @@ -94,13 +92,14 @@ public function execute(Observer $observer) if (!$invoice->getEmailSent() && $invoice->getIsPaid() && $canCapture && $sendInvoiceEmail) { $invoice->save(); - $this->logger->addDebug(__METHOD__ . '|10|sendinvoiceemail'); + $this->logger->addDebug( + '[SEND_EMAIL] | [Observer] | ['.__METHOD__.':'.__LINE__.'] - Send email on creating invoice' + ); $orderBaseSubtotal = $order->getBaseSubtotal(); $orderBaseTaxAmount = $order->getBaseTaxAmount(); $orderBaseShippingAmount = $order->getBaseShippingAmount(); $this->invoiceSender->send($invoice, true); if (($orderBaseShippingAmount > 0) && ($order->getBaseShippingAmount() == 0)) { - $this->logger->addDebug(__METHOD__ . '|15|'); $invoice->getOrder()->setBaseShippingAmount($orderBaseShippingAmount); } $order->setBaseSubtotal($orderBaseSubtotal); @@ -111,7 +110,6 @@ public function execute(Observer $observer) && !$this->helper->areEqualAmounts($order->getBaseTotalPaid(), $order->getTotalPaid()) && ($order->getBaseCurrencyCode() == $order->getOrderCurrencyCode()) ) { - $this->logger->addDebug(__METHOD__ . '|25|'); $order->setBaseTotalPaid($order->getTotalPaid()); } } diff --git a/Observer/SendOrderConfirmation.php b/Observer/SendOrderConfirmation.php index 51927b964..8980f8b39 100644 --- a/Observer/SendOrderConfirmation.php +++ b/Observer/SendOrderConfirmation.php @@ -96,7 +96,11 @@ public function execute(Observer $observer) && $order->getIncrementId() && !$createOrderBeforeTransaction ) { - $this->logger->addDebug(__METHOD__ . '|sendemail|'); + $this->logger->addDebug(sprintf( + '[SEND_MAIL] | [Observer] | [%s:%s] - Send order confirmation on email | order: %s', + __METHOD__, __LINE__, + $order->getId() + )); $this->orderSender->send($order, true); } } diff --git a/Plugin/CommandInterface.php b/Plugin/CommandInterface.php index 42bba93a0..c980c4eb1 100644 --- a/Plugin/CommandInterface.php +++ b/Plugin/CommandInterface.php @@ -24,6 +24,11 @@ use Buckaroo\Magento2\Exception; use Buckaroo\Magento2\Helper\Data; use Buckaroo\Magento2\Logging\BuckarooLoggerInterface; +use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay; +use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay2; +use Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay20; +use Buckaroo\Magento2\Model\ConfigProvider\Method\Applepay; +use Buckaroo\Magento2\Model\ConfigProvider\Method\Eps; use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory; use Buckaroo\Magento2\Model\ConfigProvider\Method\PayPerEmail; use Magento\Payment\Model\MethodInterface; @@ -76,6 +81,7 @@ public function __construct( * @return mixed * * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws Exception */ public function aroundExecute( MagentoCommandInterface $commandInterface, @@ -86,48 +92,79 @@ public function aroundExecute( ) { $message = $proceed($payment, $amount, $order); - /** @var MethodInterface $methodInstance */ $methodInstance = $payment->getMethodInstance(); $paymentAction = $methodInstance->getConfigPaymentAction(); - $paymentCode = substr($methodInstance->getCode(), 0, 18); + $paymentCode = $methodInstance->getCode(); + $buckarooPaymentCode = substr($paymentCode, 0, 18); + + $this->logger->addDebug(sprintf( + '[UPDATE_STATUS] | [Plugin] | [%s:%s] - Update order state and status |' . + ' paymentMethod: %s | paymentAction: %s', + __METHOD__, __LINE__, + $paymentCode, + $paymentAction + )); - $this->logger->addDebug(__METHOD__ . '|1|' . var_export([$methodInstance->getCode(), $paymentAction], true)); + if ($buckarooPaymentCode == 'buckaroo_magento2_' && $paymentAction) { + $orderState = Order::STATE_NEW; + $orderStatus = $this->helper->getOrderStatusByState($order, $orderState); - if ($paymentCode == 'buckaroo_magento2_' && $paymentAction) { - if (($methodInstance->getCode() == PayPerEmail::CODE) && ($paymentAction == 'order')) { - $config = $this->configProviderMethodFactory->get(PayPerEmail::CODE); - if ($config->isEnabledB2B()) { - $this->logger->addDebug(__METHOD__ . '|5|'); - return $message; - } + if ($this->skipUpdateOrderStateAndStatus($orderStatus, $order, $methodInstance)) { + $this->logger->addDebug(sprintf( + '[UPDATE_STATUS] | [Plugin] | [%s:%s] - Skip Update order state and status |' . + ' paymentMethod: %s | paymentAction: %s, orderStatus: %s', + __METHOD__, __LINE__, + $paymentCode, + $paymentAction, + $orderStatus + )); + return $message; } - $this->updateOrderStateAndStatus($order, $methodInstance); + + $order->setState($orderState); + $order->setStatus($orderStatus); } return $message; } /** - * Update order state and status based on the payment method + * Determines if the order's state and status update should be skipped based on payment method and configuration. * - * @param OrderInterface|Order $order + * - Skips for PayPerEmail B2B when the payment action is 'order'. + * - Skips for Afterpay, Afterpay20, Afterpay2, and EPS if status is pending, state is processing + * - Always skips for Apple Pay. + * + * @param string $orderStatus + * @param OrderInterface $order * @param MethodInterface $methodInstance + * @return bool * @throws Exception */ - private function updateOrderStateAndStatus(OrderInterface $order, MethodInterface $methodInstance) - { - $orderState = Order::STATE_NEW; - $orderStatus = $this->helper->getOrderStatusByState($order, $orderState); + private function skipUpdateOrderStateAndStatus( + string $orderStatus, + OrderInterface $order, + MethodInterface $methodInstance + ): bool { + $paymentAction = $methodInstance->getConfigPaymentAction(); + $paymentCode = $methodInstance->getCode(); - $this->logger->addDebug(__METHOD__ . '|5|' . var_export($orderStatus, true)); + // Skip setting the status here for PayPerEmail B2B + if (($paymentCode == PayPerEmail::CODE) && ($paymentAction == 'order')) { + $config = $this->configProviderMethodFactory->get(PayPerEmail::CODE); + if ($config->isEnabledB2B()) { + return true; + } + } + // Skip setting the status here for Afterpay and EPS if (( ( - preg_match('/afterpay/', $methodInstance->getCode()) + in_array($paymentCode, [Afterpay::CODE, Afterpay20::CODE, Afterpay2::CODE]) && $this->helper->getOriginalTransactionKey($order->getIncrementId()) ) || ( - preg_match('/eps/', $methodInstance->getCode()) + $paymentCode == Eps::CODE && ($this->helper->getMode($methodInstance->getCode()) != Data::MODE_LIVE) ) ) @@ -135,15 +172,14 @@ private function updateOrderStateAndStatus(OrderInterface $order, MethodInterfac && ($order->getState() === Order::STATE_PROCESSING) && ($order->getStatus() === Order::STATE_PROCESSING) ) { - $this->logger->addDebug(__METHOD__ . '|10|'); - return false; + return true; } - //skip setting the status here for applepay - if (preg_match('/applepay/', $methodInstance->getCode())) { - return; + // Skip setting the status here for Apple Pay + if ($paymentCode == Applepay::CODE) { + return true; } - $order->setState($orderState); - $order->setStatus($orderStatus); + + return false; } } diff --git a/Plugin/Onepage/Success.php b/Plugin/Onepage/Success.php index 0238f51e7..3950789d3 100644 --- a/Plugin/Onepage/Success.php +++ b/Plugin/Onepage/Success.php @@ -78,13 +78,14 @@ public function aroundExecute(ControllerOnePageSuccess $checkoutSuccess, callabl $order = $checkoutSuccess->getOnepage()->getCheckout()->getLastRealOrder(); $payment = $order->getPayment(); - $this->logger->addDebug( + $this->logger->addDebug(sprintf( + '[SUCCESS_PAGE] | [Plugin] | [%s:%s] - Redirect to cart | details: %s', + __METHOD__, __LINE__, var_export([ - $order->getStatus() === BuckarooDataHelper::M2_ORDER_STATE_PENDING, - $this->checkPaymentType->isPaymentInTransit($payment), - $order->getStatus() === Order::STATE_CANCELED + 'orderStatus' => $order->getStatus(), + 'isPaymentInTransit' => $this->checkPaymentType->isPaymentInTransit($payment) ], true) - ); + )); if ($this->checkPaymentType->isBuckarooPayment($payment) && ( diff --git a/Service/Applepay/Add.php b/Service/Applepay/Add.php index c4f49846f..2472e06da 100644 --- a/Service/Applepay/Add.php +++ b/Service/Applepay/Add.php @@ -98,7 +98,11 @@ public function process(array $request) 'totals' => $totals ]; } catch (\Exception $exception) { - $this->logger->addDebug(__METHOD__ . '|exception|' . $exception->getMessage()); + $this->logger->addError(sprintf( + '[ApplePay] | [Controller] | [%s:%s] - Add Product to Cart on Apple Pay | [ERROR]: %s', + __METHOD__, __LINE__, + $exception->getMessage() + )); return false; } } diff --git a/Service/Formatter/Address/PhoneFormatter.php b/Service/Formatter/Address/PhoneFormatter.php index 44195b317..b7d6faf09 100644 --- a/Service/Formatter/Address/PhoneFormatter.php +++ b/Service/Formatter/Address/PhoneFormatter.php @@ -77,8 +77,11 @@ public function __construct( */ public function format(string $phoneNumber, string $country): array { - $this->logger->addDebug(__METHOD__ . '|1|'); - $this->logger->addDebug(var_export([$phoneNumber, $country], true)); + $this->logger->addDebug(sprintf( + '[PHONE_FORMATER] | [Service] | [%s:%s] - Format phone number by country | request: %s', + __METHOD__, __LINE__, + var_export(['phoneNumber' => $phoneNumber, 'country' => $country], true) + )); $return = ["orginal" => $phoneNumber, "clean" => false, "mobile" => false, "valid" => false]; @@ -94,8 +97,11 @@ public function format(string $phoneNumber, string $country): array $return['valid'] = true; } - $this->logger->addDebug(__METHOD__ . '|2|'); - $this->logger->addDebug(var_export($return, true)); + $this->logger->addDebug(sprintf( + '[PHONE_FORMATER] | [Service] | [%s:%s] - Format phone number by country | response: %s', + __METHOD__, __LINE__, + var_export($return, true) + )); return $return; } diff --git a/Service/Push/OrderRequestService.php b/Service/Push/OrderRequestService.php index 19224a2b7..c32bf389d 100644 --- a/Service/Push/OrderRequestService.php +++ b/Service/Push/OrderRequestService.php @@ -313,15 +313,7 @@ public function saveAndReloadOrder() */ public function loadOrder() { - $brqOrderId = $this->getOrderIncrementId(); - - //Check if the order can receive further status updates + $brqOrderId = $this->getOrderByRequest()->getIncrementId(); $this->order->loadByIncrementId((string)$brqOrderId); - - if (!$this->order->getId()) { - $this->logger->addDebug('Order could not be loaded by Invoice Number or Order Number'); - // try to get order by transaction id on payment. - $this->order = $this->getOrderByTransactionKey(); - } } } \ No newline at end of file From e2d72e72aaccf8b2229343f042b2fa90843e3fe1 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Wed, 23 Aug 2023 18:26:24 +0300 Subject: [PATCH 5/6] BP-2433 - Finish to add Logging more descriptive --- Cron/LogCleaner.php | 12 ++++++-- .../DHLParcelAddressHandler.php | 1 - .../DPDPickupAddressHandler.php | 15 ++++++---- .../AddressHandler/MyParcelAddressHandler.php | 28 +++++++++++-------- Model/Adapter/BuckarooAdapter.php | 13 +++++++-- Model/Push/GroupTransactionPushProcessor.php | 6 +++- Service/Push/OrderRequestService.php | 25 ++++++++++++----- 7 files changed, 71 insertions(+), 29 deletions(-) diff --git a/Cron/LogCleaner.php b/Cron/LogCleaner.php index 979401c6b..ee816b7dc 100644 --- a/Cron/LogCleaner.php +++ b/Cron/LogCleaner.php @@ -129,7 +129,11 @@ private function proceedDb(int $retentionPeriod) ['time <= date_sub(now(),interval ' . $retentionPeriod . ' second)'] ); } catch (\Exception $e) { - $this->logger->error('Proceed Db error:' . var_export($e->getMessage(), true)); + $this->logger->error(sprintf( + '[LOGGING] | [CRON] | [%s:%s] - Delete logs from data base. Proceed DB error. | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } } @@ -168,7 +172,11 @@ private function getAllFiles(string $path): array $path = $this->directoryList->getPath('var') . $path; $paths = $this->driverFile->readDirectory($path); } catch (FileSystemException $e) { - $this->logger->error('Get All Files error:' . var_export($e->getMessage(), true)); + $this->logger->error(sprintf( + '[LOGGING] | [CRON] | [%s:%s] - Get all files from log directory. | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getMessage() + )); } return $paths; diff --git a/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php b/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php index ae8754b13..b574084cf 100644 --- a/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php +++ b/Gateway/Request/AddressHandler/DHLParcelAddressHandler.php @@ -71,7 +71,6 @@ public function handle(Order $order, OrderAddressInterface $shippingAddress): Or */ public function updateShippingAddressByDhlParcel(string $servicePointId, OrderAddressInterface $shippingAddress) { - $this->logger->addDebug(__METHOD__ . '|1|'); $matches = []; if (preg_match('/^(.*)-([A-Z]{2})-(.*)$/', $servicePointId, $matches)) { $this->curl->get( diff --git a/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php b/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php index f3bbdae7e..7c4b83644 100644 --- a/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php +++ b/Gateway/Request/AddressHandler/DPDPickupAddressHandler.php @@ -84,8 +84,11 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r $country = $quote->getDpdCountry(); if (!$fullStreet && $quote->getDpdParcelshopId()) { - $this->logger->addDebug(__METHOD__ . '|2|'); - $this->logger->addDebug(var_export($_COOKIE, true)); + $this->logger->addDebug(sprintf( + '[CREATE_ORDER] | [Gateway] | [%s:%s] - Set shipping address fields by DPD Parcel | cookie: %s', + __METHOD__, __LINE__, + var_export($_COOKIE, true) + )); $fullStreet = $_COOKIE['dpd-selected-parcelshop-street'] ?? ''; $postalCode = $_COOKIE['dpd-selected-parcelshop-zipcode'] ?? ''; $city = $_COOKIE['dpd-selected-parcelshop-city'] ?? ''; @@ -94,8 +97,6 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r $matches = false; if ($fullStreet && preg_match('/(.*)\s(.+)$/', $fullStreet, $matches)) { - $this->logger->addDebug(__METHOD__ . '|3|'); - $street = $matches[1]; $streetHouseNumber = $matches[2]; @@ -107,7 +108,11 @@ public function updateShippingAddressByDpdParcel(CartInterface $quote, array &$r ['StreetNumber', $streetHouseNumber], ]; - $this->logger->addDebug(var_export($mapping, true)); + $this->logger->addDebug(sprintf( + '[CREATE_ORDER] | [Gateway] | [%s:%s] - Set shipping address fields by DPD Parcel | newAddress: %s', + __METHOD__, __LINE__, + var_export($mapping, true) + )); $this->updateShippingAddressCommonMapping($mapping, $requestData); diff --git a/Gateway/Request/AddressHandler/MyParcelAddressHandler.php b/Gateway/Request/AddressHandler/MyParcelAddressHandler.php index b7985de27..35fc53026 100644 --- a/Gateway/Request/AddressHandler/MyParcelAddressHandler.php +++ b/Gateway/Request/AddressHandler/MyParcelAddressHandler.php @@ -54,7 +54,6 @@ public function __construct(BuckarooLoggerInterface $logger, BuckarooHelper $hel */ public function handle(Order $order, OrderAddressInterface $shippingAddress): Order { - $this->logger->addDebug(__METHOD__ . '|1|'); $myparcelFetched = false; $myparcelOptions = $order->getData('myparcel_delivery_options'); $requestData = $shippingAddress->getData(); @@ -70,25 +69,24 @@ public function handle(Order $order, OrderAddressInterface $shippingAddress): Or $myparcelFetched = true; } } catch (\JsonException $je) { - $this->logger->addDebug( - __METHOD__ . '|2|' . ' Error related to json_decode (MyParcel plugin compatibility)' - ); + $this->logger->addError(sprintf( + '[CREATE_ORDER] | [Gateway] | [%s:%s] - Error related to json_decode' . ' + (MyParcel plugin compatibility) | [ERROR]: %s', + __METHOD__, __LINE__, + $je->getMessage() + )); } } if (!$myparcelFetched) { - $this->logger->addDebug(__METHOD__ . '|10|'); if ((strpos((string)$order->getShippingMethod(), 'myparcelnl') !== false) - && - (strpos((string)$order->getShippingMethod(), 'pickup') !== false) + && (strpos((string)$order->getShippingMethod(), 'pickup') !== false) ) { - $this->logger->addDebug(__METHOD__ . '|15|'); if ($this->helper->getCheckoutSession()->getMyParcelNLBuckarooData() && $myParcelNLData = $this->helper->getJson()->unserialize( $this->helper->getCheckoutSession()->getMyParcelNLBuckarooData() ) ) { - $this->logger->addDebug(__METHOD__ . '|20|'); $this->updateShippingAddressByMyParcel($myParcelNLData, $requestData); } } @@ -116,7 +114,11 @@ protected function updateShippingAddressByMyParcel(array $myParcelLocation, arra ['ShippingHouseNumberSuffix', $myParcelLocation['number_suffix']], ]; - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); + $this->logger->addDebug(sprintf( + '[CREATE_ORDER] | [Gateway] | [%s:%s] - Set shipping address fields by myParcelNL | newAddress: %s', + __METHOD__, __LINE__, + var_export($mapping, true) + )); $this->updateShippingAddressCommonMappingV2($mapping, $requestData); } @@ -139,7 +141,11 @@ protected function updateShippingAddressByMyParcelV2(array $myParcelLocation, ar ['StreetNumberAdditional', $myParcelLocation['number_suffix']], ]; - $this->logger->addDebug(__METHOD__ . '|1|' . var_export($mapping, true)); + $this->logger->addDebug(sprintf( + '[CREATE_ORDER] | [Gateway] | [%s:%s] - Set shipping address fields by myParcelNL V2 | newAddress: %s', + __METHOD__, __LINE__, + var_export($mapping, true) + )); $this->updateShippingAddressCommonMapping($mapping, $requestData); } diff --git a/Model/Adapter/BuckarooAdapter.php b/Model/Adapter/BuckarooAdapter.php index d958d599e..038512d3f 100644 --- a/Model/Adapter/BuckarooAdapter.php +++ b/Model/Adapter/BuckarooAdapter.php @@ -125,7 +125,12 @@ public function execute(string $action, string $method, array $data): Transactio return $payment->{$action}($data); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . $th); + $this->logger->addError(sprintf( + '[SDK] | [Adapter] | [%s:%s] - Execute request using Buckaroo SDK | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); + throw $th; } } @@ -141,7 +146,11 @@ public function getIdealIssuers(): array try { return $this->buckaroo->method('ideal')->issuers(); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . $th); + $this->logger->addError(sprintf( + '[SDK] | [Adapter] | [%s:%s] - Get ideal issuers | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); return []; } } diff --git a/Model/Push/GroupTransactionPushProcessor.php b/Model/Push/GroupTransactionPushProcessor.php index 37c2ae368..e8e2527c4 100644 --- a/Model/Push/GroupTransactionPushProcessor.php +++ b/Model/Push/GroupTransactionPushProcessor.php @@ -203,7 +203,11 @@ protected function handleGroupTransactionFailed() $this->savePartGroupTransaction(); } catch (\Throwable $th) { - $this->logger->addDebug(__METHOD__ . '|' . (string)$th); + $this->logger->addError(sprintf( + '[SDK] | [Adapter] | [%s:%s] - Handle push group transaction fail | [ERROR]: %s', + __METHOD__, __LINE__, + $th->getMessage() + )); } } diff --git a/Service/Push/OrderRequestService.php b/Service/Push/OrderRequestService.php index c32bf389d..e188658e5 100644 --- a/Service/Push/OrderRequestService.php +++ b/Service/Push/OrderRequestService.php @@ -107,7 +107,10 @@ public function getOrderByRequest(?PushRequestInterface $pushRequest = null) $this->order->loadByIncrementId((string)$brqOrderId); if (!$this->order->getId()) { - $this->logger->addDebug('Order could not be loaded by Invoice Number or Order Number'); + $this->logger->addDebug(sprintf( + '[ORDER] | [Service] | [%s:%s] - Order could not be loaded by Invoice Number or Order Number', + __METHOD__, __LINE__ + )); // Try to get order by transaction id on payment. $this->order = $this->getOrderByTransactionKey($pushRequest); } @@ -196,7 +199,11 @@ public function setOrderNotificationNote($message): void $this->order->addStatusToHistory($note); $this->order->save(); } catch (\Exception $e) { - $this->logger->addDebug($e->getLogMessage()); + $this->logger->addError(sprintf( + '[ORDER] | [Service] | [%s:%s] - Set Order Notification Note Failed | [ERROR]: %s', + __METHOD__, __LINE__, + $e->getLogMessage() + )); } } @@ -218,10 +225,16 @@ public function updateOrderStatus( bool $force = false, bool $dontSaveOrderUponSuccessPush = false ): void { - $this->logger->addDebug(__METHOD__ . '|0|' . var_export([$orderState, $newStatus, $description], true)); + $this->logger->addDebug(sprintf( + '[ORDER] | [Service] | [%s:%s] - Updates the order state and add a comment | data: %s', + __METHOD__, __LINE__, + var_export([ + 'orderState' => $orderState, + 'newStatus' => $newStatus, + 'description' => $description + ], true) + )); if ($this->order->getState() == $orderState || $force) { - $this->logger->addDebug(__METHOD__ . '|1|'); - $this->logger->addDebug('||| $orderState: ' . '|1|' . $orderState); if ($dontSaveOrderUponSuccessPush) { $this->order->addCommentToStatusHistory($description) ->setIsCustomerNotified(false) @@ -232,8 +245,6 @@ public function updateOrderStatus( $this->order->addCommentToStatusHistory($description, $newStatus); } } else { - $this->logger->addDebug(__METHOD__ . '|2|'); - $this->logger->addDebug('||| $orderState: ' . '|2|' . $orderState); if ($dontSaveOrderUponSuccessPush) { $this->order->addCommentToStatusHistory($description) ->setIsCustomerNotified(false) From e6375ddd801dd5f10cfc250d7735004125d481b1 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Thu, 24 Aug 2023 14:24:09 +0300 Subject: [PATCH 6/6] BP-2433 - Finish to add Logging more descriptive, Fix PHP MD --- Plugin/CommandInterface.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugin/CommandInterface.php b/Plugin/CommandInterface.php index c980c4eb1..7e1c2e2e5 100644 --- a/Plugin/CommandInterface.php +++ b/Plugin/CommandInterface.php @@ -37,6 +37,9 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Payment\State\CommandInterface as MagentoCommandInterface; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class CommandInterface { /** @@ -140,6 +143,8 @@ public function aroundExecute( * @param MethodInterface $methodInstance * @return bool * @throws Exception + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function skipUpdateOrderStateAndStatus( string $orderStatus,