diff --git a/src/Controller/Admin/PayPalConfigController.php b/src/Controller/Admin/PayPalConfigController.php index ca61dca1d..ea34d5ba8 100644 --- a/src/Controller/Admin/PayPalConfigController.php +++ b/src/Controller/Admin/PayPalConfigController.php @@ -209,7 +209,11 @@ protected function checkEligibility(): void /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error("Error on checkEligibility", [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error("Error on checkEligibility", [$exception]); + } } } @@ -346,7 +350,11 @@ public function autoConfigurationFromCallback() PayPalSession::storeOnboardingPayload($requestReader->getRawPost()); } catch (\Exception $exception) { $logger = $this->getServiceFromContainer(LoggerInterface::class); - $logger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } } $result = []; @@ -391,7 +399,11 @@ protected function autoConfiguration(): array } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } } return $credentials; } @@ -412,7 +424,11 @@ protected function registerWebhooks(): string } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } } return $webhookId; diff --git a/src/Controller/Admin/PayPalOrderController.php b/src/Controller/Admin/PayPalOrderController.php index 9b7336f6d..bcbf0ca97 100644 --- a/src/Controller/Admin/PayPalOrderController.php +++ b/src/Controller/Admin/PayPalOrderController.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; @@ -97,7 +98,11 @@ public function executeFunction($functionName) /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage()); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage()); + } } } @@ -160,7 +165,11 @@ public function render() $this->addTplParam('error', $lang->translateString('OSC_PAYPAL_ERROR_' . $exception->getErrorIssue())); /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage()); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage()); + } } } elseif ( $order->getFieldData('oxpaymenttype') == $this->payPalPlusPaymentType && diff --git a/src/Controller/OrderController.php b/src/Controller/OrderController.php index 6f200668f..40a3ffe07 100644 --- a/src/Controller/OrderController.php +++ b/src/Controller/OrderController.php @@ -9,6 +9,7 @@ use OxidEsales\Eshop\Core\DisplayError; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; @@ -147,7 +148,11 @@ public function createAcdcOrder(): void } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } $this->outputJson(['acdcerror' => 'failed to execute shop order']); return; } @@ -183,12 +188,17 @@ public function captureAcdcOrder(): void $sessionAcdcOrderId = (string) PayPalSession::getCheckoutOrderId(); $acdcStatus = Registry::getSession()->getVariable(Constants::SESSION_ACDC_PAYPALORDER_STATUS); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ( 'COMPLETED' === $acdcStatus && $sessionOrderId && $sessionAcdcOrderId ) { - $logger->debug('captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug('captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId); + } $result = [ 'location' => [ @@ -234,7 +244,9 @@ public function captureAcdcOrder(): void //track status in session Registry::getSession()->setVariable(Constants::SESSION_ACDC_PAYPALORDER_STATUS, $response->status); } catch (\Exception $exception) { - $logger->debug($exception->getMessage(), [$exception]); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug($exception->getMessage(), [$exception]); + } $this->getServiceFromContainer(PaymentService::class)->removeTemporaryOrder(); } @@ -275,10 +287,14 @@ public function finalizepaypalsession(): string } catch (PayPalException $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->debug( - 'PayPal Checkout error during order finalization ' . $exception->getMessage(), - [$exception] - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug( + 'PayPal Checkout error during order finalization ' . $exception->getMessage(), + [$exception] + ); + } $this->cancelpaypalsession('cannot finalize order'); return 'payment?payerror=2'; } @@ -301,10 +317,14 @@ public function finalizeacdc(): string } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error( - 'failure during finalizeOrderAfterExternalPayment', - [$exception] - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error( + 'failure during finalizeOrderAfterExternalPayment', + [$exception] + ); + } $this->cancelpaypalsession('cannot finalize order'); $goNext = 'payment?payerror=2'; } diff --git a/src/Controller/ProxyController.php b/src/Controller/ProxyController.php index c445ab995..bf297922e 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -94,7 +94,11 @@ public function approveOrder() } catch (Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error("Error on order capture call.", [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error("Error on order capture call.", [$exception]); + } } if (!$this->getUser()) { diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index bab8ea42a..19ac0ce8e 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -9,6 +9,7 @@ use OxidEsales\Eshop\Application\Component\Widget\WidgetController; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher; @@ -33,19 +34,25 @@ public function init() /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); try { $requestReader = new RequestReader(); $verificationService = Registry::get(EventVerifier::class); $dispatcher = Registry::get(EventDispatcher::class); - $logger->debug('PayPal Webhook request ' . $requestReader->getRawPost()); - $logger->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug('PayPal Webhook request ' . $requestReader->getRawPost()); + $logger->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); + } $webhookRequestHandler = new WebhookRequestHandler($requestReader, $verificationService, $dispatcher); $webhookRequestHandler->process(); } catch (\Exception $exception) { - $logger->error($exception->getMessage(), [$exception]); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } $this->sendErrorResponse(); } //We need to return a 200 if the call could be processed successfully, the otherwise webhook event diff --git a/src/Core/Config.php b/src/Core/Config.php index 7d88fb9fd..8adad2c60 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -368,4 +368,17 @@ public function getClientSandboxUrl(): string { return Client::SANDBOX_URL; } + + public function isLogLevel(string $level): bool + { + $possiblePayPalLevels = [ + 'error' => 400, + 'info' => 200, + 'debug' => 100 + ]; + $logLevel = Registry::getConfig()->getConfigParam('sLogLevel') ?? 'error'; + $logLevel = isset($possiblePayPalLevels[$logLevel]) ? $logLevel : 'error'; + $level = isset($possiblePayPalLevels[$level]) ? $level : 'error'; + return $possiblePayPalLevels[$logLevel] <= $possiblePayPalLevels[$level]; + } } diff --git a/src/Core/Onboarding/Onboarding.php b/src/Core/Onboarding/Onboarding.php index 616d71e63..286f192d2 100644 --- a/src/Core/Onboarding/Onboarding.php +++ b/src/Core/Onboarding/Onboarding.php @@ -59,7 +59,11 @@ public function fetchCredentials(): array } catch (ApiException $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage(), [$exception]); + /** @var PayPalConfig $payPalConfig */ + $payPalConfig = oxNew(PayPalConfig::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } } return $credentials; diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index 86a8244c3..0821725fb 100644 --- a/src/Core/Onboarding/Webhook.php +++ b/src/Core/Onboarding/Webhook.php @@ -71,10 +71,14 @@ public function registerWebhooks(): string } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error( - 'PayPal Webhook creation failed: ' . $exception->getMessage(), - [$exception] - ); + /** @var PayPalConfig $payPalConfig */ + $payPalConfig = oxNew(PayPalConfig::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error( + 'PayPal Webhook creation failed: ' . $exception->getMessage(), + [$exception] + ); + } } return $webhookId; diff --git a/src/Core/Tracker/Tracker.php b/src/Core/Tracker/Tracker.php index 10405ca37..c83731571 100644 --- a/src/Core/Tracker/Tracker.php +++ b/src/Core/Tracker/Tracker.php @@ -8,6 +8,7 @@ namespace OxidSolutionCatalysts\PayPal\Core\Tracker; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; @@ -55,10 +56,14 @@ public function sendtracking( } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error( - 'PayPal sending Tracker failed: ' . $exception->getMessage(), - [$exception] - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error( + 'PayPal sending Tracker failed: ' . $exception->getMessage(), + [$exception] + ); + } } return $result; diff --git a/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php b/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php index 3aa004666..46eaedeed 100644 --- a/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php +++ b/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php @@ -9,6 +9,7 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalModelOrder; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; @@ -42,11 +43,15 @@ public function handleWebhookTasks( } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->debug( - "Error during " . self::WEBHOOK_EVENT_NAME . " for PayPal order_id '" . - $payPalOrderId . "'", - [$exception] - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug( + "Error during " . self::WEBHOOK_EVENT_NAME . " for PayPal order_id '" . + $payPalOrderId . "'", + [$exception] + ); + } } } } diff --git a/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php b/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php index 5e1948dc4..42c5a4658 100644 --- a/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php +++ b/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php @@ -8,6 +8,7 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook\Handler; use OxidEsales\EshopCommunity\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; @@ -47,10 +48,14 @@ protected function getPayPalOrderDetails(string $payPalOrderId): ?PayPalApiModel } catch (ApiException $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->debug( - 'Exception during PaymentCaptureCompletedHandler::getPayPalOrderDetails().', - [$exception] - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug( + 'Exception during PaymentCaptureCompletedHandler::getPayPalOrderDetails().', + [$exception] + ); + } } return $apiOrder; diff --git a/src/Core/Webhook/Handler/WebhookHandlerBase.php b/src/Core/Webhook/Handler/WebhookHandlerBase.php index 33cd8c052..4dd68ce58 100644 --- a/src/Core/Webhook/Handler/WebhookHandlerBase.php +++ b/src/Core/Webhook/Handler/WebhookHandlerBase.php @@ -9,6 +9,7 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook\Handler; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\Webhook\Event; use OxidSolutionCatalysts\PayPal\Exception\NotFound; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventException; @@ -61,11 +62,15 @@ public function handle(Event $event): void } else { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->debug( - "Not enough information to handle " . static::WEBHOOK_EVENT_NAME . - " with PayPal order_id '" . $payPalOrderId . "' and PayPal transaction id '" . - $payPalTransactionId . "'" - ); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + $logger->debug( + "Not enough information to handle " . static::WEBHOOK_EVENT_NAME . + " with PayPal order_id '" . $payPalOrderId . "' and PayPal transaction id '" . + $payPalTransactionId . "'" + ); + } } //Webhook is used to trigger unfinished order cleanup at the end of each webhook handle. diff --git a/src/Core/Webhook/RequestHandler.php b/src/Core/Webhook/RequestHandler.php index a70de9878..1238b993b 100644 --- a/src/Core/Webhook/RequestHandler.php +++ b/src/Core/Webhook/RequestHandler.php @@ -10,6 +10,7 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook; use JsonException; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier as VerificationService; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher as WebhookDispatcher; @@ -47,6 +48,8 @@ public function process(): bool $result = false; /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); try { $requestBody = $this->requestReader->getRawPost(); @@ -58,11 +61,15 @@ public function process(): bool $result = true; } catch (WebhookEventException | WebhookEventTypeException $exception) { - //we could not handle the call and don't want to receive it again, log and be done - $logger->error($exception->getMessage(), [$exception]); + if ($payPalConfig->isLogLevel('error')) { + //we could not handle the call and don't want to receive it again, log and be done + $logger->error($exception->getMessage(), [$exception]); + } } catch (ApiException $exception) { - //we could not handle the call but want to retry, so log and rethrow - $logger->error($exception->getMessage(), [$exception]); + if ($payPalConfig->isLogLevel('error')) { + //we could not handle the call but want to retry, so log and rethrow + $logger->error($exception->getMessage(), [$exception]); + } throw $exception; } diff --git a/src/Model/Order.php b/src/Model/Order.php index 3ead5543e..dc69fb259 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -10,6 +10,7 @@ namespace OxidSolutionCatalysts\PayPal\Model; use DateTimeImmutable; +use Exception; use OxidEsales\Eshop\Application\Model\Basket; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\UserPayment; @@ -17,6 +18,7 @@ use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Model\BaseModel; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config as PayPalConfig; use OxidSolutionCatalysts\PayPal\Core\Tracker\Tracker; use OxidSolutionCatalysts\PayPal\Exception\PayPalException; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; @@ -287,11 +289,15 @@ protected function _executePayment(Basket $basket, $userpayment) PayPalSession::setSessionRedirectLink($redirectLink); return self::ORDER_STATE_SESSIONPAYMENT_INPROGRESS; - } catch (\Exception $exception) { + } catch (Exception $exception) { $this->delete(); /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error($exception->getMessage(), [$exception]); + /** @var PayPalConfig $payPalConfig */ + $payPalConfig = oxNew(PayPalConfig::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error($exception->getMessage(), [$exception]); + } } return self::ORDER_STATE_PAYMENTERROR; } elseif ($isPayPalACDC) { @@ -340,10 +346,14 @@ protected function doExecutePayPalPayment($payPalOrderId): bool $order = $paymentService->doCapturePayPalOrder($this, $payPalOrderId, $sessionPaymentId); // success means at this point, that we triggered the capture without errors $success = true; - } catch (\Exception $exception) { + } catch (Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); - $logger->error("Error on order capture call.", [$exception]); + /** @var PayPalConfig $payPalConfig */ + $payPalConfig = oxNew(PayPalConfig::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error("Error on order capture call.", [$exception]); + } } // destroy PayPal-Session diff --git a/src/Model/PaymentGateway.php b/src/Model/PaymentGateway.php index 16ac511c1..e6cc65923 100644 --- a/src/Model/PaymentGateway.php +++ b/src/Model/PaymentGateway.php @@ -9,6 +9,7 @@ use Exception; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; @@ -65,14 +66,18 @@ protected function doExecutePayPalExpressPayment(EshopModelOrder $order): bool $sessionPaymentId = (string) $paymentService->getSessionPaymentId(); $success = false; - /** @var LoggerInterface $logger */ - $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); if ($checkoutOrderId = PayPalSession::getCheckoutOrderId()) { // Update Order try { $paymentService->doPatchPayPalOrder(Registry::getSession()->getBasket(), $checkoutOrderId); } catch (Exception $exception) { - $logger->error("Error on order patch call.", [$exception]); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $logger->error("Error on order patch call.", [$exception]); + } } // Capture Order diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index 2086bc6cc..8d6e5f5d6 100644 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -18,6 +18,7 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleSettingNotFountException; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Module; @@ -399,14 +400,21 @@ public function saveClientSecret(string $clientSecret): void public function saveMerchantId(string $merchantId, ?bool $isSandbox = null): void { $isSandbox = !is_null($isSandbox) ? $isSandbox : $this->isSandbox(); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($isSandbox) { $this->save('oscPayPalSandboxClientMerchantId', $merchantId); - $this->moduleLogger->info(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); + if ($payPalConfig->isLogLevel('debug')) { + $this->moduleLogger->debug(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); + } } if (!$isSandbox) { $this->save('oscPayPalClientMerchantId', $merchantId); - $this->moduleLogger->info(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); + if ($payPalConfig->isLogLevel('debug')) { + $this->moduleLogger->debug(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); + } } } diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 5309d188e..d1dcf5da5 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -13,6 +13,7 @@ use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Session as EshopSession; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Core\ConfirmOrderRequestFactory; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\OrderRequestFactory; @@ -122,6 +123,8 @@ public function doCreatePayPalOrder( /** @var ApiOrderService $orderService */ $orderService = $this->serviceFactory->getOrderService(); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); $request = $this->orderRequestFactory->getRequest( $basket, @@ -148,11 +151,17 @@ public function doCreatePayPalOrder( $payPalRequestId ); } catch (ApiException $exception) { - $this->moduleLogger->error("Api error on order create call. " . - $exception->getErrorIssue(), [$exception]); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error( + "Api error on order create call. " . $exception->getErrorIssue(), + [$exception] + ); + } $this->handlePayPalApiError($exception); } catch (Exception $exception) { - $this->moduleLogger->error("Error on order create call.", [$exception]); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error("Error on order create call.", [$exception]); + } $this->setPaymentExecutionError(self::PAYMENT_ERROR_GENERIC); } @@ -217,7 +226,11 @@ public function doPatchPayPalOrder( Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP ); } catch (Exception $exception) { - $this->moduleLogger->error("Error on order patch call.", [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error("Error on order patch call.", [$exception]); + } throw $exception; } } @@ -300,8 +313,11 @@ public function doCapturePayPalOrder( $issue = $exception->getErrorIssue(); $this->displayErrorIfInstrumentDeclined($issue); - - $this->moduleLogger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error($exception->getMessage(), [$exception]); + } throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -323,8 +339,11 @@ public function doCapturePayPalOrder( $issue = $exception->getErrorIssue(); $this->displayErrorIfInstrumentDeclined($issue); - - $this->moduleLogger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error($exception->getMessage(), [$exception]); + } throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } } @@ -350,8 +369,12 @@ public function doCapturePayPalOrder( $order->setTransId((string)$payPalTransactionId); } } catch (Exception $exception) { - //Webhook might try to capture already captured order - $this->moduleLogger->debug("Error on order capture call.", [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + //Webhook might try to capture already captured order + $this->moduleLogger->debug("Warning on order capture call.", [$exception]); + } throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -443,7 +466,11 @@ public function removeTemporaryOrder(): void if ($orderModel->isLoaded()) { if ($orderModel->hasOrderNumber()) { - $this->moduleLogger->info('Cannot delete valid order with id ' . $sessionOrderId); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('debug')) { + $this->moduleLogger->debug('Cannot delete valid order with id ' . $sessionOrderId); + } } else { $orderModel->delete(); } @@ -498,8 +525,12 @@ public function doExecuteUAPMPayment(EshopModelOrder $order, EshopModelBasket $b } catch (Exception $exception) { PayPalSession::unsetPayPalOrderId(); $this->removeTemporaryOrder(); - //TODO: do we need to log this? - $this->moduleLogger->error($exception->getMessage(), [$exception]); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); + if ($payPalConfig->isLogLevel('error')) { + //TODO: do we need to log this? + $this->moduleLogger->error($exception->getMessage(), [$exception]); + } } //NOTE: payment not fully executed, we need customer interaction first @@ -590,6 +621,8 @@ public function doExecutePuiPayment( string $payPalClientMetadataId = '' ): bool { $this->setPaymentExecutionError(self::PAYMENT_ERROR_NONE); + /** @var Config $payPalConfig */ + $payPalConfig = oxNew(Config::class); try { $result = $this->doCreatePayPalOrder( @@ -608,12 +641,16 @@ public function doExecutePuiPayment( $this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_PHONE); } catch (Exception $exception) { $this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_GENERIC); - $this->moduleLogger->error("Error on pui order creation call.", [$exception]); + if ($payPalConfig->isLogLevel('error')) { + $this->moduleLogger->error("Error on pui order creation call.", [$exception]); + } } # TODO: check what we created, ensure it is a pui order # $paymentSource = $this->fetchOrderFields((string) $payPalOrderId, 'payment_source'); + # if ($payPalConfig->isLogLevel('error')) { # $this->moduleLogger->error(serialize($paymentSource)); + # } if (!$payPalOrderId) { return false;