Skip to content

Commit

Permalink
Merge pull request #568 from Adyen/develop-3
Browse files Browse the repository at this point in the history
Release version 3.16.3
  • Loading branch information
goran-stamenkovski-logeecom authored Oct 15, 2024
2 parents ee350e5 + 67b632f commit b7865db
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/templates/docker-compose.playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
playwright:
image: mcr.microsoft.com/playwright:v1.47.0-focal
image: mcr.microsoft.com/playwright:v1.48.0-focal
networks:
- localnetwork
shm_size: 1gb
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"description": "Official Shopware 6 Plugin to connect to Payment Service Provider Adyen",
"version": "3.16.2",
"version": "3.16.3",
"type": "shopware-platform-plugin",
"license": "MIT",
"require": {
Expand Down
7 changes: 4 additions & 3 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public function __construct(
}

/**
* @Route(path="/api/_action/adyen/verify")
* @Route(path="/api/_action/adyen/verify",
* name="api.action.adyen.verify", methods={"GET", "POST"})
*
* @param RequestDataBag $dataBag
* @return JsonResponse
Expand Down Expand Up @@ -311,7 +312,7 @@ public function isManualCaptureEnabled(string $orderId)
if (is_null($orderTransaction)) {
return new JsonResponse(false);
}

$paymentMethodHandlerIdentifier = $orderTransaction->getPaymentMethod()->getHandlerIdentifier();

return new JsonResponse(
Expand Down Expand Up @@ -410,7 +411,7 @@ public function getRefunds(string $orderId): JsonResponse
* @Route(
* "/api/adyen/orders/{orderId}/notifications",
* methods={"GET"}
* )
* )
* @param string $orderId
* @return JsonResponse
*/
Expand Down
20 changes: 13 additions & 7 deletions src/Controller/StoreApi/Payment/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
use Shopware\Core\Checkout\Order\SalesChannel\SetPaymentOrderRouteResponse;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\StateMachine\Loader\InitialStateIdLoader;
use Shopware\Core\System\StateMachine\StateMachineRegistry;
use Shopware\Core\System\StateMachine\Transition;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -114,9 +115,9 @@ class PaymentController
*/
private $orderTransactionStateHandler;
/**
* @var InitialStateIdLoader
* @var EntityRepository
*/
private $initialStateIdLoader;
private $stateMachineRepo;

/**
* StoreApiController constructor.
Expand All @@ -130,7 +131,7 @@ class PaymentController
* @param OrderRepository $orderRepository
* @param OrderService $orderService
* @param StateMachineRegistry $stateMachineRegistry
* @param InitialStateIdLoader $initialStateIdLoader
* @param EntityRepository $stateMachineRepo
* @param EntityRepository $orderTransactionRepository
* @param ConfigurationService $configurationService
* @param OrderTransactionStateHandler $orderTransactionStateHandler
Expand All @@ -146,7 +147,7 @@ public function __construct(
OrderRepository $orderRepository,
OrderService $orderService,
StateMachineRegistry $stateMachineRegistry,
InitialStateIdLoader $initialStateIdLoader,
EntityRepository $stateMachineRepo,
EntityRepository $orderTransactionRepository,
ConfigurationService $configurationService,
OrderTransactionStateHandler $orderTransactionStateHandler,
Expand All @@ -164,7 +165,7 @@ public function __construct(
$this->orderTransactionRepository = $orderTransactionRepository;
$this->configurationService = $configurationService;
$this->orderTransactionStateHandler = $orderTransactionStateHandler;
$this->initialStateIdLoader = $initialStateIdLoader;
$this->stateMachineRepo = $stateMachineRepo;
$this->logger = $logger;
}

Expand Down Expand Up @@ -346,7 +347,12 @@ private function setPaymentMethod(
SalesChannelContext $salesChannelContext
): void {
$context = $salesChannelContext->getContext();
$initialStateId = $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE);
$criteria = new Criteria();
$criteria->addFilter(
new EqualsFilter('technicalName', OrderTransactionStates::STATE_MACHINE)
);

$initialStateId = $this->stateMachineRepo->search($criteria, $context)->first()->getInitialStateId();

/** @var OrderEntity $order */
$order = $this->orderRepository->getOrder($orderId, $context, ['transactions']);
Expand Down
9 changes: 3 additions & 6 deletions src/Handlers/AbstractPaymentMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,9 @@ protected function preparePaymentsRequest(
$paymentRequest->setLineItems($lineItems);
}

//Setting info from statedata additionalData if present
if (!empty($stateDataAdditionalData['origin'])) {
$origin = $stateDataAdditionalData['origin'];
} else {
$origin = $this->salesChannelRepository->getCurrentDomainUrl($salesChannelContext);
}
$origin = $stateDataAdditionalData['origin'] ??
$request['origin'] ??
$this->salesChannelRepository->getCurrentDomainUrl($salesChannelContext);

$paymentRequest->setOrigin($origin);
$paymentRequest->setAdditionaldata(['allow3DS2' => true]);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/app/storefront/dist/storefront/js/adyen-payment-shopware6.js
100644 → 100755

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ export default class ConfirmOrderPlugin extends Plugin {
return;
}

if(order.url){
location.href = order.url;

return;
}

this.orderId = order.id;
this.finishUrl = new URL(
location.origin + adyenCheckoutOptions.paymentFinishUrl);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<argument type="service" id="Adyen\Shopware\Service\Repository\OrderRepository"/>
<argument type="service" id="Shopware\Core\Checkout\Order\SalesChannel\OrderService"/>
<argument type="service" id="Shopware\Core\System\StateMachine\StateMachineRegistry"/>
<argument type="service" id="Shopware\Core\System\StateMachine\Loader\InitialStateIdLoader"/>
<argument type="service" id="state_machine.repository"/>
<argument type="service" id="order_transaction.repository"/>
<argument type="service" id="Adyen\Shopware\Service\ConfigurationService"/>
<argument type="service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
name="paymentMethodId"
value="{{ payment.id }}"
{% if payment.id is same as(selectedPaymentMethodId) %}checked="checked"{% endif %}
{% if page.isPaymentChangeable is defined and not page.isPaymentChangeable %}
disabled="disabled"
{% endif %}
class="{{ formCheckInputClass ?? 'form-check-input' }} payment-method-input {% if 'handler_adyen_' in payment.formattedHandlerIdentifier %}adyen-payment-method-input-radio{% endif %}">
{% if page.isPaymentChangeable is defined and not page.isPaymentChangeable %}
disabled="disabled"
{% endif %}
class="{{ formCheckInputClass ?? 'form-check-input' }} custom-control-input payment-method-input {% if 'handler_adyen_' in payment.formattedHandlerIdentifier %}adyen-payment-method-input-radio{% endif %}">
{% endblock %}

{% block component_payment_method_description %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{% block page_account_order_item_detail_table_labels_summary %}
{{ parent() }}
{% if actionType === 'voucher' %}
{% if actionType == 'voucher' %}
<dl class="adyen-voucher-details" data-orderId = "{{ orderId }}">
<div class="voucher-detail">
<dt>Voucher reference:</dt>
Expand Down
8 changes: 4 additions & 4 deletions src/Service/PaymentMethodsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use Adyen\Shopware\Util\Currency;
use Psr\Log\LoggerInterface;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
use Shopware\Core\Framework\Adapter\Cache\CacheCompressor;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Contracts\Cache\CacheInterface;

Expand Down Expand Up @@ -96,7 +96,7 @@ public function __construct(
ConfigurationService $configurationService,
Currency $currency,
CartService $cartService,
CacheInterface $cache,
$cache,
SalesChannelRepository $salesChannelRepository,
OrderRepository $orderRepository
) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getPaymentMethods(SalesChannelContext $context, $orderId = ''):
$paymentMethodsResponseCache = $this->cache->getItem($cacheKey);

if ($paymentMethodsResponseCache->isHit() && $paymentMethodsResponseCache->get()) {
return CacheValueCompressor::uncompress($paymentMethodsResponseCache->get());
return CacheCompressor::uncompress($paymentMethodsResponseCache);
}

$responseData = new PaymentMethodsResponse();
Expand All @@ -135,7 +135,7 @@ public function getPaymentMethods(SalesChannelContext $context, $orderId = ''):

$responseData = $paymentsApiService->paymentMethods(new PaymentMethodsRequest($requestData));

$paymentMethodsResponseCache->set(CacheValueCompressor::compress($responseData));
$paymentMethodsResponseCache = CacheCompressor::compress($paymentMethodsResponseCache, $responseData);
$this->cache->save($paymentMethodsResponseCache);
} catch (AdyenException $e) {
$this->logger->error($e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/Service/RefundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ public function getAdyenOrderTransactionForRefund(OrderEntity $order, array $sta
* @return array
*/
public function getRefundRequest(
mixed $requestRefundAmount,
$requestRefundAmount,
string $currencyCode,
mixed $merchantAccount,
$merchantAccount,
string $pspReference,
array $idempotencyExtraData = null
): array {
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Repository/SalesChannelRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SalesChannelRepository
*/
public function __construct(
EntityRepository $domainRepository,
EntityRepository $salesChannelRepository,
$salesChannelRepository,
ConfigurationService $configurationService,
EntityRepository $languageRepository
) {
Expand Down
25 changes: 23 additions & 2 deletions src/Storefront/Controller/FrontendProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
use Adyen\Shopware\Controller\StoreApi\OrderApi\OrderApiController;
use Adyen\Shopware\Controller\StoreApi\Payment\PaymentController;
use Adyen\Shopware\Exception\ValidationException;
use Error;
use Shopware\Core\Checkout\Cart\Exception\InvalidCartException;
use Shopware\Core\Checkout\Cart\SalesChannel\AbstractCartOrderRoute;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Order\Exception\EmptyCartException;
use Shopware\Core\Checkout\Order\SalesChannel\SetPaymentOrderRouteResponse;
use Shopware\Core\Checkout\Payment\SalesChannel\AbstractHandlePaymentMethodRoute;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
Expand All @@ -41,6 +44,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
Expand Down Expand Up @@ -135,9 +139,26 @@ public function switchContext(RequestDataBag $data, SalesChannelContext $context
public function checkoutOrder(RequestDataBag $data, SalesChannelContext $salesChannelContext): JsonResponse
{
$cart = $this->cartService->getCart($salesChannelContext->getToken(), $salesChannelContext);
$order = $this->cartOrderRoute->order($cart, $salesChannelContext, $data)->getOrder();
try {
$order = $this->cartOrderRoute->order($cart, $salesChannelContext, $data)->getOrder();

return new JsonResponse(['id' => $order->getId()]);
return new JsonResponse(['id' => $order->getId()]);
} catch (InvalidCartException|Error|EmptyCartException $exception) {
$this->addCartErrors(
$this->cartService->getCart($salesChannelContext->getToken(), $salesChannelContext)
);

return new JsonResponse(
[
'url' => $this->generateUrl(
'frontend.checkout.cart.page',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
],
400
);
}
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Subscriber/ContextSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Adyen\Shopware\Service\PaymentStateDataService;
use Adyen\Shopware\Struct\AdyenContextDataStruct;
use Adyen\Shopware\Util\Currency;
use Shopware\Core\Checkout\Cart\AbstractCartPersister;
use Shopware\Core\Checkout\Cart\CartCalculator;
use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent;
use Shopware\Core\System\SalesChannel\Event\SalesChannelContextRestoredEvent;
Expand All @@ -41,7 +40,7 @@ class ContextSubscriber implements EventSubscriberInterface
private ConfigurationService $configurationService;
private PaymentStateDataService $paymentStateDataService;
private AbstractContextSwitchRoute $contextSwitchRoute;
private AbstractCartPersister $cartPersister;
private $cartPersister;
private CartCalculator $cartCalculator;
private Currency $currency;

Expand All @@ -50,7 +49,7 @@ public function __construct(
ConfigurationService $configurationService,
PaymentStateDataService $paymentStateDataService,
AbstractContextSwitchRoute $contextSwitchRoute,
AbstractCartPersister $cartPersister,
$cartPersister,
CartCalculator $cartCalculator,
Currency $currency
) {
Expand All @@ -74,7 +73,7 @@ public static function getSubscribedEvents()
public function onContextRestored(SalesChannelContextRestoredEvent $event): void
{
$token = $event->getRestoredSalesChannelContext()->getToken();
$oldToken = $event->getCurrentSalesChannelContext()->getToken();
$oldToken = $_SESSION['_sf2_attributes']['sw-context-token'];

$stateData = $this->paymentStateDataService->fetchRedeemedGiftCardsFromContextToken($oldToken);
foreach ($stateData->getElements() as $statedataArray) {
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber/PaymentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function __construct(
ConfigurationService $configurationService,
PaymentMethodsService $paymentMethodsService,
RequestStack $requestStack,
AbstractCartPersister $cartPersister,
$cartPersister,
CartCalculator $cartCalculator,
AbstractContextSwitchRoute $contextSwitchRoute,
AbstractSalesChannelContextFactory $salesChannelContextFactory,
Expand Down
3 changes: 2 additions & 1 deletion src/Util/CheckoutStateDataValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class CheckoutStateDataValidator
'storePaymentMethod',
'conversionId',
'paymentData',
'details'
'details',
'origin'
);

/**
Expand Down

0 comments on commit b7865db

Please sign in to comment.