Skip to content

Commit

Permalink
Move all Apple Pay-related services under the ApplePayPayment nam…
Browse files Browse the repository at this point in the history
…espace
  • Loading branch information
jakubtobiasz committed Nov 26, 2024
1 parent 7bd4421 commit 3f4c269
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 60 deletions.
2 changes: 1 addition & 1 deletion config/routes_webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Symfony\Component\Routing\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\Controller\InitApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Controller\InitApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\PaymentNotificationAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\TpayNotificationAction;
use CommerceWeavers\SyliusTpayPlugin\Routing;
Expand Down
5 changes: 3 additions & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory;
use Payum\Core\Gateway;

return function(ContainerConfigurator $container): void {
$container->import('services/**/*.php');

$services = $container->services();

$services->set('commerce_weavers_sylius_tpay.gateway', Gateway::class)
$services->set('commerce_weavers_sylius_tpay.apple_pay_gateway', Gateway::class)
->factory([service('payum'), 'getGateway'])
->args(['tpay'])
->args([GatewayFactory::NAME])
;
};
2 changes: 1 addition & 1 deletion config/services/api/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
->args([
service('sylius.repository.order'),
service('sylius.repository.payment'),
service('commerce_weavers_sylius_tpay.gateway'),
service('commerce_weavers_sylius_tpay.apple_pay_gateway'),
service('commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment'),
])
->tag('messenger.message_handler')
Expand Down
18 changes: 18 additions & 0 deletions config/services/apple_pay_payment/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Controller\InitApplePayPaymentAction;

return function(ContainerConfigurator $container): void {
$services = $container->services();

$services->set(InitApplePayPaymentAction::class)
->args([
service('payum'),
])
->tag('controller.service_arguments')
;
};
4 changes: 2 additions & 2 deletions config/services/apple_pay_payment/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory as ApplePayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;

return function(ContainerConfigurator $container): void {
$services = $container->services();
Expand Down
6 changes: 6 additions & 0 deletions config/services/apple_pay_payment/payum/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactory;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder;

return function(ContainerConfigurator $container): void {
Expand All @@ -16,4 +18,8 @@
])
->tag('payum.gateway_factory_builder', ['factory' => GatewayFactory::NAME])
;

$services->set('commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment', InitializeApplePayPaymentFactory::class)
->alias(InitializeApplePayPaymentFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment')
;
};
10 changes: 1 addition & 9 deletions config/services/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use CommerceWeavers\SyliusTpayPlugin\Controller\DisplayThankYouPageAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\DisplayWaitingForPaymentPage;
use CommerceWeavers\SyliusTpayPlugin\Controller\PaymentNotificationAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\InitApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\TpayNotificationAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\RetryPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Controller\TpayNotificationAction;

return function(ContainerConfigurator $container): void {
$services = $container->services();
Expand Down Expand Up @@ -42,13 +41,6 @@
->tag('controller.service_arguments')
;

$services->set(InitApplePayPaymentAction::class)
->args([
service('payum'),
])
->tag('controller.service_arguments')
;

$services->set(PaymentNotificationAction::class)
->args([
service('payum'),
Expand Down
6 changes: 0 additions & 6 deletions config/services/payum/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\NotifyDataFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\NotifyDataFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\NotifyFactory;
Expand Down Expand Up @@ -35,10 +33,6 @@
->alias(CreateTransactionFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.create_transaction')
;

$services->set('commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment', InitializeApplePayPaymentFactory::class)
->alias(InitializeApplePayPaymentFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment')
;

$services->set('commerce_weavers_sylius_tpay.payum.factory.notify_data', NotifyDataFactory::class)
->alias(NotifyDataFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.notify_data')
;
Expand Down
1 change: 0 additions & 1 deletion config/services/refunding.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
$services->set('commerce_weavers_sylius_tpay.refunding.dispatcher.refund', RefundDispatcher::class)
->public()
->args([
service('commerce_weavers_sylius_tpay.gateway'),
service('commerce_weavers_sylius_tpay.refunding.checker.refund_plugin_availability'),
])
->alias(RefundDispatcherInterface::class, 'commerce_weavers_sylius_tpay.refunding.dispatcher.refund')
Expand Down
4 changes: 2 additions & 2 deletions config/validation/Pay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</option>
</constraint>
<property name="applePayToken">
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayConfigTypeEquals">
<option name="paymentMethodType">apple_pay</option>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayNameEquals">
<option name="gatewayName">tpay_apple_pay</option>
<option name="fieldRequiredErrorMessage">commerce_weavers_sylius_tpay.shop.pay.apple_pay_token.required</option>
<option name="groups">
<value>commerce_weavers_sylius_tpay:shop:order:pay</value>
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Command/InitializeApplePaySessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\OrderCannotBeFoundException;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\PaymentCannotBeFoundException;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use Payum\Core\GatewayInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Controller;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Controller;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use Payum\Core\GatewayInterface;
use Payum\Core\Payum;
use Sylius\Component\Core\Model\OrderInterface;
Expand Down Expand Up @@ -53,6 +54,6 @@ public function __invoke(Request $request): Response

private function getGateway(): GatewayInterface
{
return $this->payum->getGateway('tpay');
return $this->payum->getGateway(GatewayFactory::NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\BasePaymentAwareAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\Token\NotifyTokenFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreateApplePayPaymentPayloadFactoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\BasePaymentAwareAction;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreateInitializeApplePayPaymentPayloadFactoryInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Request\Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Factory;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory;

use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use Sylius\Component\Core\Model\PaymentInterface;

final class InitializeApplePayPaymentFactory implements InitializeApplePayPaymentFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Factory;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory;

use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use Sylius\Component\Core\Model\PaymentInterface;

interface InitializeApplePayPaymentFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api;
namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request;

use Payum\Core\Request\Generic;

Expand Down
18 changes: 16 additions & 2 deletions src/Refunding/Dispatcher/RefundDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

use CommerceWeavers\SyliusTpayPlugin\Refunding\Checker\RefundPluginAvailabilityCheckerInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Payum;
use Payum\Core\Request\Refund;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\RefundPlugin\Entity\RefundPaymentInterface;
use Webmozart\Assert\Assert;

final class RefundDispatcher implements RefundDispatcherInterface
{
public function __construct(
private readonly GatewayInterface $gateway,
private readonly Payum $payum,
private readonly RefundPluginAvailabilityCheckerInterface $refundPluginAvailabilityChecker,
) {
}
Expand All @@ -24,7 +27,7 @@ public function dispatch(PaymentInterface|RefundPaymentInterface $payment): void
return;
}

$this->gateway->execute(new Refund($payment));
$this->getGateway($payment)->execute(new Refund($payment));
}

private function checkIfShouldBeDispatched(PaymentInterface|RefundPaymentInterface $payment): bool
Expand All @@ -35,4 +38,15 @@ private function checkIfShouldBeDispatched(PaymentInterface|RefundPaymentInterfa

return (!$isRefundPaymentAvailable && $isPayment) || ($isRefundPaymentAvailable && $isRefundPayment);
}

private function getGateway(PaymentInterface|RefundPaymentInterface $payment): GatewayInterface
{
/** @var PaymentMethodInterface|null $paymentMethod */
$paymentMethod = $payment instanceof PaymentInterface ? $payment->getMethod() : $payment->getPaymentMethod();
$gatewayName = $paymentMethod?->getGatewayConfig()?->getGatewayName();

Assert::notNull($gatewayName);

return $this->payum->getGateway($gatewayName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\PaymentCannotBeFoundException;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\InitializeApplePaySession;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\InitializeApplePaySessionHandler;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use Payum\Core\GatewayInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Action\Api;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\ApplePayPayment\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\Token\NotifyTokenFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreateApplePayPaymentPayloadFactoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Action\Api;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\ApplePayPayment\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Action\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\Tpay\ApplePayApi;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreateInitializeApplePayPaymentPayloadFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\TpayApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Factory;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\ApplePayPayment\Payum\Factory;

use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\InitializeApplePayPayment;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactory;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Request\InitializeApplePayPayment;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Sylius\Component\Core\Model\PaymentInterface;
Expand Down
Loading

0 comments on commit 3f4c269

Please sign in to comment.