From 0226e2f3caff7bfc5dc4bcf88a80d7bba9e1a5af Mon Sep 17 00:00:00 2001 From: Aleksandar Sasa Boljanovic Date: Wed, 21 Feb 2024 17:52:24 +0100 Subject: [PATCH 1/4] Add support for language shops ISSUE: CS-5124 --- Components/CheckoutConfigProvider.php | 14 +++-- .../ShopperReferenceProcessor.php | 5 +- Components/PaymentMeansEnricher.php | 4 +- Controllers/Frontend/AdyenDonations.php | 21 +++++++- Controllers/Frontend/AdyenPaymentProcess.php | 54 +++++++++++++++++-- Subscriber/EnrichPaymentSubscriber.php | 3 +- Utilities/Shop.php | 21 ++++++++ 7 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 Utilities/Shop.php diff --git a/Components/CheckoutConfigProvider.php b/Components/CheckoutConfigProvider.php index a50179cb..68d72f71 100644 --- a/Components/CheckoutConfigProvider.php +++ b/Components/CheckoutConfigProvider.php @@ -13,6 +13,7 @@ use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Models\Country; use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Models\PaymentMethodCode; use Adyen\Core\BusinessLogic\Domain\Payment\Models\MethodAdditionalData\CardConfig; +use AdyenPayment\Utilities\Shop; use Enlight_Components_Session_Namespace; use Shopware\Models\Customer\Customer; @@ -41,7 +42,10 @@ public function __construct(Enlight_Components_Session_Namespace $session) } /** + * @param Amount|null $forceAmount + * * @return Response + * * @throws InvalidCurrencyCode */ public function getCheckoutConfig(?Amount $forceAmount = null): Response @@ -50,7 +54,7 @@ public function getCheckoutConfig(?Amount $forceAmount = null): Response $response = $this->getCheckoutConfigResponse($request, false, static function (PaymentCheckoutConfigRequest $request) { return CheckoutAPI::get() - ->checkoutConfig(Shopware()->Shop()->getId()) + ->checkoutConfig(Shop::getShopId()) ->getPaymentCheckoutConfig($request); }); @@ -71,7 +75,9 @@ public function getCheckoutConfig(?Amount $forceAmount = null): Response /** * @param Amount|null $forceAmount + * * @return Response + * * @throws InvalidCurrencyCode */ public function getExpressCheckoutConfig(Amount $forceAmount): Response @@ -80,7 +86,7 @@ public function getExpressCheckoutConfig(Amount $forceAmount): Response return $this->getCheckoutConfigResponse($request, true, static function (PaymentCheckoutConfigRequest $request) { return CheckoutAPI::get() - ->checkoutConfig(Shopware()->Shop()->getId()) + ->checkoutConfig(Shop::getShopId()) ->getExpressPaymentCheckoutConfig($request); }); } @@ -109,7 +115,7 @@ private function buildConfigRequest(?Amount $forceAmount = null): PaymentCheckou $shop = Shopware()->Shop(); $userId = (int)$this->session->offsetGet('sUserId'); - $shopperReference = ($userId !== 0) ? $shop->getHost() . '_' . $shop->getId() . '_' . $userId : null; + $shopperReference = ($userId !== 0) ? $shop->getHost() . '_' . Shop::getShopId() . '_' . $userId : null; return new PaymentCheckoutConfigRequest( $this->getAmount($forceAmount), @@ -123,7 +129,9 @@ private function buildConfigRequest(?Amount $forceAmount = null): PaymentCheckou * Gets the response from cache or makes the response and cache the result by calling $responseCallback * * @param PaymentCheckoutConfigRequest $request + * @param bool $isExpressCheckout * @param callable $responseCallback + * * @return Response|PaymentCheckoutConfigResponse */ private function getCheckoutConfigResponse( diff --git a/Components/Integration/PaymentProcessors/ShopperReferenceProcessor.php b/Components/Integration/PaymentProcessors/ShopperReferenceProcessor.php index 04dc4a23..01d5c49f 100644 --- a/Components/Integration/PaymentProcessors/ShopperReferenceProcessor.php +++ b/Components/Integration/PaymentProcessors/ShopperReferenceProcessor.php @@ -8,6 +8,7 @@ use Adyen\Core\BusinessLogic\Domain\Integration\Processors\PaymentLinkRequest\ShopperReferenceProcessor as PaymentLinkShopperReferenceProcessorInterface; use Adyen\Core\BusinessLogic\Domain\Multistore\StoreContext; use AdyenPayment\Repositories\Wrapper\OrderRepository; +use AdyenPayment\Utilities\Shop; use Exception; /** @@ -35,7 +36,7 @@ public function __construct(OrderRepository $orderRepository) * @param PaymentLinkRequestContext $context * * @return void - * + * * @throws Exception */ public function processPaymentLink(PaymentLinkRequestBuilder $builder, PaymentLinkRequestContext $context): void @@ -53,7 +54,7 @@ public function processPaymentLink(PaymentLinkRequestBuilder $builder, PaymentLi $builder->setShopperReference( ShopperReference::parse( - $shop->getHost() . '_' . $shop->getId() . '_' . $order->getCustomer()->getId() + $shop->getHost() . '_' . Shop::getShopId() . '_' . $order->getCustomer()->getId() ) ); } diff --git a/Components/PaymentMeansEnricher.php b/Components/PaymentMeansEnricher.php index 16d12694..a22d4ad8 100644 --- a/Components/PaymentMeansEnricher.php +++ b/Components/PaymentMeansEnricher.php @@ -9,6 +9,7 @@ use Adyen\Core\BusinessLogic\Domain\Payment\Models\PaymentMethod; use AdyenPayment\AdyenPayment; use AdyenPayment\Utilities\Plugin; +use AdyenPayment\Utilities\Shop; use DateTime; use Shopware_Components_Snippet_Manager; @@ -49,8 +50,7 @@ public function __construct( */ public function enrich(array $paymentMeans): array { - if (AdminAPI::get()->integration(Shopware()->Shop()->getId())->getState()->toArray( - ) !== StateResponse::dashboard()->toArray()) { + if (AdminAPI::get()->integration(Shop::getShopId())->getState()->toArray() !== StateResponse::dashboard()->toArray()) { $this->removeAdyenPaymentMeans($paymentMeans); return $paymentMeans; diff --git a/Controllers/Frontend/AdyenDonations.php b/Controllers/Frontend/AdyenDonations.php index d3668f00..ed7c1c19 100644 --- a/Controllers/Frontend/AdyenDonations.php +++ b/Controllers/Frontend/AdyenDonations.php @@ -2,8 +2,11 @@ use Adyen\Core\BusinessLogic\CheckoutAPI\CheckoutAPI; use Adyen\Core\BusinessLogic\CheckoutAPI\Donations\Request\MakeDonationRequest; +use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Exceptions\InvalidCurrencyCode; +use Adyen\Core\BusinessLogic\Domain\Connection\Exceptions\ConnectionSettingsNotFountException; use AdyenPayment\Components\ErrorMessageProvider; use AdyenPayment\Controllers\Common\AjaxResponseSetter; +use AdyenPayment\Utilities\Shop; /** * Class Shopware_Controllers_Frontend_AdyenDonations @@ -43,6 +46,7 @@ public function initController($request, $response): void /** * @return void + * * @throws Exception */ public function preDispatch(): void @@ -52,23 +56,36 @@ public function preDispatch(): void $this->snippets = $this->get('snippets'); } + /** + * @return void + * + * @throws ConnectionSettingsNotFountException + * @throws Exception + */ public function getDonationsConfigAction(): void { $merchantReference = $this->Request()->get('merchantReference'); $currencyFactor = Shopware()->Shop()->getCurrency()->getFactor(); $result = CheckoutAPI::get() - ->donation(Shopware()->Shop()->getId()) + ->donation(Shop::getShopId()) ->getDonationSettings($merchantReference, empty($currencyFactor) ? 1 : $currencyFactor); $this->returnAPIResponse($result); } + /** + * @return void + * + * @throws ConnectionSettingsNotFountException + * @throws InvalidCurrencyCode + * @throws Exception + */ public function makeDonationsAction(): void { $params = $this->Request()->getParams(); $result = CheckoutAPI::get() - ->donation(Shopware()->Shop()->getId()) + ->donation(Shop::getShopId()) ->makeDonation( new MakeDonationRequest( $params['amount']['value'] ?? '', diff --git a/Controllers/Frontend/AdyenPaymentProcess.php b/Controllers/Frontend/AdyenPaymentProcess.php index 95d567e5..1f57247c 100644 --- a/Controllers/Frontend/AdyenPaymentProcess.php +++ b/Controllers/Frontend/AdyenPaymentProcess.php @@ -7,6 +7,7 @@ use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Models\Amount\Amount; use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Models\Amount\Currency; use Adyen\Core\BusinessLogic\Domain\Checkout\PaymentRequest\Models\ShopperReference; +use Adyen\Core\BusinessLogic\Domain\Connection\Exceptions\ConnectionSettingsNotFountException; use Adyen\Core\Infrastructure\Logger\Logger; use AdyenPayment\AdyenPayment; use AdyenPayment\Components\CheckoutConfigProvider; @@ -14,6 +15,7 @@ use AdyenPayment\Components\PaymentMeansEnricher; use AdyenPayment\Utilities\Plugin; use AdyenPayment\Utilities\Url; +use AdyenPayment\Utilities\Shop; /** * Class Shopware_Controllers_Frontend_AdyenPaymentProcess @@ -57,6 +59,7 @@ public function initController($request, $response): void /** * @return void + * * @throws Exception */ public function preDispatch(): void @@ -70,7 +73,9 @@ public function preDispatch(): void /** * Main entry point for checkout processing of adyen payment + * * @return void + * * @throws Exception */ public function indexAction(): void @@ -108,7 +113,7 @@ public function indexAction(): void } $response = CheckoutAPI::get() - ->paymentRequest(Shopware()->Shop()->getId()) + ->paymentRequest(Shop::getShopId()) ->startTransaction( new StartTransactionRequest( $paymentMethodType, @@ -189,6 +194,11 @@ public function indexAction(): void $this->view->assign('orderReference', $orderReference); } + /** + * @return void + * + * @throws Exception + */ public function handleAdditionalDataAction(): void { $this->setupRedirectResponse( @@ -196,6 +206,11 @@ public function handleAdditionalDataAction(): void ); } + /** + * @return void + * + * @throws Exception + */ public function handleRedirectAction(): void { Logger::logDebug( @@ -234,6 +249,12 @@ public function getCheckoutConfigAction(): void ); } + /** + * @return void + * + * @throws Enlight_Exception + * @throws ConnectionSettingsNotFountException + */ public function disableCardDetailsAction(): void { $this->Front()->Plugins()->ViewRenderer()->setNoRender(); @@ -281,7 +302,7 @@ public function disableCardDetailsAction(): void $recurringToken ); - $result = CheckoutAPI::get()->checkoutConfig(Shopware()->Shop()->getId())->disableStoredDetails($disableRequest); + $result = CheckoutAPI::get()->checkoutConfig(Shop::getShopId())->disableStoredDetails($disableRequest); if (!$result->isSuccessful()) { $this->Response()->setBody( @@ -297,6 +318,13 @@ public function disableCardDetailsAction(): void $this->Response()->setBody(json_encode(['success' => true])); } + /** + * @param array $additionalData + * + * @return string + * + * @throws Exception + */ private function handleAdditionalDataAndGetRedirectUrl(array $additionalData): string { $basketSignature = $this->Request()->get('signature'); @@ -318,7 +346,7 @@ private function handleAdditionalDataAndGetRedirectUrl(array $additionalData): s } $response = CheckoutAPI::get() - ->paymentRequest(Shopware()->Shop()->getId()) + ->paymentRequest(Shop::getShopId()) ->updatePaymentDetails(array_key_exists('details', $additionalData) ? $additionalData : ['details' => $additionalData]); if (!$response->isSuccessful()) { @@ -342,6 +370,14 @@ private function handleAdditionalDataAndGetRedirectUrl(array $additionalData): s return Url::getFrontUrl('checkout', 'finish', ['sUniqueID' => $orderReference]); } + /** + * @param string $redirectUrl + * + * @return void + * + * @throws Enlight_Exception + * @throws Exception + */ private function setupRedirectResponse(string $redirectUrl) { if ($this->isAjaxRequest()) { @@ -356,11 +392,19 @@ private function setupRedirectResponse(string $redirectUrl) $this->redirect($redirectUrl); } - private function isAjaxRequest() + /** + * @return bool + */ + private function isAjaxRequest(): bool { return $this->Request()->getParam('isXHR') || $this->session->offsetGet('adyenIsXHR'); } + /** + * @param string $basketSignature + * + * @return string + */ private function generateOrderReference(string $basketSignature): string { /** @@ -384,6 +428,6 @@ private function getShopperReference(): ?ShopperReference return null; } - return ShopperReference::parse($shop->getHost() . '_' . $shop->getId() . '_' . $user); + return ShopperReference::parse($shop->getHost() . '_' . Shop::getShopId() . '_' . $user); } } diff --git a/Subscriber/EnrichPaymentSubscriber.php b/Subscriber/EnrichPaymentSubscriber.php index 2e08329e..d2ec5369 100755 --- a/Subscriber/EnrichPaymentSubscriber.php +++ b/Subscriber/EnrichPaymentSubscriber.php @@ -10,6 +10,7 @@ use Adyen\Core\Infrastructure\ServiceRegister; use AdyenPayment\AdyenPayment; use AdyenPayment\Components\PaymentMeansEnricher; +use AdyenPayment\Utilities\Shop; use Enlight\Event\SubscriberInterface; use Enlight_Event_EventArgs; use Exception; @@ -83,7 +84,7 @@ private function isCreditCardEnabled(): bool $repository = ServiceRegister::getService(PaymentMethodConfigRepository::class); $cardConfig = StoreContext::doWithStore( - '' . Shopware()->Shop()->getId(), + '' . Shop::getShopId(), [$repository, 'getPaymentMethodByCode'], [(string)PaymentMethodCode::scheme()] ); diff --git a/Utilities/Shop.php b/Utilities/Shop.php new file mode 100644 index 00000000..c634d93d --- /dev/null +++ b/Utilities/Shop.php @@ -0,0 +1,21 @@ +Shop()->getMain() ? Shopware()->Shop()->getMain()->getId() : Shopware()->Shop()->getId(); + } +} From fa345ffef3d056cf962e0ea05ab44504b0cf78c4 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasa Boljanovic Date: Thu, 22 Feb 2024 17:01:37 +0100 Subject: [PATCH 2/4] Implement waking up task runner when Adyen plugin page is opened ISSUE: CS-5139 --- Controllers/Backend/AdyenState.php | 31 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Controllers/Backend/AdyenState.php b/Controllers/Backend/AdyenState.php index e75403ae..1e548b81 100644 --- a/Controllers/Backend/AdyenState.php +++ b/Controllers/Backend/AdyenState.php @@ -1,6 +1,8 @@ Request()->get('storeId'); - $result = AdminAPI::get()->integration($storeId)->getState(); + /** + * @return void + */ + public function indexAction(): void + { + $storeId = $this->Request()->get('storeId'); + $result = AdminAPI::get()->integration($storeId)->getState(); + $this->getTaskRunnerWakeUp()->wakeup(); - $this->returnAPIResponse($result); - } + $this->returnAPIResponse($result); + } + + /** + * @return TaskRunnerWakeup + */ + private function getTaskRunnerWakeUp(): TaskRunnerWakeup + { + return ServiceRegister::getService(TaskRunnerWakeup::CLASS_NAME); + } } From 5afba163e7619226a49be576942ffae8678977b5 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasa Boljanovic Date: Mon, 26 Feb 2024 12:24:30 +0100 Subject: [PATCH 3/4] Update core --- composer.json | 2 +- composer.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 43064c1e..c9432b85 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "php": "^7.2|^7.4|^8.0", "ext-json": "*", "ext-zip": "*", - "adyen/integration-core": "1.1.8", + "adyen/integration-core": "1.1.9", "ext-simplexml": "*" }, "minimum-stability": "dev", diff --git a/composer.lock b/composer.lock index 3c87b173..bd69d2b4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "83237bc9c335cf6ebe15859f8c79aa83", + "content-hash": "7ebea60d376ed6f14e2f24f7187e240a", "packages": [ { "name": "adyen/integration-core", - "version": "1.1.8", + "version": "1.1.9", "source": { "type": "git", "url": "git@github.com:Adyen/adyen-php-plugin-core.git", - "reference": "3ab6c5121c9f8533959f0b9273b14cb29cbe4cf2" + "reference": "275f246045b0d394517f39de8f48bfe2f02ce59c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Adyen/adyen-php-plugin-core/zipball/3ab6c5121c9f8533959f0b9273b14cb29cbe4cf2", - "reference": "3ab6c5121c9f8533959f0b9273b14cb29cbe4cf2", + "url": "https://api.github.com/repos/Adyen/adyen-php-plugin-core/zipball/275f246045b0d394517f39de8f48bfe2f02ce59c", + "reference": "275f246045b0d394517f39de8f48bfe2f02ce59c", "shasum": "" }, "require": { @@ -48,7 +48,7 @@ "proprietary" ], "description": "Core Adyen integration library", - "time": "2024-02-02T14:24:41+00:00" + "time": "2024-02-26T09:50:59+00:00" }, { "name": "adyen/php-webhook-module", From 26492df829887b5ba66d4365e50c9f22fa797abc Mon Sep 17 00:00:00 2001 From: Aleksandar Sasa Boljanovic Date: Mon, 26 Feb 2024 12:25:44 +0100 Subject: [PATCH 4/4] Release 4.1.7 --- plugin.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index f75330b1..27e7aef7 100644 --- a/plugin.xml +++ b/plugin.xml @@ -4,7 +4,7 @@ - 4.1.6 + 4.1.7 Adyen Adyen https://adyen.com @@ -693,4 +693,14 @@ * Fix displaying original PSP reference on order details page + + + * Add support for language shops + * Wake Task runner when Adyen page is opened + + + * Add support for language shops + * Wake Task runner when Adyen page is opened + +