Skip to content

Commit

Permalink
Merge branch 'b-6.3.x' into PSPAYPAL-697_NewBannerColors
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-gust authored Oct 5, 2023
2 parents 61b6d26 + b17ca7b commit 10c7c61
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 78 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.3.2] - 2023-??-??
## [2.3.2] - 2023-10-05

- [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
- [0007543](https://bugs.oxid-esales.com/view.php?id=7543): New Color-Codes for Banner: gray, monochrome, greyscale
- [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

Expand Down
33 changes: 32 additions & 1 deletion services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:

OxidEsales\Eshop\Core\Config:
factory: [ '@OxidEsales\Eshop\Core\Registry', 'getConfig' ]
public: true

OxidEsales\Eshop\Core\Session:
factory: [ '@OxidEsales\Eshop\Core\Registry', 'getSession' ]
Expand All @@ -22,11 +23,41 @@ 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\\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:
Psr\Log\LoggerInterface: '@OxidSolutionCatalysts\PayPal\Logger'

OxidSolutionCatalysts\PayPal\Service\ModuleSettings:
class: OxidSolutionCatalysts\PayPal\Service\ModuleSettings
public: true
arguments:
Psr\Log\LoggerInterface: '@OxidSolutionCatalysts\PayPal\Logger'

OxidSolutionCatalysts\PayPal\Service\SCAValidatorInterface:
class: OxidSolutionCatalysts\PayPal\Service\SCAValidator
public: true

21 changes: 16 additions & 5 deletions src/Controller/Admin/PayPalConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
use OxidSolutionCatalysts\PayPal\Exception\OnboardingException;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use Psr\Log\LoggerInterface;

/**
* Controller for admin > PayPal/Configuration page
Expand Down Expand Up @@ -204,7 +206,10 @@ protected function checkEligibility(): void
$merchantInformations = $onBoardingClient->getMerchantInformations();
$handler->saveEligibility($merchantInformations);
} catch (ClientException $exception) {
Registry::getLogger()->error("Error on checkEligibility", [$exception]);

/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error("Error on checkEligibility", [$exception]);
}
}

Expand Down Expand Up @@ -332,19 +337,21 @@ public function transferBannerSettings()

/**
* Get ClientID, ClientSecret, WebhookID
* @throws JsonException
*/
public function autoConfigurationFromCallback()
{
try {
$requestReader = oxNew(RequestReader::class);
PayPalSession::storeOnboardingPayload($requestReader->getRawPost());
} catch (\Exception $exception) {
Registry::getLogger()->error($exception->getMessage(), [$exception]);
$logger = $this->getServiceFromContainer(LoggerInterface::class);
$logger->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()
Expand Down Expand Up @@ -382,7 +389,9 @@ protected function autoConfiguration(): array
$handler = oxNew(Onboarding::class);
$credentials = $handler->autoConfigurationFromCallback();
} catch (\Exception $exception) {
Registry::getLogger()->error($exception->getMessage(), [$exception]);
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error($exception->getMessage(), [$exception]);
}
return $credentials;
}
Expand All @@ -401,7 +410,9 @@ protected function registerWebhooks(): string
} catch (OnboardingException $exception) {
Registry::getUtilsView()->addErrorToDisplay($exception->getMessage());
} catch (\Exception $exception) {
Registry::getLogger()->error($exception->getMessage(), [$exception]);
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error($exception->getMessage(), [$exception]);
}

return $webhookId;
Expand Down
11 changes: 8 additions & 3 deletions src/Controller/Admin/PayPalOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;
Expand All @@ -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
Expand Down Expand Up @@ -94,7 +94,10 @@ public function executeFunction($functionName)
parent::executeFunction($functionName);
} catch (ApiException $exception) {
$this->addTplParam('error', $exception->getErrorDescription());
Registry::getLogger()->error($exception->getMessage());

/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error($exception->getMessage());
}
}

Expand Down Expand Up @@ -155,7 +158,9 @@ public function render()
}
} catch (ApiException $exception) {
$this->addTplParam('error', $lang->translateString('OSC_PAYPAL_ERROR_' . $exception->getErrorIssue()));
Registry::getLogger()->error($exception->getMessage());
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error($exception->getMessage());
}
} elseif (
$order->getFieldData('oxpaymenttype') == $this->payPalPlusPaymentType &&
Expand Down
24 changes: 17 additions & 7 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,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
Expand Down Expand Up @@ -144,7 +145,9 @@ public function createAcdcOrder(): void

$status = $this->execute();
} catch (\Exception $exception) {
Registry::getLogger()->error($exception->getMessage(), [$exception]);
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error($exception->getMessage(), [$exception]);
$this->outputJson(['acdcerror' => 'failed to execute shop order']);
return;
}
Expand Down Expand Up @@ -173,6 +176,8 @@ public function createAcdcOrder(): void

public function captureAcdcOrder(): void
{
/** @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();
Expand All @@ -183,9 +188,7 @@ 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);

$result = [
'location' => [
Expand Down Expand Up @@ -231,7 +234,7 @@ 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]);
$this->getServiceFromContainer(PaymentService::class)->removeTemporaryOrder();
}

Expand Down Expand Up @@ -270,7 +273,9 @@ public function finalizepaypalsession(): string
$order->finalizeOrderAfterExternalPayment($sessionCheckoutOrderId);
$order->save();
} catch (PayPalException $exception) {
Registry::getLogger()->debug(
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->debug(
'PayPal Checkout error during order finalization ' . $exception->getMessage(),
[$exception]
);
Expand All @@ -294,7 +299,12 @@ public function finalizeacdc(): string
$order->finalizeOrderAfterExternalPayment($sessionAcdcOrderId, $forceFetchDetails);
$goNext = 'thankyou';
} catch (\Exception $exception) {
Registry::getLogger()->error('failure during finalizeOrderAfterExternalPayment', [$exception]);
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error(
'failure during finalizeOrderAfterExternalPayment',
[$exception]
);
$this->cancelpaypalsession('cannot finalize order');
$goNext = 'payment?payerror=2';
}
Expand Down
10 changes: 7 additions & 3 deletions src/Controller/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,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.
Expand Down Expand Up @@ -91,7 +92,9 @@ public function approveOrder()
try {
$response = $service->showOrderDetails($orderId, '');
} catch (Exception $exception) {
Registry::getLogger()->error("Error on order capture call.", [$exception]);
/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');
$logger->error("Error on order capture call.", [$exception]);
}

if (!$this->getUser()) {
Expand Down Expand Up @@ -270,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 :
Expand Down
15 changes: 11 additions & 4 deletions src/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,39 @@
use OxidSolutionCatalysts\PayPal\Core\Webhook\EventVerifier;
use OxidSolutionCatalysts\PayPal\Core\Webhook\EventDispatcher;
use OxidSolutionCatalysts\PayPal\Core\Webhook\RequestHandler as WebhookRequestHandler;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use Psr\Log\LoggerInterface;

/**
* Class WebhookController
* @package OxidSolutionCatalysts\PayPal\Controller
*/
class WebhookController extends WidgetController
{
use ServiceContainer;

/**
* @inheritDoc
*/
public function init()
{
parent::init();

/** @var LoggerInterface $logger */
$logger = $this->getServiceFromContainer('OxidSolutionCatalysts\PayPal\Logger');

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());
$logger->debug('PayPal Webhook headers ' . serialize($requestReader->getHeaders()));

$webhookRequestHandler = new WebhookRequestHandler($requestReader, $verificationService, $dispatcher);
$success = $webhookRequestHandler->process();
$webhookRequestHandler->process();
} catch (\Exception $exception) {
Registry::getLogger()->error($exception->getMessage(), [$exception]);
$logger->error($exception->getMessage(), [$exception]);
$this->sendErrorResponse();
}
//We need to return a 200 if the call could be processed successfully, the otherwise webhook event
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
Loading

0 comments on commit 10c7c61

Please sign in to comment.