Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Tpay Apple Pay as a separate payment method #205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/config/sylius_fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@
'apple_pay' => [
'code' => 'tpay_apple_pay',
'name' => 'Apple Pay (Tpay)',
'gatewayFactory' => 'tpay',
'gatewayName' => 'tpay',
'gatewayConfig' => $tpayConfig + ['type' => PaymentType::APPLE_PAY],
'gatewayFactory' => 'tpay_apple_pay',
'gatewayName' => 'tpay_apple_pay',
'gatewayConfig' => $tpayConfig,
'channels' => [
'FASHION_WEB',
],
Expand Down
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
9 changes: 0 additions & 9 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

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)
->factory([service('payum'), 'getGateway'])
->args(['tpay'])
;
};
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('payum'),
service('commerce_weavers_sylius_tpay.payum.factory.initialize_apple_pay_payment'),
])
->tag('messenger.message_handler')
Expand Down
19 changes: 19 additions & 0 deletions config/services/apple_pay_payment/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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'),
service('sylius.context.cart.composite'),
])
->tag('controller.service_arguments')
;
};
9 changes: 9 additions & 0 deletions config/services/apple_pay_payment/form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function(ContainerConfigurator $container): void {
$container->import('form/**/*.php');
};
19 changes: 19 additions & 0 deletions config/services/apple_pay_payment/form/type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;


use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Form\Type\GatewayConfigurationType;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory;

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

$services->set('commerce_weavers_sylius_tpay.apple_pay_payment.form.type.gateway_configuration', GatewayConfigurationType::class)
->parent('commerce_weavers_sylius_tpay.form.type.abstract_tpay_gateway_configuration')
->tag('sylius.gateway_configuration_type', ['label' => 'commerce_weavers_sylius_tpay.admin.gateway_name.tpay_apple_pay', 'type' => GatewayFactory::NAME])
->tag('form.type')
;
};
9 changes: 9 additions & 0 deletions config/services/apple_pay_payment/payum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function(ContainerConfigurator $container): void {
$container->import('payum/**/*.php');
};
32 changes: 32 additions & 0 deletions config/services/apple_pay_payment/payum/action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

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;

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

$services->defaults()
->public()
;

$services->set(CreateApplePayTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_apple_pay_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
])
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.create_apple_pay_transaction'])
;

$services->set(InitializeApplePayPaymentAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_initialize_apple_pay_payment_payload'),
])
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.initialize_apple_pay_payment'])
;
};
25 changes: 25 additions & 0 deletions config/services/apple_pay_payment/payum/factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

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 {
$services = $container->services();

$services->set('commerce_weavers_sylius_tpay.apple_pay_payment.payum.factory.gateway', GatewayFactoryBuilder::class)
->args([
GatewayFactory::class,
])
->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
26 changes: 8 additions & 18 deletions config/services/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory as ApplePayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Payum\Factory\GatewayFactory as BlikGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Payum\Factory\GatewayFactory as CardGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GatewayFactory as PayByLinkGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\RedirectPayment\Payum\Factory\GatewayFactory as RedirectGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateVisaMobileTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\NotifyAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\CaptureAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\GetStatusAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\PartialRefundAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\RefundAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\ResolveNextRouteAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\TpayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\RedirectPayment\Payum\Factory\GatewayFactory as RedirectGatewayFactory;

return static function(ContainerConfigurator $container): void {
$services = $container->services();
Expand All @@ -30,21 +29,14 @@
->args([
service('commerce_weavers_sylius_tpay.payum.factory.create_transaction'),
])
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.capture'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.capture'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.capture'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.capture'])
->tag('payum.action', ['factory' => RedirectGatewayFactory::NAME, 'alias' => 'cw.tpay_redirect.capture'])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.capture'])
;

$services->set(CreateApplePayTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_apple_pay_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.create_apple_pay_transaction'])
;

$services->set(CreateGooglePayTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_google_pay_payment_payload'),
Expand All @@ -67,6 +59,7 @@
service('commerce_weavers_sylius_tpay.tpay.security.notification.verifier.checksum'),
service('commerce_weavers_sylius_tpay.tpay.security.notification.verifier.signature'),
])
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.notify'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.notify'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.notify'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.notify'])
Expand All @@ -75,6 +68,7 @@
;

$services->set(GetStatusAction::class)
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.get_status'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.get_status'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.get_status'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.get_status'])
Expand All @@ -83,6 +77,7 @@
;

$services->set(PartialRefundAction::class)
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.partial_refund'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.partial_refund'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.partial_refund'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.partial_refund'])
Expand All @@ -91,21 +86,16 @@
;

$services->set(RefundAction::class)
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.refund'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.refund'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.refund'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.refund'])
->tag('payum.action', ['factory' => RedirectGatewayFactory::NAME, 'alias' => 'cw.tpay_redirect.refund'])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.refund'])
;

$services->set(InitializeApplePayPaymentAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_initialize_apple_pay_payment_payload'),
])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.initialize_apple_pay_payment'])
;

$services->set(ResolveNextRouteAction::class)
->tag('payum.action', ['factory' => ApplePayGatewayFactory::NAME, 'alias' => 'cw.tpay_apple_pay.resolve_next_route'])
->tag('payum.action', ['factory' => BlikGatewayFactory::NAME, 'alias' => 'cw.tpay_blik.resolve_next_route'])
->tag('payum.action', ['factory' => CardGatewayFactory::NAME, 'alias' => 'cw.tpay_card.resolve_next_route'])
->tag('payum.action', ['factory' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.resolve_next_route'])
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
13 changes: 10 additions & 3 deletions src/Api/Command/InitializeApplePaySessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\OrderCannotBeFoundException;
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\PaymentCannotBeFoundException;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\GatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Payum;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
Expand All @@ -22,7 +24,7 @@ final class InitializeApplePaySessionHandler
public function __construct(
private readonly OrderRepositoryInterface $orderRepository,
private readonly PaymentRepositoryInterface $paymentRepository,
private readonly GatewayInterface $gateway,
private readonly Payum $payum,
private readonly InitializeApplePayPaymentFactoryInterface $initializeApplePayPaymentFactory,
) {
}
Expand All @@ -32,7 +34,7 @@ public function __invoke(InitializeApplePaySession $command): InitializeApplePay
$order = $this->findOrderOr404($command->orderToken);
$payment = $this->findPaymentOr404($order, $command->paymentId);

$this->gateway->execute(
$this->getGateway()->execute(
$this->initializeApplePayPaymentFactory->createNewWithModelAndOutput(
$payment,
$command->domainName,
Expand Down Expand Up @@ -74,4 +76,9 @@ private function findPaymentOr404(OrderInterface $order, int $paymentId): Paymen

return $payment;
}

private function getGateway(): GatewayInterface
{
return $this->payum->getGateway(GatewayFactory::NAME);
}
}
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);
}
}
Loading
Loading