Skip to content

Commit

Permalink
Merge pull request #778 from buckaroo-it/BP-2433-make-the-logging-mor…
Browse files Browse the repository at this point in the history
…e-descriptive

BP-2433 make the logging more descriptive
  • Loading branch information
LucianTuriacArnia authored Aug 24, 2023
2 parents c7de473 + e6375dd commit 0596b9d
Show file tree
Hide file tree
Showing 75 changed files with 1,331 additions and 817 deletions.
10 changes: 7 additions & 3 deletions Controller/Adminhtml/Notification/MarkUserNotified.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions Controller/Applepay/AbstractApplepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,9 +32,9 @@
abstract class AbstractApplepay implements HttpPostActionInterface
{
/**
* @var Log $logging
* @var BuckarooLoggerInterface $logger
*/
public Log $logging;
public BuckarooLoggerInterface $logger;

/**
* @var JsonFactory
Expand All @@ -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;
}

/**
Expand Down
24 changes: 17 additions & 7 deletions Controller/Applepay/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,24 +32,24 @@ class Add extends AbstractApplepay
/**
* @var AddService
*/
protected $addService;
protected AddService $addService;

/**
* @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;
}
Expand All @@ -61,10 +61,20 @@ public function __construct(
*/
public function execute()
{
$this->logging->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->logging->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);
}
Expand Down
33 changes: 19 additions & 14 deletions Controller/Applepay/GetShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,31 +37,31 @@ class GetShippingMethods extends AbstractApplepay
/**
* @var QuoteService
*/
private $quoteService;
private QuoteService $quoteService;

/**
* @var ApplePayFormatData
*/
private $applePayFormatData;
private ApplePayFormatData $applePayFormatData;

/**
* @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;
Expand All @@ -75,7 +75,12 @@ public function __construct(
public function execute()
{
$postValues = $this->getParams();
$this->logging->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;
Expand Down Expand Up @@ -114,15 +119,15 @@ public function execute()
'totals' => $totals
];
} catch (\Exception $exception) {
$this->logging->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);
Expand Down
49 changes: 30 additions & 19 deletions Controller/Applepay/SaveOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -133,7 +133,7 @@ public function __construct(
parent::__construct(
$resultJsonFactory,
$request,
$logging
$logger
);

$this->quoteManagement = $quoteManagement;
Expand Down Expand Up @@ -167,9 +167,11 @@ 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(sprintf(
'[ApplePay] | [Controller] | [%s:%s] - Save Order | request: %s',
__METHOD__, __LINE__,
var_export($isPost, true)
));

// Get Cart
$quote = $this->checkoutSession->getQuote();
Expand Down Expand Up @@ -202,8 +204,6 @@ public function execute()
*/
private function submitQuote($quote, $extra)
{
$this->logging->addDebug(__METHOD__ . '|2|');

try {
if (!($this->customerSession->getCustomer() && $this->customerSession->getCustomer()->getId())) {
$quote->setCheckoutMethod('guest')
Expand All @@ -222,7 +222,11 @@ private function submitQuote($quote, $extra)

$this->quoteManagement->submit($quote);
} catch (\Throwable $th) {
$this->logging->addDebug(__METHOD__ . '|exception|' . var_export($th->getMessage(), true));
$this->logger->addError(sprintf(
'[ApplePay] | [Controller] | [%s:%s] - Submit Quote | [ERROR]: %s',
__METHOD__, __LINE__,
$th->getMessage()
));
}
}

Expand All @@ -236,20 +240,22 @@ 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(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->logging->addDebug(__METHOD__ . '|5|');
$data = [
'RequiredAction' => $data->RequiredAction
];
} else {
//live mode
$this->logging->addDebug(__METHOD__ . '|6|');
if (isset($data['Status']['Code']['Code']) && $data['Status']['Code']['Code'] == '190'
&& isset($data['Order'])
) {
$this->processBuckarooResponse($data);
$data = $this->processBuckarooResponse($data);
}
}
}
Expand All @@ -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()) {
Expand All @@ -279,12 +284,18 @@ 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(sprintf(
'[ApplePay] | [Controller] | [%s:%s] - Save Order - Redirect URL | redirectURL: %s',
__METHOD__, __LINE__,
$url
));
$data = [
'RequiredAction' => [
'RedirectURL' => $url
]
];
}

return $data;
}
}
8 changes: 4 additions & 4 deletions Controller/Applepay/UpdateShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 0596b9d

Please sign in to comment.