From ed6614944975395732c7e172d9af5cfcecfa588e Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 22 Sep 2023 17:36:17 +0200 Subject: [PATCH 1/7] Fix missing ConfigurationDaoBridge --- src/Core/Events/Events.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Core/Events/Events.php b/src/Core/Events/Events.php index ec02fd419..5f7294c34 100644 --- a/src/Core/Events/Events.php +++ b/src/Core/Events/Events.php @@ -13,6 +13,7 @@ use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Application\Model\Payment as EshopModelPayment; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; @@ -160,10 +161,13 @@ private static function getModuleSettingsService(): ModuleSettings $moduleSettingsBridge = $container->get(ModuleSettingBridgeInterface::class); /** @var ContextInterface $context */ $context = $container->get(ContextInterface::class); + /** @var ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface */ + $moduleConfigurationDaoBridgeInterface = $container->get(ModuleConfigurationDaoBridgeInterface::class); return new ModuleSettings( $moduleSettingsBridge, - $context + $context, + $moduleConfigurationDaoBridgeInterface ); } } From a291880d5ccab3b7455c1d2e35caa3c34715e8d7 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 22 Sep 2023 21:19:38 +0200 Subject: [PATCH 2/7] WIP: Change Logger to Service --- services.yaml | 39 ++++++++++++++- .../Admin/PayPalConfigController.php | 17 +++++-- .../Admin/PayPalOrderController.php | 10 ++-- src/Controller/OrderController.php | 30 +++++++++--- src/Controller/ProxyController.php | 5 +- src/Controller/WebhookController.php | 15 ++++-- src/Core/Onboarding/Onboarding.php | 13 +++-- src/Core/Onboarding/Webhook.php | 8 +++- src/Core/ServiceFactory.php | 8 +++- src/Core/Tracker/Tracker.php | 8 +++- .../Handler/CheckoutOrderApprovedHandler.php | 9 +++- .../PaymentCaptureCompletedHandler.php | 8 +++- .../Webhook/Handler/WebhookHandlerBase.php | 9 +++- src/Core/Webhook/RequestHandler.php | 12 +++-- src/Model/Order.php | 10 +++- src/Model/PaymentGateway.php | 12 +++-- src/Service/ModuleSettings.php | 16 +++++-- src/Service/PayPalLogger.php | 48 +++++++++++++++++++ src/Service/Payment.php | 36 ++++++++++---- 19 files changed, 264 insertions(+), 49 deletions(-) create mode 100644 src/Service/PayPalLogger.php diff --git a/services.yaml b/services.yaml index d4593e8c5..f4c3f9a66 100644 --- a/services.yaml +++ b/services.yaml @@ -22,11 +22,48 @@ services: OxidEsales\Eshop\Core\Request: factory: [ '@OxidEsales\Eshop\Core\Registry', 'getRequest' ] + OxidSolutionCatalysts\PayPal\Logger: + class: Monolog\Logger + factory: ['@OxidSolutionCatalysts\PayPal\Logger\Factory', 'create'] + public: true + + OxidSolutionCatalysts\PayPal\Logger\Factory: + class: OxidEsales\EshopCommunity\Internal\Framework\Logger\Factory\MonologLoggerFactory + public: true + arguments: + $configuration: '@OxidSolutionCatalysts\PayPal\Logger\Configuration' + + OxidSolutionCatalysts\PayPal\Logger\Configuration: + class: OxidEsales\EshopCommunity\Internal\Framework\Logger\Configuration\MonologConfiguration + public: true + arguments: + $loggerName: 'PayPal Payment Logger' + $logFilePath: '@=service("OxidSolutionCatalysts\\PayPal\\Service\\PayPalLogger").getPayPalLogFilePath()' + $logLevel: !php/const Psr\Log\LogLevel::INFO + + OxidSolutionCatalysts\PayPal\Service\PayPalLogger: + class: OxidSolutionCatalysts\PayPal\Service\PayPalLogger + public: true + arguments: + $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' + + OxidSolutionCatalysts\PayPal\Service\Payment: + class: OxidSolutionCatalysts\PayPal\Service\Payment + public: true + arguments: + $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' + + OxidSolutionCatalysts\PayPal\Service\ModuleSettings: + class: OxidSolutionCatalysts\PayPal\Service\ModuleSettings + public: true + arguments: + $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' + OxidSolutionCatalysts\PayPal\Service\: resource: 'src/Service/*' + exclude: ['src/Service/{PayPalLogger}','src/Service/{Payment}','src/Service/{ModuleSettings}'] public: true OxidSolutionCatalysts\PayPal\Service\SCAValidatorInterface: class: OxidSolutionCatalysts\PayPal\Service\SCAValidator public: true - diff --git a/src/Controller/Admin/PayPalConfigController.php b/src/Controller/Admin/PayPalConfigController.php index 8ed9f196f..f2f0d5f62 100644 --- a/src/Controller/Admin/PayPalConfigController.php +++ b/src/Controller/Admin/PayPalConfigController.php @@ -21,6 +21,7 @@ use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; /** @@ -204,7 +205,9 @@ protected function checkEligibility(): void $merchantInformations = $onBoardingClient->getMerchantInformations(); $handler->saveEligibility($merchantInformations); } catch (ClientException $exception) { - Registry::getLogger()->error("Error on checkEligibility", [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error("Error on checkEligibility", [$exception]); + //Registry::getLogger()->error("Error on checkEligibility", [$exception]); } } @@ -339,7 +342,9 @@ public function autoConfigurationFromCallback() $requestReader = oxNew(RequestReader::class); PayPalSession::storeOnboardingPayload($requestReader->getRawPost()); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } $result = []; @@ -382,7 +387,9 @@ protected function autoConfiguration(): array $handler = oxNew(Onboarding::class); $credentials = $handler->autoConfigurationFromCallback(); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $credentials; } @@ -401,7 +408,9 @@ protected function registerWebhooks(): string } catch (OnboardingException $exception) { Registry::getUtilsView()->addErrorToDisplay($exception->getMessage()); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $webhookId; diff --git a/src/Controller/Admin/PayPalOrderController.php b/src/Controller/Admin/PayPalOrderController.php index b27e142f0..92625da97 100644 --- a/src/Controller/Admin/PayPalOrderController.php +++ b/src/Controller/Admin/PayPalOrderController.php @@ -12,11 +12,11 @@ use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\Constants; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as ApiOrderModel; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalOrder; -use OxidSolutionCatalysts\PayPalApi\Model\Orders\OrderCaptureRequest; use OxidSolutionCatalysts\PayPalApi\Model\Payments\Refund; use OxidSolutionCatalysts\PayPalApi\Model\Payments\RefundRequest; use OxidSolutionCatalysts\PayPalApi\Service\Payments; @@ -94,7 +94,9 @@ public function executeFunction($functionName) parent::executeFunction($functionName); } catch (ApiException $exception) { $this->addTplParam('error', $exception->getErrorDescription()); - Registry::getLogger()->error($exception->getMessage()); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage()); + //Registry::getLogger()->error($exception->getMessage()); } } @@ -155,7 +157,9 @@ public function render() } } catch (ApiException $exception) { $this->addTplParam('error', $lang->translateString('OSC_PAYPAL_ERROR_' . $exception->getErrorIssue())); - Registry::getLogger()->error($exception->getMessage()); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage()); + //Registry::getLogger()->error($exception->getMessage()); } } elseif ( $order->getFieldData('oxpaymenttype') == $this->payPalPlusPaymentType && diff --git a/src/Controller/OrderController.php b/src/Controller/OrderController.php index 99f86a850..4e6b5dac0 100644 --- a/src/Controller/OrderController.php +++ b/src/Controller/OrderController.php @@ -14,6 +14,7 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; use OxidSolutionCatalysts\PayPal\Exception\RedirectWithMessage; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\JsonTrait; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; @@ -144,7 +145,9 @@ public function createAcdcOrder(): void $status = $this->execute(); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); $this->outputJson(['acdcerror' => 'failed to execute shop order']); return; } @@ -173,6 +176,7 @@ public function createAcdcOrder(): void public function captureAcdcOrder(): void { + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); $acdcRequestId = (string) Registry::getRequest()->getRequestParameter('acdcorderid'); $sessionOrderId = (string) Registry::getSession()->getVariable('sess_challenge'); $sessionAcdcOrderId = (string) PayPalSession::getCheckoutOrderId(); @@ -183,9 +187,10 @@ public function captureAcdcOrder(): void $sessionOrderId && $sessionAcdcOrderId ) { - Registry::getLogger()->debug( - 'captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId - ); + $logger->debug('captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId); + //Registry::getLogger()->debug( + // 'captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId + //); $result = [ 'location' => [ @@ -231,7 +236,8 @@ public function captureAcdcOrder(): void //track status in session Registry::getSession()->setVariable(Constants::SESSION_ACDC_PAYPALORDER_STATUS, $response->status); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger->debug($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); $this->getServiceFromContainer(PaymentService::class)->removeTemporaryOrder(); } @@ -270,10 +276,15 @@ public function finalizepaypalsession(): string $order->finalizeOrderAfterExternalPayment($sessionCheckoutOrderId); $order->save(); } catch (PayPalException $exception) { - Registry::getLogger()->debug( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->debug( 'PayPal Checkout error during order finalization ' . $exception->getMessage(), [$exception] ); + //Registry::getLogger()->debug( + // 'PayPal Checkout error during order finalization ' . $exception->getMessage(), + // [$exception] + //); $this->cancelpaypalsession('cannot finalize order'); return 'payment?payerror=2'; } @@ -294,7 +305,12 @@ public function finalizeacdc(): string $order->finalizeOrderAfterExternalPayment($sessionAcdcOrderId, $forceFetchDetails); $goNext = 'thankyou'; } catch (\Exception $exception) { - Registry::getLogger()->error('failure during finalizeOrderAfterExternalPayment', [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error( + 'failure during finalizeOrderAfterExternalPayment', + [$exception] + ); + //Registry::getLogger()->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 6fac6b546..096040b23 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -19,6 +19,7 @@ use OxidEsales\Eshop\Core\Exception\StandardException; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\UserRepository; use OxidSolutionCatalysts\PayPal\Core\Config; @@ -91,7 +92,9 @@ public function approveOrder() try { $response = $service->showOrderDetails($orderId, ''); } catch (Exception $exception) { - Registry::getLogger()->error("Error on order capture call.", [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error("Error on order capture call.", [$exception]); + //Registry::getLogger()->error("Error on order capture call.", [$exception]); } if (!$this->getUser()) { diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 0f54ff18f..9b2b602bd 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -13,6 +13,8 @@ use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher; use OxidSolutionCatalysts\PayPal\Core\Webhook\RequestHandler as WebhookRequestHandler; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; +use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; /** * Class WebhookController @@ -20,6 +22,8 @@ */ class WebhookController extends WidgetController { + use ServiceContainer; + /** * @inheritDoc */ @@ -27,18 +31,23 @@ public function init() { parent::init(); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + try { $requestReader = new RequestReader(); $verificationService = Registry::get(EventVerifier::class); $dispatcher = Registry::get(EventDispatcher::class); - Registry::getLogger()->debug('PayPal Webhook request ' . $requestReader->getRawPost()); - Registry::getLogger()->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); + $logger->debug('PayPal Webhook request ' . $requestReader->getRawPost()); + //Registry::getLogger()->debug('PayPal Webhook request ' . $requestReader->getRawPost()); + $logger->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); + //Registry::getLogger()->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); $webhookRequestHandler = new WebhookRequestHandler($requestReader, $verificationService, $dispatcher); $success = $webhookRequestHandler->process(); } catch (\Exception $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->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/Onboarding/Onboarding.php b/src/Core/Onboarding/Onboarding.php index ce6248dab..4afb8dec6 100644 --- a/src/Core/Onboarding/Onboarding.php +++ b/src/Core/Onboarding/Onboarding.php @@ -11,8 +11,10 @@ use OxidSolutionCatalysts\PayPal\Core\Config as PayPalConfig; use OxidSolutionCatalysts\PayPal\Core\PartnerConfig; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; +use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Onboarding as ApiOnboardingClient; @@ -56,7 +58,9 @@ public function fetchCredentials(): array $credentials = $apiClient->getCredentials(); } catch (ApiException $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $credentials; @@ -118,7 +122,8 @@ public function getOnboardingClient(bool $isSandbox, bool $withCredentials = fal } return new ApiOnboardingClient( - Registry::getLogger(), + //Registry::getLogger(), + $this->getServiceFromContainer(PayPalLogger::class)->getLogger(), $isSandbox ? $paypalConfig->getClientSandboxUrl() : $paypalConfig->getClientLiveUrl(), $clientId, $clientSecret, @@ -136,7 +141,9 @@ public function fetchMerchantInformations() $apiClient = $this->getOnboardingClient($onboardingResponse['isSandBox'], true); $merchantInformations = $apiClient->getMerchantInformations(); } catch (ApiException $exception) { - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $merchantInformations; } diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index ea6ddeadc..d84a442bb 100644 --- a/src/Core/Onboarding/Webhook.php +++ b/src/Core/Onboarding/Webhook.php @@ -11,6 +11,7 @@ use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventHandlerMapping; use OxidSolutionCatalysts\PayPal\Core\Config as PayPalConfig; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; @@ -68,10 +69,15 @@ public function registerWebhooks(): string $webhookId = $webHookResponse['id'] ?? ''; } catch (\Exception $exception) { - Registry::getLogger()->error( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error( 'PayPal Webhook creation failed: ' . $exception->getMessage(), [$exception] ); + //Registry::getLogger()->error( + // 'PayPal Webhook creation failed: ' . $exception->getMessage(), + // [$exception] + //); } return $webhookId; diff --git a/src/Core/ServiceFactory.php b/src/Core/ServiceFactory.php index dcfd9aabe..4dbe55c2e 100644 --- a/src/Core/ServiceFactory.php +++ b/src/Core/ServiceFactory.php @@ -10,6 +10,8 @@ namespace OxidSolutionCatalysts\PayPal\Core; use OxidEsales\Eshop\Core\Registry; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; +use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Client; use OxidSolutionCatalysts\PayPalApi\Service\Partner; use OxidSolutionCatalysts\PayPalApi\Service\Catalog; @@ -26,6 +28,8 @@ */ class ServiceFactory { + use ServiceContainer; + /** * @var Client */ @@ -115,9 +119,11 @@ private function getClient(): Client if ($this->client === null) { /** @var Config $config */ $config = oxNew(Config::class); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); $client = new Client( - Registry::getLogger(), + //Registry::getLogger(), + $logger, $config->isSandbox() ? Client::SANDBOX_URL : Client::PRODUCTION_URL, $config->getClientId(), $config->getClientSecret(), diff --git a/src/Core/Tracker/Tracker.php b/src/Core/Tracker/Tracker.php index 06ca0656e..efd4750d3 100644 --- a/src/Core/Tracker/Tracker.php +++ b/src/Core/Tracker/Tracker.php @@ -9,6 +9,7 @@ use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; @@ -52,10 +53,15 @@ public function sendtracking( $result = $trackerResponse['tracker_identifiers'][0]['tracking_number'] === $trackingNumber; } catch (\Exception $exception) { - Registry::getLogger()->error( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error( 'PayPal sending Tracker failed: ' . $exception->getMessage(), [$exception] ); + //Registry::getLogger()->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 81db39bbb..af80e6ff2 100644 --- a/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php +++ b/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php @@ -10,6 +10,7 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalModelOrder; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as OrderResponse; @@ -39,11 +40,17 @@ public function handleWebhookTasks( ); $order->setOrderNumber(); //ensure the order has a number } catch (\Exception $exception) { - Registry::getLogger()->debug( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->debug( "Error during " . self::WEBHOOK_EVENT_NAME . " for PayPal order_id '" . $payPalOrderId . "'", [$exception] ); + //Registry::getLogger()->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 dd8846fa8..c78fc6ec0 100644 --- a/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php +++ b/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php @@ -10,6 +10,7 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\EshopCommunity\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; @@ -46,10 +47,15 @@ protected function getPayPalOrderDetails(string $payPalOrderId): ?PayPalApiModel ->getOrderService() ->showOrderDetails($payPalOrderId, ''); } catch (ApiException $exception) { - Registry::getLogger()->debug( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->debug( 'Exception during PaymentCaptureCompletedHandler::getPayPalOrderDetails().', [$exception] ); + //Registry::getLogger()->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 a07ce83b2..20d3b9a94 100644 --- a/src/Core/Webhook/Handler/WebhookHandlerBase.php +++ b/src/Core/Webhook/Handler/WebhookHandlerBase.php @@ -16,6 +16,7 @@ use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalModelOrder; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; @@ -59,11 +60,17 @@ public function handle(Event $event): void $order ); } else { - Registry::getLogger()->debug( + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->debug( "Not enough information to handle " . static::WEBHOOK_EVENT_NAME . " with PayPal order_id '" . $payPalOrderId . "' and PayPal transaction id '" . $payPalTransactionId . "'" ); + //Registry::getLogger()->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 853d9bee4..c5fa208f8 100644 --- a/src/Core/Webhook/RequestHandler.php +++ b/src/Core/Webhook/RequestHandler.php @@ -9,16 +9,19 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook; -use OxidEsales\Eshop\Core\Registry as EshopRegistry; use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier as VerificationService; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher as WebhookDispatcher; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventException; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventTypeException; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; +use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; final class RequestHandler { + use ServiceContainer; + /** @var RequestReader */ private $requestReader; @@ -41,6 +44,7 @@ public function __construct( public function process(): bool { $result = false; + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); try { $requestBody = $this->requestReader->getRawPost(); @@ -53,10 +57,12 @@ 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 - EshopRegistry::getLogger()->error($exception->getMessage(), [$exception]); + $logger->error($exception->getMessage(), [$exception]); + // Registry::getLogger()->error($exception->getMessage(), [$exception]); } catch (ApiException $exception) { //we could not handle the call but want to retry, so log and rethrow - EshopRegistry::getLogger()->error($exception->getMessage(), [$exception]); + $logger->error($exception->getMessage(), [$exception]); + // Registry::getLogger()->error($exception->getMessage(), [$exception]); throw $exception; } diff --git a/src/Model/Order.php b/src/Model/Order.php index 3e2384979..d55a466a9 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -17,9 +17,11 @@ use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Model\BaseModel; use OxidEsales\Eshop\Core\Registry; +use OxidEsales\PayPalModule\Core\Logger; use OxidSolutionCatalysts\PayPal\Core\Tracker\Tracker; use OxidSolutionCatalysts\PayPal\Exception\PayPalException; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiOrder; @@ -288,7 +290,9 @@ protected function _executePayment(Basket $basket, $userpayment) return self::ORDER_STATE_SESSIONPAYMENT_INPROGRESS; } catch (\Exception $exception) { $this->delete(); - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return self::ORDER_STATE_PAYMENTERROR; } elseif ($isPayPalACDC) { @@ -338,7 +342,9 @@ protected function doExecutePayPalPayment($payPalOrderId): bool // success means at this point, that we triggered the capture without errors $success = true; } catch (\Exception $exception) { - Registry::getLogger()->error("Error on order capture call.", [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error("Error on order capture call.", [$exception]); + //Registry::getLogger()->error("Error on order capture call.", [$exception]); } // destroy PayPal-Session diff --git a/src/Model/PaymentGateway.php b/src/Model/PaymentGateway.php index 89ce037ce..bfcf2fbb6 100644 --- a/src/Model/PaymentGateway.php +++ b/src/Model/PaymentGateway.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; +use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; @@ -64,12 +65,14 @@ protected function doExecutePayPalExpressPayment(EshopModelOrder $order): bool $sessionPaymentId = (string) $paymentService->getSessionPaymentId(); $success = false; + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); if ($checkoutOrderId = PayPalSession::getCheckoutOrderId()) { // Update Order try { $paymentService->doPatchPayPalOrder(Registry::getSession()->getBasket(), $checkoutOrderId); } catch (Exception $exception) { - Registry::getLogger()->error("Error on order patch call.", [$exception]); + $logger->error("Error on order patch call.", [$exception]); + //Registry::getLogger()->error("Error on order patch call.", [$exception]); } // Capture Order @@ -80,7 +83,8 @@ protected function doExecutePayPalExpressPayment(EshopModelOrder $order): bool // success means at this point, that we triggered the capture without errors $success = true; } catch (Exception $exception) { - Registry::getLogger()->error("Error on order capture call.", [$exception]); + $logger->error("Error on order capture call.", [$exception]); + //Registry::getLogger()->error("Error on order capture call.", [$exception]); $success = false; } @@ -105,7 +109,9 @@ protected function doExecutePuiPayment(EshopModelOrder $order): bool ); PayPalSession::unsetPayPalPuiCmId(); } catch (Exception $exception) { - Registry::getLogger()->error("Error on execute pui payment call.", [$exception]); + $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger->error("Error on execute pui payment call.", [$exception]); + //Registry::getLogger()->error("Error on execute pui payment call.", [$exception]); } // destroy PayPal-Session PayPalSession::unsetPayPalOrderId(); diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index 1cae0cfaf..c2f944d4b 100644 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -12,7 +12,7 @@ use OxidEsales\Eshop\Application\Model\Country; use OxidEsales\Eshop\Application\Model\Payment; use OxidEsales\Eshop\Application\Model\User; -use OxidEsales\EshopCommunity\Core\Registry; +use OxidEsales\Eshop\Core\Registry; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration; @@ -20,7 +20,9 @@ use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; +use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Module; +use Psr\Log\LoggerInterface; class ModuleSettings { @@ -61,6 +63,8 @@ class ModuleSettings /** @var ContextInterface */ private $context; + private LoggerInterface $moduleLogger; + //TODO: we need service for fetching module settings from db (this one) //another class for moduleconfiguration (database values/edefaults) //and the view configuration should go into some separate class @@ -69,11 +73,13 @@ class ModuleSettings public function __construct( ModuleSettingBridgeInterface $moduleSettingBridge, ContextInterface $context, - ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface + ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface, + LoggerInterface $moduleLogger ) { $this->moduleSettingBridge = $moduleSettingBridge; $this->context = $context; $this->moduleConfigurationDaoBridgeInterface = $moduleConfigurationDaoBridgeInterface; + $this->moduleLogger = $moduleLogger; } public function showAllPayPalBanners(): bool @@ -396,12 +402,14 @@ public function saveMerchantId(string $merchantId, ?bool $isSandbox = null): voi $isSandbox = !is_null($isSandbox) ? $isSandbox : $this->isSandbox(); if ($isSandbox) { $this->save('oscPayPalSandboxClientMerchantId', $merchantId); - Registry::getLogger()->info(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); + $this->moduleLogger->info(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); + //Registry::getLogger()->info(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); } if (!$isSandbox) { $this->save('oscPayPalClientMerchantId', $merchantId); - Registry::getLogger()->info(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); + $this->moduleLogger->info(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); + //Registry::getLogger()->info(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); } } diff --git a/src/Service/PayPalLogger.php b/src/Service/PayPalLogger.php new file mode 100644 index 000000000..03f10ee5d --- /dev/null +++ b/src/Service/PayPalLogger.php @@ -0,0 +1,48 @@ +moduleLogger = $moduleLogger; + } + + public function getLogger(): LoggerInterface + { + return $this->moduleLogger; + } + + /** + * @SuppressWarnings(PHPMD.StaticAccess) + */ + public function getPayPalLogFilePath(): string + { + return Path::join([ + Registry::getConfig()->getLogsDir(), + 'paypal', + $this->getPayPalLogFileName() + ]); + } + + private function getPayPalLogFileName(): string + { + return "paypal_" . date("Y-m-d") . ".log"; + } +} \ No newline at end of file diff --git a/src/Service/Payment.php b/src/Service/Payment.php index ab51f0106..1dbf28bb1 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -37,6 +37,7 @@ use OxidSolutionCatalysts\PayPalApi\Model\Payments\ReauthorizeRequest; use OxidSolutionCatalysts\PayPalApi\Service\Orders as ApiOrderService; use OxidSolutionCatalysts\PayPalApi\Service\Payments as ApiPaymentService; +use Psr\Log\LoggerInterface; class Payment { @@ -79,11 +80,14 @@ class Payment /** @var ModuleSettingsService */ private $moduleSettingsService; + private LoggerInterface $moduleLogger; + public function __construct( EshopSession $eshopSession, OrderRepository $orderRepository, SCAValidatorInterface $scaValidator, ModuleSettingsService $moduleSettingsService, + LoggerInterface $moduleLogger, ServiceFactory $serviceFactory = null, PatchRequestFactory $patchRequestFactory = null, OrderRequestFactory $orderRequestFactory = null @@ -92,6 +96,7 @@ public function __construct( $this->orderRepository = $orderRepository; $this->scaValidator = $scaValidator; $this->moduleSettingsService = $moduleSettingsService; + $this->moduleLogger = $moduleLogger; $this->serviceFactory = $serviceFactory ?: Registry::get(ServiceFactory::class); $this->patchRequestFactory = $patchRequestFactory ?: Registry::get(PatchRequestFactory::class); $this->orderRequestFactory = $orderRequestFactory ?: Registry::get(OrderRequestFactory::class); @@ -144,11 +149,15 @@ public function doCreatePayPalOrder( $payPalRequestId ); } catch (ApiException $exception) { - Registry::getLogger()->error("Api error on order create call. " . + + $this->moduleLogger->error("Api error on order create call. " . $exception->getErrorIssue(), [$exception]); + //Registry::getLogger()->error("Api error on order create call. " . + // $exception->getErrorIssue(), [$exception]); $this->handlePayPalApiError($exception); } catch (Exception $exception) { - Registry::getLogger()->error("Error on order create call.", [$exception]); + $this->moduleLogger->error("Error on order create call.", [$exception]); + //Registry::getLogger()->error("Error on order create call.", [$exception]); $this->setPaymentExecutionError(self::PAYMENT_ERROR_GENERIC); } @@ -209,7 +218,8 @@ public function doPatchPayPalOrder( try { $orderService->updateOrder($checkoutOrderId, $request); } catch (Exception $exception) { - Registry::getLogger()->error("Error on order patch call.", [$exception]); + $this->moduleLogger->error("Error on order patch call.", [$exception]); + //Registry::getLogger()->error("Error on order patch call.", [$exception]); throw $exception; } } @@ -280,7 +290,8 @@ public function doCapturePayPalOrder( $issue = $exception->getErrorIssue(); $this->displayErrorIfInstrumentDeclined($issue); - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $this->moduleLogger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -297,7 +308,8 @@ public function doCapturePayPalOrder( $issue = $exception->getErrorIssue(); $this->displayErrorIfInstrumentDeclined($issue); - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $this->moduleLogger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } } @@ -324,7 +336,8 @@ public function doCapturePayPalOrder( } } catch (Exception $exception) { //Webhook might try to capture already captured order - Registry::getLogger()->debug("Error on order capture call.", [$exception]); + $this->moduleLogger->debug("Error on order capture call.", [$exception]); + //Registry::getLogger()->debug("Error on order capture call.", [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -415,7 +428,8 @@ public function removeTemporaryOrder(): void if ($orderModel->isLoaded()) { if ($orderModel->hasOrderNumber()) { - Registry::getLogger()->info('Cannot delete valid order with id ' . $sessionOrderId); + $this->moduleLogger->info('Cannot delete valid order with id ' . $sessionOrderId); + //Registry::getLogger()->info('Cannot delete valid order with id ' . $sessionOrderId); } else { $orderModel->delete(); } @@ -471,7 +485,8 @@ public function doExecuteUAPMPayment(EshopModelOrder $order, EshopModelBasket $b PayPalSession::unsetPayPalOrderId(); $this->removeTemporaryOrder(); //TODO: do we need to log this? - Registry::getLogger()->error($exception->getMessage(), [$exception]); + $this->moduleLogger->error($exception->getMessage(), [$exception]); + //Registry::getLogger()->error($exception->getMessage(), [$exception]); } //NOTE: payment not fully executed, we need customer interaction first @@ -562,6 +577,7 @@ public function doExecutePuiPayment( string $payPalClientMetadataId = '' ): bool { $this->setPaymentExecutionError(self::PAYMENT_ERROR_NONE); + try { $result = $this->doCreatePayPalOrder( $basket, @@ -579,11 +595,13 @@ public function doExecutePuiPayment( $this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_PHONE); } catch (Exception $exception) { $this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_GENERIC); - Registry::getLogger()->error("Error on pui order creation call.", [$exception]); + $this->moduleLogger->error("Error on pui order creation call.", [$exception]); + //Registry::getLogger()->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'); + # $this->moduleLogger->error(serialize($paymentSource)); # Registry::getLogger()->error(serialize($paymentSource)); if (!$payPalOrderId) { From 1ad5eb86c1d308e6d1b736dad2b870dde2d58ae9 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Tue, 26 Sep 2023 17:05:31 +0200 Subject: [PATCH 3/7] WIP: Refactor getting Logger --- services.yaml | 10 ++------ .../Admin/PayPalConfigController.php | 22 +++++++++-------- .../Admin/PayPalOrderController.php | 11 +++++---- src/Controller/OrderController.php | 24 +++++++------------ src/Controller/ProxyController.php | 6 ++--- src/Controller/WebhookController.php | 10 ++++---- src/Core/Onboarding/Onboarding.php | 17 ++++++------- src/Core/Onboarding/Webhook.php | 9 +++---- src/Core/ServiceFactory.php | 8 +++---- src/Core/Tracker/Tracker.php | 9 +++---- .../Handler/CheckoutOrderApprovedHandler.php | 10 +++----- .../PaymentCaptureCompletedHandler.php | 13 ++++------ .../Webhook/Handler/WebhookHandlerBase.php | 11 +++------ src/Core/Webhook/RequestHandler.php | 16 ++++++++----- src/Model/Order.php | 11 ++++----- src/Model/PaymentGateway.php | 12 ++++------ src/Service/{PayPalLogger.php => Context.php} | 17 +------------ src/Service/ModuleSettings.php | 9 +++---- src/Service/Payment.php | 17 +++---------- 19 files changed, 91 insertions(+), 151 deletions(-) rename src/Service/{PayPalLogger.php => Context.php} (63%) diff --git a/services.yaml b/services.yaml index f4c3f9a66..5cb4c0dbc 100644 --- a/services.yaml +++ b/services.yaml @@ -38,15 +38,9 @@ services: public: true arguments: $loggerName: 'PayPal Payment Logger' - $logFilePath: '@=service("OxidSolutionCatalysts\\PayPal\\Service\\PayPalLogger").getPayPalLogFilePath()' + $logFilePath: '@=service("OxidSolutionCatalysts\\PayPal\\Service\\Context").getPayPalLogFilePath()' $logLevel: !php/const Psr\Log\LogLevel::INFO - OxidSolutionCatalysts\PayPal\Service\PayPalLogger: - class: OxidSolutionCatalysts\PayPal\Service\PayPalLogger - public: true - arguments: - $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' - OxidSolutionCatalysts\PayPal\Service\Payment: class: OxidSolutionCatalysts\PayPal\Service\Payment public: true @@ -61,7 +55,7 @@ services: OxidSolutionCatalysts\PayPal\Service\: resource: 'src/Service/*' - exclude: ['src/Service/{PayPalLogger}','src/Service/{Payment}','src/Service/{ModuleSettings}'] + exclude: ['src/Service/{Payment}','src/Service/{ModuleSettings}'] public: true OxidSolutionCatalysts\PayPal\Service\SCAValidatorInterface: diff --git a/src/Controller/Admin/PayPalConfigController.php b/src/Controller/Admin/PayPalConfigController.php index f2f0d5f62..ca61dca1d 100644 --- a/src/Controller/Admin/PayPalConfigController.php +++ b/src/Controller/Admin/PayPalConfigController.php @@ -8,6 +8,7 @@ namespace OxidSolutionCatalysts\PayPal\Controller\Admin; use GuzzleHttp\Exception\ClientException; +use JsonException; use OxidEsales\Eshop\Application\Controller\Admin\AdminController; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; @@ -21,8 +22,8 @@ use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; +use Psr\Log\LoggerInterface; /** * Controller for admin > PayPal/Configuration page @@ -205,9 +206,10 @@ protected function checkEligibility(): void $merchantInformations = $onBoardingClient->getMerchantInformations(); $handler->saveEligibility($merchantInformations); } catch (ClientException $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error("Error on checkEligibility", [$exception]); - //Registry::getLogger()->error("Error on checkEligibility", [$exception]); } } @@ -335,6 +337,7 @@ public function transferBannerSettings() /** * Get ClientID, ClientSecret, WebhookID + * @throws JsonException */ public function autoConfigurationFromCallback() { @@ -342,14 +345,13 @@ public function autoConfigurationFromCallback() $requestReader = oxNew(RequestReader::class); PayPalSession::storeOnboardingPayload($requestReader->getRawPost()); } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + $logger = $this->getServiceFromContainer(LoggerInterface::class); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } $result = []; header('Content-Type: application/json; charset=UTF-8'); - Registry::getUtils()->showMessageAndExit(json_encode($result)); + Registry::getUtils()->showMessageAndExit(json_encode($result, JSON_THROW_ON_ERROR)); } public function returnFromSignup() @@ -387,9 +389,9 @@ protected function autoConfiguration(): array $handler = oxNew(Onboarding::class); $credentials = $handler->autoConfigurationFromCallback(); } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $credentials; } @@ -408,9 +410,9 @@ protected function registerWebhooks(): string } catch (OnboardingException $exception) { Registry::getUtilsView()->addErrorToDisplay($exception->getMessage()); } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $webhookId; diff --git a/src/Controller/Admin/PayPalOrderController.php b/src/Controller/Admin/PayPalOrderController.php index 92625da97..033567d04 100644 --- a/src/Controller/Admin/PayPalOrderController.php +++ b/src/Controller/Admin/PayPalOrderController.php @@ -12,7 +12,6 @@ use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\Constants; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as ApiOrderModel; @@ -27,6 +26,7 @@ use OxidSolutionCatalysts\PayPal\Traits\AdminOrderTrait; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; +use Psr\Log\LoggerInterface; /** * Order class wrapper for PayPal module @@ -94,9 +94,10 @@ public function executeFunction($functionName) parent::executeFunction($functionName); } catch (ApiException $exception) { $this->addTplParam('error', $exception->getErrorDescription()); - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage()); - //Registry::getLogger()->error($exception->getMessage()); } } @@ -157,9 +158,9 @@ public function render() } } catch (ApiException $exception) { $this->addTplParam('error', $lang->translateString('OSC_PAYPAL_ERROR_' . $exception->getErrorIssue())); - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage()); - //Registry::getLogger()->error($exception->getMessage()); } } elseif ( $order->getFieldData('oxpaymenttype') == $this->payPalPlusPaymentType && diff --git a/src/Controller/OrderController.php b/src/Controller/OrderController.php index 4e6b5dac0..6f200668f 100644 --- a/src/Controller/OrderController.php +++ b/src/Controller/OrderController.php @@ -14,7 +14,6 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; use OxidSolutionCatalysts\PayPal\Exception\RedirectWithMessage; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\JsonTrait; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; @@ -24,6 +23,7 @@ use OxidSolutionCatalysts\PayPal\Core\Utils\PayPalAddressResponseToOxidAddress; use OxidSolutionCatalysts\PayPal\Model\Order as PayPalOrderModel; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; +use Psr\Log\LoggerInterface; /** * Class OrderController @@ -145,9 +145,9 @@ public function createAcdcOrder(): void $status = $this->execute(); } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); $this->outputJson(['acdcerror' => 'failed to execute shop order']); return; } @@ -176,7 +176,8 @@ public function createAcdcOrder(): void public function captureAcdcOrder(): void { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $acdcRequestId = (string) Registry::getRequest()->getRequestParameter('acdcorderid'); $sessionOrderId = (string) Registry::getSession()->getVariable('sess_challenge'); $sessionAcdcOrderId = (string) PayPalSession::getCheckoutOrderId(); @@ -188,9 +189,6 @@ public function captureAcdcOrder(): void $sessionAcdcOrderId ) { $logger->debug('captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId); - //Registry::getLogger()->debug( - // 'captureAcdcOrder already COMPLETED for PayPal Order id ' . $sessionAcdcOrderId - //); $result = [ 'location' => [ @@ -237,7 +235,6 @@ public function captureAcdcOrder(): void Registry::getSession()->setVariable(Constants::SESSION_ACDC_PAYPALORDER_STATUS, $response->status); } catch (\Exception $exception) { $logger->debug($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); $this->getServiceFromContainer(PaymentService::class)->removeTemporaryOrder(); } @@ -276,15 +273,12 @@ public function finalizepaypalsession(): string $order->finalizeOrderAfterExternalPayment($sessionCheckoutOrderId); $order->save(); } catch (PayPalException $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->debug( 'PayPal Checkout error during order finalization ' . $exception->getMessage(), [$exception] ); - //Registry::getLogger()->debug( - // 'PayPal Checkout error during order finalization ' . $exception->getMessage(), - // [$exception] - //); $this->cancelpaypalsession('cannot finalize order'); return 'payment?payerror=2'; } @@ -305,12 +299,12 @@ public function finalizeacdc(): string $order->finalizeOrderAfterExternalPayment($sessionAcdcOrderId, $forceFetchDetails); $goNext = 'thankyou'; } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error( 'failure during finalizeOrderAfterExternalPayment', [$exception] ); - //Registry::getLogger()->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 096040b23..8d2227100 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -19,7 +19,6 @@ use OxidEsales\Eshop\Core\Exception\StandardException; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\UserRepository; use OxidSolutionCatalysts\PayPal\Core\Config; @@ -30,6 +29,7 @@ use OxidSolutionCatalysts\PayPal\Core\Utils\PayPalAddressResponseToOxidAddress; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiOrder; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; +use Psr\Log\LoggerInterface; /** * Server side interface for PayPal smart buttons. @@ -92,9 +92,9 @@ public function approveOrder() try { $response = $service->showOrderDetails($orderId, ''); } catch (Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error("Error on order capture call.", [$exception]); - //Registry::getLogger()->error("Error on order capture call.", [$exception]); } if (!$this->getUser()) { diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index 9b2b602bd..bab8ea42a 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -13,8 +13,8 @@ use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher; use OxidSolutionCatalysts\PayPal\Core\Webhook\RequestHandler as WebhookRequestHandler; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; +use Psr\Log\LoggerInterface; /** * Class WebhookController @@ -31,7 +31,8 @@ public function init() { parent::init(); - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); try { $requestReader = new RequestReader(); @@ -39,15 +40,12 @@ public function init() $dispatcher = Registry::get(EventDispatcher::class); $logger->debug('PayPal Webhook request ' . $requestReader->getRawPost()); - //Registry::getLogger()->debug('PayPal Webhook request ' . $requestReader->getRawPost()); $logger->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); - //Registry::getLogger()->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders())); $webhookRequestHandler = new WebhookRequestHandler($requestReader, $verificationService, $dispatcher); - $success = $webhookRequestHandler->process(); + $webhookRequestHandler->process(); } catch (\Exception $exception) { $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->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/Onboarding/Onboarding.php b/src/Core/Onboarding/Onboarding.php index 4afb8dec6..616d71e63 100644 --- a/src/Core/Onboarding/Onboarding.php +++ b/src/Core/Onboarding/Onboarding.php @@ -11,13 +11,12 @@ use OxidSolutionCatalysts\PayPal\Core\Config as PayPalConfig; use OxidSolutionCatalysts\PayPal\Core\PartnerConfig; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; -use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Onboarding as ApiOnboardingClient; +use Psr\Log\LoggerInterface; class Onboarding { @@ -58,9 +57,9 @@ public function fetchCredentials(): array $credentials = $apiClient->getCredentials(); } catch (ApiException $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $credentials; @@ -121,9 +120,11 @@ public function getOnboardingClient(bool $isSandbox, bool $withCredentials = fal $merchantId = $paypalConfig->getMerchantId(); } + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); + return new ApiOnboardingClient( - //Registry::getLogger(), - $this->getServiceFromContainer(PayPalLogger::class)->getLogger(), + $logger, $isSandbox ? $paypalConfig->getClientSandboxUrl() : $paypalConfig->getClientLiveUrl(), $clientId, $clientSecret, @@ -141,9 +142,9 @@ public function fetchMerchantInformations() $apiClient = $this->getOnboardingClient($onboardingResponse['isSandBox'], true); $merchantInformations = $apiClient->getMerchantInformations(); } catch (ApiException $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return $merchantInformations; } diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index d84a442bb..86a8244c3 100644 --- a/src/Core/Onboarding/Webhook.php +++ b/src/Core/Onboarding/Webhook.php @@ -11,11 +11,11 @@ use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventHandlerMapping; use OxidSolutionCatalysts\PayPal\Core\Config as PayPalConfig; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; +use Psr\Log\LoggerInterface; class Webhook { @@ -69,15 +69,12 @@ public function registerWebhooks(): string $webhookId = $webHookResponse['id'] ?? ''; } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error( 'PayPal Webhook creation failed: ' . $exception->getMessage(), [$exception] ); - //Registry::getLogger()->error( - // 'PayPal Webhook creation failed: ' . $exception->getMessage(), - // [$exception] - //); } return $webhookId; diff --git a/src/Core/ServiceFactory.php b/src/Core/ServiceFactory.php index 4dbe55c2e..021da211e 100644 --- a/src/Core/ServiceFactory.php +++ b/src/Core/ServiceFactory.php @@ -9,16 +9,14 @@ namespace OxidSolutionCatalysts\PayPal\Core; -use OxidEsales\Eshop\Core\Registry; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Client; use OxidSolutionCatalysts\PayPalApi\Service\Partner; -use OxidSolutionCatalysts\PayPalApi\Service\Catalog; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; use OxidSolutionCatalysts\PayPalApi\Service\Orders; use OxidSolutionCatalysts\PayPalApi\Service\Payments; use OxidSolutionCatalysts\PayPal\Core\Api\IdentityService; +use Psr\Log\LoggerInterface; /** * Class ServiceFactory @@ -119,10 +117,10 @@ private function getClient(): Client if ($this->client === null) { /** @var Config $config */ $config = oxNew(Config::class); - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $client = new Client( - //Registry::getLogger(), $logger, $config->isSandbox() ? Client::SANDBOX_URL : Client::PRODUCTION_URL, $config->getClientId(), diff --git a/src/Core/Tracker/Tracker.php b/src/Core/Tracker/Tracker.php index efd4750d3..10405ca37 100644 --- a/src/Core/Tracker/Tracker.php +++ b/src/Core/Tracker/Tracker.php @@ -9,9 +9,9 @@ use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; +use Psr\Log\LoggerInterface; class Tracker { @@ -53,15 +53,12 @@ public function sendtracking( $result = $trackerResponse['tracker_identifiers'][0]['tracking_number'] === $trackingNumber; } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error( 'PayPal sending Tracker failed: ' . $exception->getMessage(), [$exception] ); - //Registry::getLogger()->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 af80e6ff2..77793a1b2 100644 --- a/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php +++ b/src/Core/Webhook/Handler/CheckoutOrderApprovedHandler.php @@ -10,13 +10,13 @@ use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalModelOrder; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as OrderResponse; use OxidSolutionCatalysts\PayPalApi\Model\Orders\OrderCaptureRequest; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; +use Psr\Log\LoggerInterface; class CheckoutOrderApprovedHandler extends WebhookHandlerBase { @@ -40,17 +40,13 @@ public function handleWebhookTasks( ); $order->setOrderNumber(); //ensure the order has a number } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->debug( "Error during " . self::WEBHOOK_EVENT_NAME . " for PayPal order_id '" . $payPalOrderId . "'", [$exception] ); - //Registry::getLogger()->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 c78fc6ec0..5e1948dc4 100644 --- a/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php +++ b/src/Core/Webhook/Handler/PaymentCaptureCompletedHandler.php @@ -7,12 +7,11 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook\Handler; -use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\EshopCommunity\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; +use Psr\Log\LoggerInterface; class PaymentCaptureCompletedHandler extends WebhookHandlerBase { @@ -34,8 +33,7 @@ protected function getPayPalTransactionIdFromResource(array $eventPayload): stri protected function getStatusFromResource(array $eventPayload): string { //API v1 response uses 'state', v2 uses 'status' and some webhook events don't come with a status - return isset($eventPayload['state']) ? $eventPayload['state'] : - (isset($eventPayload['status']) ? $eventPayload['status'] : ''); + return $eventPayload['state'] ?? ($eventPayload['status'] ?? ''); } protected function getPayPalOrderDetails(string $payPalOrderId): ?PayPalApiModelOrder @@ -47,15 +45,12 @@ protected function getPayPalOrderDetails(string $payPalOrderId): ?PayPalApiModel ->getOrderService() ->showOrderDetails($payPalOrderId, ''); } catch (ApiException $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->debug( 'Exception during PaymentCaptureCompletedHandler::getPayPalOrderDetails().', [$exception] ); - //Registry::getLogger()->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 20d3b9a94..33cd8c052 100644 --- a/src/Core/Webhook/Handler/WebhookHandlerBase.php +++ b/src/Core/Webhook/Handler/WebhookHandlerBase.php @@ -9,17 +9,16 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook\Handler; -use OxidEsales\EshopCommunity\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\Webhook\Event; use OxidSolutionCatalysts\PayPal\Exception\NotFound; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventException; use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalModelOrder; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiModelOrder; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; +use Psr\Log\LoggerInterface; abstract class WebhookHandlerBase { @@ -60,17 +59,13 @@ public function handle(Event $event): void $order ); } else { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @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 . "'" ); - //Registry::getLogger()->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 c5fa208f8..a70de9878 100644 --- a/src/Core/Webhook/RequestHandler.php +++ b/src/Core/Webhook/RequestHandler.php @@ -9,14 +9,15 @@ namespace OxidSolutionCatalysts\PayPal\Core\Webhook; +use JsonException; use OxidSolutionCatalysts\PayPal\Core\RequestReader; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier as VerificationService; use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher as WebhookDispatcher; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventException; use OxidSolutionCatalysts\PayPal\Exception\WebhookEventTypeException; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; +use Psr\Log\LoggerInterface; final class RequestHandler { @@ -44,7 +45,8 @@ public function __construct( public function process(): bool { $result = false; - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); try { $requestBody = $this->requestReader->getRawPost(); @@ -58,22 +60,24 @@ public function process(): bool } 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]); - // Registry::getLogger()->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]); - // Registry::getLogger()->error($exception->getMessage(), [$exception]); throw $exception; } return $result; } + /** + * @throws WebhookEventTypeException + * @throws WebhookEventException + * @throws JsonException + */ private function processEvent(string $data): void { - $data = json_decode($data, true); + $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR); if ( - is_array($data) && isset($data['event_type']) ) { $this->webhookDispatcher->dispatch(new Event($data, $data['event_type'])); diff --git a/src/Model/Order.php b/src/Model/Order.php index d55a466a9..3ead5543e 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -17,11 +17,9 @@ use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Model\BaseModel; use OxidEsales\Eshop\Core\Registry; -use OxidEsales\PayPalModule\Core\Logger; use OxidSolutionCatalysts\PayPal\Core\Tracker\Tracker; use OxidSolutionCatalysts\PayPal\Exception\PayPalException; use OxidSolutionCatalysts\PayPal\Service\OrderRepository; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Capture; use OxidSolutionCatalysts\PayPalApi\Model\Orders\Order as PayPalApiOrder; @@ -34,6 +32,7 @@ use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidEsales\Eshop\Core\Counter as EshopCoreCounter; +use Psr\Log\LoggerInterface; /** * PayPal Eshop model order class @@ -290,9 +289,9 @@ protected function _executePayment(Basket $basket, $userpayment) return self::ORDER_STATE_SESSIONPAYMENT_INPROGRESS; } catch (\Exception $exception) { $this->delete(); - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } return self::ORDER_STATE_PAYMENTERROR; } elseif ($isPayPalACDC) { @@ -342,9 +341,9 @@ protected function doExecutePayPalPayment($payPalOrderId): bool // success means at this point, that we triggered the capture without errors $success = true; } catch (\Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error("Error on order capture call.", [$exception]); - //Registry::getLogger()->error("Error on order capture call.", [$exception]); } // destroy PayPal-Session diff --git a/src/Model/PaymentGateway.php b/src/Model/PaymentGateway.php index bfcf2fbb6..16ac511c1 100644 --- a/src/Model/PaymentGateway.php +++ b/src/Model/PaymentGateway.php @@ -11,10 +11,10 @@ use OxidEsales\Eshop\Core\Registry; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Core\PayPalSession; -use OxidSolutionCatalysts\PayPal\Service\PayPalLogger; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidSolutionCatalysts\PayPal\Service\Payment as PaymentService; +use Psr\Log\LoggerInterface; /** * Class PaymentGateway @@ -65,14 +65,14 @@ protected function doExecutePayPalExpressPayment(EshopModelOrder $order): bool $sessionPaymentId = (string) $paymentService->getSessionPaymentId(); $success = false; - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @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]); - //Registry::getLogger()->error("Error on order patch call.", [$exception]); } // Capture Order @@ -84,8 +84,6 @@ protected function doExecutePayPalExpressPayment(EshopModelOrder $order): bool $success = true; } catch (Exception $exception) { $logger->error("Error on order capture call.", [$exception]); - //Registry::getLogger()->error("Error on order capture call.", [$exception]); - $success = false; } // destroy PayPal-Session @@ -109,9 +107,9 @@ protected function doExecutePuiPayment(EshopModelOrder $order): bool ); PayPalSession::unsetPayPalPuiCmId(); } catch (Exception $exception) { - $logger = $this->getServiceFromContainer(PayPalLogger::class)->getLogger(); + /** @var LoggerInterface $logger */ + $logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger'); $logger->error("Error on execute pui payment call.", [$exception]); - //Registry::getLogger()->error("Error on execute pui payment call.", [$exception]); } // destroy PayPal-Session PayPalSession::unsetPayPalOrderId(); diff --git a/src/Service/PayPalLogger.php b/src/Service/Context.php similarity index 63% rename from src/Service/PayPalLogger.php rename to src/Service/Context.php index 03f10ee5d..ce32e27f7 100644 --- a/src/Service/PayPalLogger.php +++ b/src/Service/Context.php @@ -10,25 +10,10 @@ namespace OxidSolutionCatalysts\PayPal\Service; use OxidEsales\Eshop\Core\Registry; -use Psr\Log\LoggerInterface; use Webmozart\PathUtil\Path; -class PayPalLogger +class Context { - private LoggerInterface $moduleLogger; - - public function __construct( - LoggerInterface $moduleLogger - ) - { - $this->moduleLogger = $moduleLogger; - } - - public function getLogger(): LoggerInterface - { - return $this->moduleLogger; - } - /** * @SuppressWarnings(PHPMD.StaticAccess) */ diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index c2f944d4b..9be5cbffd 100644 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -9,6 +9,7 @@ namespace OxidSolutionCatalysts\PayPal\Service; +use Monolog\Logger; use OxidEsales\Eshop\Application\Model\Country; use OxidEsales\Eshop\Application\Model\Payment; use OxidEsales\Eshop\Application\Model\User; @@ -20,9 +21,7 @@ use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; -use OxidSolutionCatalysts\PayPal\Core\ServiceFactory; use OxidSolutionCatalysts\PayPal\Module; -use Psr\Log\LoggerInterface; class ModuleSettings { @@ -63,7 +62,7 @@ class ModuleSettings /** @var ContextInterface */ private $context; - private LoggerInterface $moduleLogger; + private Logger $moduleLogger; //TODO: we need service for fetching module settings from db (this one) //another class for moduleconfiguration (database values/edefaults) @@ -74,7 +73,7 @@ public function __construct( ModuleSettingBridgeInterface $moduleSettingBridge, ContextInterface $context, ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface, - LoggerInterface $moduleLogger + Logger $moduleLogger ) { $this->moduleSettingBridge = $moduleSettingBridge; $this->context = $context; @@ -403,13 +402,11 @@ public function saveMerchantId(string $merchantId, ?bool $isSandbox = null): voi if ($isSandbox) { $this->save('oscPayPalSandboxClientMerchantId', $merchantId); $this->moduleLogger->info(sprintf('Saving Sandbox Merchant ID %s from onboarding', $merchantId)); - //Registry::getLogger()->info(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)); - //Registry::getLogger()->info(sprintf('Saving Live Merchant ID %s from onboarding', $merchantId)); } } diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 1dbf28bb1..469f23eae 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -8,6 +8,7 @@ namespace OxidSolutionCatalysts\PayPal\Service; use Exception; +use Monolog\Logger; use OxidEsales\Eshop\Application\Model\Basket as EshopModelBasket; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\Eshop\Core\Exception\StandardException; @@ -37,7 +38,6 @@ use OxidSolutionCatalysts\PayPalApi\Model\Payments\ReauthorizeRequest; use OxidSolutionCatalysts\PayPalApi\Service\Orders as ApiOrderService; use OxidSolutionCatalysts\PayPalApi\Service\Payments as ApiPaymentService; -use Psr\Log\LoggerInterface; class Payment { @@ -80,14 +80,14 @@ class Payment /** @var ModuleSettingsService */ private $moduleSettingsService; - private LoggerInterface $moduleLogger; + private Logger $moduleLogger; public function __construct( EshopSession $eshopSession, OrderRepository $orderRepository, SCAValidatorInterface $scaValidator, ModuleSettingsService $moduleSettingsService, - LoggerInterface $moduleLogger, + Logger $moduleLogger, ServiceFactory $serviceFactory = null, PatchRequestFactory $patchRequestFactory = null, OrderRequestFactory $orderRequestFactory = null @@ -152,12 +152,9 @@ public function doCreatePayPalOrder( $this->moduleLogger->error("Api error on order create call. " . $exception->getErrorIssue(), [$exception]); - //Registry::getLogger()->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]); - //Registry::getLogger()->error("Error on order create call.", [$exception]); $this->setPaymentExecutionError(self::PAYMENT_ERROR_GENERIC); } @@ -219,7 +216,6 @@ public function doPatchPayPalOrder( $orderService->updateOrder($checkoutOrderId, $request); } catch (Exception $exception) { $this->moduleLogger->error("Error on order patch call.", [$exception]); - //Registry::getLogger()->error("Error on order patch call.", [$exception]); throw $exception; } } @@ -291,7 +287,6 @@ public function doCapturePayPalOrder( $this->displayErrorIfInstrumentDeclined($issue); $this->moduleLogger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -309,7 +304,6 @@ public function doCapturePayPalOrder( $this->displayErrorIfInstrumentDeclined($issue); $this->moduleLogger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } } @@ -337,7 +331,6 @@ public function doCapturePayPalOrder( } catch (Exception $exception) { //Webhook might try to capture already captured order $this->moduleLogger->debug("Error on order capture call.", [$exception]); - //Registry::getLogger()->debug("Error on order capture call.", [$exception]); throw oxNew(StandardException::class, 'OSC_PAYPAL_ORDEREXECUTION_ERROR'); } @@ -429,7 +422,6 @@ public function removeTemporaryOrder(): void if ($orderModel->isLoaded()) { if ($orderModel->hasOrderNumber()) { $this->moduleLogger->info('Cannot delete valid order with id ' . $sessionOrderId); - //Registry::getLogger()->info('Cannot delete valid order with id ' . $sessionOrderId); } else { $orderModel->delete(); } @@ -486,7 +478,6 @@ public function doExecuteUAPMPayment(EshopModelOrder $order, EshopModelBasket $b $this->removeTemporaryOrder(); //TODO: do we need to log this? $this->moduleLogger->error($exception->getMessage(), [$exception]); - //Registry::getLogger()->error($exception->getMessage(), [$exception]); } //NOTE: payment not fully executed, we need customer interaction first @@ -596,13 +587,11 @@ public function doExecutePuiPayment( } catch (Exception $exception) { $this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_GENERIC); $this->moduleLogger->error("Error on pui order creation call.", [$exception]); - //Registry::getLogger()->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'); # $this->moduleLogger->error(serialize($paymentSource)); - # Registry::getLogger()->error(serialize($paymentSource)); if (!$payPalOrderId) { return false; From 8e0e31f0079d4d69e4108daf1c284bd0e1668c7e Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Thu, 28 Sep 2023 13:57:49 +0200 Subject: [PATCH 4/7] Use interfaces in Services --- services.yaml | 39 +++++++++++++--------------------- src/Service/ModuleSettings.php | 6 +++--- src/Service/Payment.php | 7 +++--- src/Service/UserRepository.php | 14 ++++++------ 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/services.yaml b/services.yaml index 5cb4c0dbc..729c71e20 100644 --- a/services.yaml +++ b/services.yaml @@ -3,24 +3,16 @@ services: _defaults: public: false autowire: true - - OxidEsales\Eshop\Core\Registry: + bind: + OxidEsales\Eshop\Core\Config: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getConfig()' + OxidEsales\Eshop\Core\Session: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getSession()' + OxidEsales\Eshop\Core\Language: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getLang()' + OxidEsales\Eshop\Core\UtilsDate: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getUtilsDate()' + OxidEsales\Eshop\Core\Request: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getRequest()' + + OxidSolutionCatalysts\PayPal\Core\Registry: class: OxidEsales\Eshop\Core\Registry - - OxidEsales\Eshop\Core\Config: - factory: [ '@OxidEsales\Eshop\Core\Registry', 'getConfig' ] - - OxidEsales\Eshop\Core\Session: - factory: [ '@OxidEsales\Eshop\Core\Registry', 'getSession' ] - - OxidEsales\Eshop\Core\Language: - factory: [ '@OxidEsales\Eshop\Core\Registry', 'getLang' ] - - OxidEsales\Eshop\Core\UtilsDate: - factory: [ '@OxidEsales\Eshop\Core\Registry', 'getUtilsDate' ] - - OxidEsales\Eshop\Core\Request: - factory: [ '@OxidEsales\Eshop\Core\Registry', 'getRequest' ] + public: true OxidSolutionCatalysts\PayPal\Logger: class: Monolog\Logger @@ -41,22 +33,21 @@ services: $logFilePath: '@=service("OxidSolutionCatalysts\\PayPal\\Service\\Context").getPayPalLogFilePath()' $logLevel: !php/const Psr\Log\LogLevel::INFO + OxidSolutionCatalysts\PayPal\Service\: + resource: 'src/Service/*' + public: true + OxidSolutionCatalysts\PayPal\Service\Payment: class: OxidSolutionCatalysts\PayPal\Service\Payment public: true arguments: - $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' + Psr\Log\LoggerInterface: '@OxidSolutionCatalysts\PayPal\Logger' OxidSolutionCatalysts\PayPal\Service\ModuleSettings: class: OxidSolutionCatalysts\PayPal\Service\ModuleSettings public: true arguments: - $moduleLogger: '@OxidSolutionCatalysts\PayPal\Logger' - - OxidSolutionCatalysts\PayPal\Service\: - resource: 'src/Service/*' - exclude: ['src/Service/{Payment}','src/Service/{ModuleSettings}'] - public: true + Psr\Log\LoggerInterface: '@OxidSolutionCatalysts\PayPal\Logger' OxidSolutionCatalysts\PayPal\Service\SCAValidatorInterface: class: OxidSolutionCatalysts\PayPal\Service\SCAValidator diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index 9be5cbffd..2086bc6cc 100644 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -9,7 +9,6 @@ namespace OxidSolutionCatalysts\PayPal\Service; -use Monolog\Logger; use OxidEsales\Eshop\Application\Model\Country; use OxidEsales\Eshop\Application\Model\Payment; use OxidEsales\Eshop\Application\Model\User; @@ -22,6 +21,7 @@ use OxidSolutionCatalysts\PayPal\Core\Constants; use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Module; +use Psr\Log\LoggerInterface; class ModuleSettings { @@ -62,7 +62,7 @@ class ModuleSettings /** @var ContextInterface */ private $context; - private Logger $moduleLogger; + private LoggerInterface $moduleLogger; //TODO: we need service for fetching module settings from db (this one) //another class for moduleconfiguration (database values/edefaults) @@ -73,7 +73,7 @@ public function __construct( ModuleSettingBridgeInterface $moduleSettingBridge, ContextInterface $context, ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface, - Logger $moduleLogger + LoggerInterface $moduleLogger ) { $this->moduleSettingBridge = $moduleSettingBridge; $this->context = $context; diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 469f23eae..8a8a87c51 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -8,7 +8,6 @@ namespace OxidSolutionCatalysts\PayPal\Service; use Exception; -use Monolog\Logger; use OxidEsales\Eshop\Application\Model\Basket as EshopModelBasket; use OxidEsales\Eshop\Application\Model\Order as EshopModelOrder; use OxidEsales\Eshop\Core\Exception\StandardException; @@ -38,6 +37,7 @@ use OxidSolutionCatalysts\PayPalApi\Model\Payments\ReauthorizeRequest; use OxidSolutionCatalysts\PayPalApi\Service\Orders as ApiOrderService; use OxidSolutionCatalysts\PayPalApi\Service\Payments as ApiPaymentService; +use Psr\Log\LoggerInterface; class Payment { @@ -80,14 +80,14 @@ class Payment /** @var ModuleSettingsService */ private $moduleSettingsService; - private Logger $moduleLogger; + private LoggerInterface $moduleLogger; public function __construct( EshopSession $eshopSession, OrderRepository $orderRepository, SCAValidatorInterface $scaValidator, ModuleSettingsService $moduleSettingsService, - Logger $moduleLogger, + LoggerInterface $moduleLogger, ServiceFactory $serviceFactory = null, PatchRequestFactory $patchRequestFactory = null, OrderRequestFactory $orderRequestFactory = null @@ -118,7 +118,6 @@ public function doCreatePayPalOrder( #): ?ApiModelOrder ) { //TODO return value - $this->setPaymentExecutionError(self::PAYMENT_ERROR_NONE); /** @var ApiOrderService $orderService */ diff --git a/src/Service/UserRepository.php b/src/Service/UserRepository.php index fbb70f567..046c86a6b 100644 --- a/src/Service/UserRepository.php +++ b/src/Service/UserRepository.php @@ -12,9 +12,9 @@ use PDO; use Doctrine\DBAL\Query\QueryBuilder; use OxidEsales\Eshop\Core\Config as EshopCoreConfig; +use OxidEsales\Eshop\Core\Session as EshopCoreSession; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; -use OxidEsales\Eshop\Core\Registry as EshopRegistry; use OxidEsales\Eshop\Application\Model\Country; use OxidEsales\Eshop\Application\Model\State; @@ -29,19 +29,19 @@ class UserRepository /** @var EshopCoreConfig */ private $config; - /** @var EshopRegistry */ - private $registry; + /** @var EshopCoreSession */ + private $session; public function __construct( QueryBuilderFactoryInterface $queryBuilderFactory, ContextInterface $context, EshopCoreConfig $config, - EshopRegistry $registry + EshopCoreSession $session ) { $this->queryBuilderFactory = $queryBuilderFactory; $this->context = $context; $this->config = $config; - $this->registry = $registry; + $this->session = $session; } /** @@ -96,7 +96,7 @@ private function getUserId(string $userEmail, bool $hasPassword = true): string public function getUserCountryIso(): string { $result = ''; - if ($user = $this->registry->getSession()->getUser()) { + if ($user = $this->session->getUser()) { $country = oxNew(Country::class); $country->load($user->getFieldData('oxcountryid')); $result = (string) $country->getFieldData('oxisoalpha2'); @@ -107,7 +107,7 @@ public function getUserCountryIso(): string public function getUserStateIso(): string { $result = ''; - if ($user = $this->registry->getSession()->getUser()) { + if ($user = $this->session->getUser()) { $state = oxNew(State::class); $state->loadByIdAndCountry( $user->getFieldData('oxstateid'), From 561dddc1822b8c76001a499f3adfc02948ae8c10 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Thu, 28 Sep 2023 14:21:20 +0200 Subject: [PATCH 5/7] fix codestyle --- .gitignore | 10 ++--- src/Controller/ProxyController.php | 5 ++- src/Service/Context.php | 66 +++++++++++++++--------------- src/Service/Payment.php | 1 - 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 76208a583..277c48d6c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ php-cs-fixer.phar /var/ /vendor/ /composer.lock -/Tests/Codeception/_output/ -/Tests/Codeception/_support/_generated/ -/Tests/.env -/Tests/report -/resources/node_modules/ +/tests/Codeception/_output/ +/tests/Codeception/_support/_generated/ +/tests/.env +/tests/report +/resources/node_modules/ \ No newline at end of file diff --git a/src/Controller/ProxyController.php b/src/Controller/ProxyController.php index 8d2227100..474bbe7a0 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -273,8 +273,9 @@ protected function getPayPalPartnerAttributionId(): string return Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_EXPRESS; } - protected function getRequestedPayPalPaymentId($defaultPayPalPaymentId = PayPalDefinitions::EXPRESS_PAYPAL_PAYMENT_ID): string - { + protected function getRequestedPayPalPaymentId( + $defaultPayPalPaymentId = PayPalDefinitions::EXPRESS_PAYPAL_PAYMENT_ID + ): string { $paymentId = (string) Registry::getRequest()->getRequestEscapedParameter('paymentid'); return PayPalDefinitions::isPayPalPayment($paymentId) ? $paymentId : diff --git a/src/Service/Context.php b/src/Service/Context.php index ce32e27f7..786f4e142 100644 --- a/src/Service/Context.php +++ b/src/Service/Context.php @@ -1,33 +1,33 @@ -getLogsDir(), - 'paypal', - $this->getPayPalLogFileName() - ]); - } - - private function getPayPalLogFileName(): string - { - return "paypal_" . date("Y-m-d") . ".log"; - } -} \ No newline at end of file +getLogsDir(), + 'paypal', + $this->getPayPalLogFileName() + ]); + } + + private function getPayPalLogFileName(): string + { + return "paypal_" . date("Y-m-d") . ".log"; + } +} diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 8a8a87c51..f9bebd897 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -148,7 +148,6 @@ public function doCreatePayPalOrder( $payPalRequestId ); } catch (ApiException $exception) { - $this->moduleLogger->error("Api error on order create call. " . $exception->getErrorIssue(), [$exception]); $this->handlePayPalApiError($exception); From c5ae27c770f76af4187ec2a431be98da8794df5c Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Thu, 28 Sep 2023 14:24:39 +0200 Subject: [PATCH 6/7] Change-Log --- CHANGELOG.md | 1 + metadata.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b93b783..374c7329e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [0007537](https://bugs.oxid-esales.com/view.php?id=7537): Show PayNow-Button on PP-Standard instead of Continue-Button - [0007531](https://bugs.oxid-esales.com/view.php?id=7531): Correct Handling of Vouchers from Voucher-Series - [0007536](https://bugs.oxid-esales.com/view.php?id=7536): PayPal Checkout - Values are stored correctly in the YAML +- [0007547](https://bugs.oxid-esales.com/view.php?id=7547): PayPal error messages are written into seperate log (/log/paypal/paypal_YYYY-MM-DD.log) ## [2.3.1] - 2023-08-17 diff --git a/metadata.php b/metadata.php index 05ba95e7f..5343f0618 100644 --- a/metadata.php +++ b/metadata.php @@ -56,7 +56,7 @@ 'en' => 'Use of the online payment service from PayPal. Documentation: PayPal Checkout' ], 'thumbnail' => 'out/img/paypal.png', - 'version' => '2.3.2-rc.1', + 'version' => '2.3.2-rc.2', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com', From bb74e07a06de16d125c34b02a847f4afef8c4cd7 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 29 Sep 2023 23:58:23 +0200 Subject: [PATCH 7/7] switch back from bindings because it does not work in OXID 6.3 --- services.yaml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/services.yaml b/services.yaml index 729c71e20..1a195f693 100644 --- a/services.yaml +++ b/services.yaml @@ -3,17 +3,26 @@ services: _defaults: public: false autowire: true - bind: - OxidEsales\Eshop\Core\Config: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getConfig()' - OxidEsales\Eshop\Core\Session: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getSession()' - OxidEsales\Eshop\Core\Language: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getLang()' - OxidEsales\Eshop\Core\UtilsDate: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getUtilsDate()' - OxidEsales\Eshop\Core\Request: '@=service("OxidSolutionCatalysts\\PayPal\\Core\\Registry").getRequest()' - - OxidSolutionCatalysts\PayPal\Core\Registry: + + OxidEsales\Eshop\Core\Registry: class: OxidEsales\Eshop\Core\Registry + + OxidEsales\Eshop\Core\Config: + factory: [ '@OxidEsales\Eshop\Core\Registry', 'getConfig' ] public: true + OxidEsales\Eshop\Core\Session: + factory: [ '@OxidEsales\Eshop\Core\Registry', 'getSession' ] + + OxidEsales\Eshop\Core\Language: + factory: [ '@OxidEsales\Eshop\Core\Registry', 'getLang' ] + + OxidEsales\Eshop\Core\UtilsDate: + factory: [ '@OxidEsales\Eshop\Core\Registry', 'getUtilsDate' ] + + OxidEsales\Eshop\Core\Request: + factory: [ '@OxidEsales\Eshop\Core\Registry', 'getRequest' ] + OxidSolutionCatalysts\PayPal\Logger: class: Monolog\Logger factory: ['@OxidSolutionCatalysts\PayPal\Logger\Factory', 'create']