From 253d10dbf976dfdccc8ebcae2d971104a9b676e9 Mon Sep 17 00:00:00 2001 From: Jacob Tobiasz Date: Tue, 26 Nov 2024 18:10:09 +0100 Subject: [PATCH] Extract Tpay Apple Pay as a separate payment method --- config/config/sylius_fixtures.php | 6 ++-- .../services/apple_pay_payment/controller.php | 19 +++++++++++ config/services/apple_pay_payment/form.php | 9 ++++++ .../services/apple_pay_payment/form/type.php | 19 +++++++++++ config/services/apple_pay_payment/payum.php | 9 ++++++ .../apple_pay_payment/payum/action.php | 32 +++++++++++++++++++ .../apple_pay_payment/payum/factory.php | 19 +++++++++++ config/services/payum/action.php | 26 +++++---------- .../Form/Type/GatewayConfigurationType.php | 29 +++++++++++++++++ .../Payum/Factory/GatewayFactory.php | 17 ++++++++++ .../Checkout/Complete/_navigation.html.twig | 4 +-- .../shop/cart/complete/_apple_pay.html.twig | 4 +-- .../complete/_apple_pay_regulations.html.twig | 5 +-- .../shop/paying_for_orders_by_apple_pay.yml | 5 ++- 14 files changed, 170 insertions(+), 33 deletions(-) create mode 100644 config/services/apple_pay_payment/controller.php create mode 100644 config/services/apple_pay_payment/form.php create mode 100644 config/services/apple_pay_payment/form/type.php create mode 100644 config/services/apple_pay_payment/payum.php create mode 100644 config/services/apple_pay_payment/payum/action.php create mode 100644 config/services/apple_pay_payment/payum/factory.php create mode 100644 src/ApplePayPayment/Form/Type/GatewayConfigurationType.php create mode 100644 src/ApplePayPayment/Payum/Factory/GatewayFactory.php diff --git a/config/config/sylius_fixtures.php b/config/config/sylius_fixtures.php index 528377a9..2847d0a4 100644 --- a/config/config/sylius_fixtures.php +++ b/config/config/sylius_fixtures.php @@ -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', ], diff --git a/config/services/apple_pay_payment/controller.php b/config/services/apple_pay_payment/controller.php new file mode 100644 index 00000000..5d4c855c --- /dev/null +++ b/config/services/apple_pay_payment/controller.php @@ -0,0 +1,19 @@ +services(); + + $services->set(InitApplePayPaymentAction::class) + ->args([ + service('payum'), + service('sylius.context.cart.composite'), + ]) + ->tag('controller.service_arguments') + ; +}; diff --git a/config/services/apple_pay_payment/form.php b/config/services/apple_pay_payment/form.php new file mode 100644 index 00000000..0c78f855 --- /dev/null +++ b/config/services/apple_pay_payment/form.php @@ -0,0 +1,9 @@ +import('form/**/*.php'); +}; diff --git a/config/services/apple_pay_payment/form/type.php b/config/services/apple_pay_payment/form/type.php new file mode 100644 index 00000000..78cf7728 --- /dev/null +++ b/config/services/apple_pay_payment/form/type.php @@ -0,0 +1,19 @@ +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') + ; +}; diff --git a/config/services/apple_pay_payment/payum.php b/config/services/apple_pay_payment/payum.php new file mode 100644 index 00000000..32161d65 --- /dev/null +++ b/config/services/apple_pay_payment/payum.php @@ -0,0 +1,9 @@ +import('payum/**/*.php'); +}; diff --git a/config/services/apple_pay_payment/payum/action.php b/config/services/apple_pay_payment/payum/action.php new file mode 100644 index 00000000..493d52f3 --- /dev/null +++ b/config/services/apple_pay_payment/payum/action.php @@ -0,0 +1,32 @@ +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']) + ; +}; diff --git a/config/services/apple_pay_payment/payum/factory.php b/config/services/apple_pay_payment/payum/factory.php new file mode 100644 index 00000000..4161992b --- /dev/null +++ b/config/services/apple_pay_payment/payum/factory.php @@ -0,0 +1,19 @@ +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]) + ; +}; diff --git a/config/services/payum/action.php b/config/services/payum/action.php index f9da2129..94f96044 100644 --- a/config/services/payum/action.php +++ b/config/services/payum/action.php @@ -4,14 +4,12 @@ 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; @@ -19,6 +17,7 @@ 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(); @@ -30,6 +29,7 @@ ->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']) @@ -37,14 +37,6 @@ ->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'), @@ -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']) @@ -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']) @@ -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']) @@ -91,6 +86,7 @@ ; $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']) @@ -98,14 +94,8 @@ ->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']) diff --git a/src/ApplePayPayment/Form/Type/GatewayConfigurationType.php b/src/ApplePayPayment/Form/Type/GatewayConfigurationType.php new file mode 100644 index 00000000..dcd9d9c9 --- /dev/null +++ b/src/ApplePayPayment/Form/Type/GatewayConfigurationType.php @@ -0,0 +1,29 @@ +add( + 'apple_pay_merchant_id', + TextType::class, + [ + 'empty_data' => '', + 'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.apple_pay_merchant_id', + 'required' => true, + ], + ) + ; + } +} diff --git a/src/ApplePayPayment/Payum/Factory/GatewayFactory.php b/src/ApplePayPayment/Payum/Factory/GatewayFactory.php new file mode 100644 index 00000000..1fa1c00d --- /dev/null +++ b/src/ApplePayPayment/Payum/Factory/GatewayFactory.php @@ -0,0 +1,17 @@ + @@ -15,4 +16,3 @@ {% endif %} {# SyliusTpayPlugin customization <<< #} - diff --git a/templates/shop/cart/complete/_apple_pay.html.twig b/templates/shop/cart/complete/_apple_pay.html.twig index b58d19a4..2c8eb50e 100644 --- a/templates/shop/cart/complete/_apple_pay.html.twig +++ b/templates/shop/cart/complete/_apple_pay.html.twig @@ -1,6 +1,4 @@ -{% if payment is not null and - cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'type') == constant('CommerceWeavers\\SyliusTpayPlugin\\Tpay\\PaymentType::APPLE_PAY') -%} +{% if payment is not null and payment.method.gatewayConfig.gatewayName == 'tpay_apple_pay' %} diff --git a/templates/shop/cart/complete/_apple_pay_regulations.html.twig b/templates/shop/cart/complete/_apple_pay_regulations.html.twig index 255b30e5..11c128f5 100644 --- a/templates/shop/cart/complete/_apple_pay_regulations.html.twig +++ b/templates/shop/cart/complete/_apple_pay_regulations.html.twig @@ -1,9 +1,6 @@ {% set payment = order.lastCartPayment() %} -{% if payment is not null and - cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'type') == - constant('CommerceWeavers\\SyliusTpayPlugin\\Tpay\\PaymentType::APPLE_PAY') -%} +{% if payment is not null and payment.method.gatewayConfig.gatewayName == 'tpay_apple_pay' %}
diff --git a/tests/Api/DataFixtures/shop/paying_for_orders_by_apple_pay.yml b/tests/Api/DataFixtures/shop/paying_for_orders_by_apple_pay.yml index 868bf118..5e0d8c44 100644 --- a/tests/Api/DataFixtures/shop/paying_for_orders_by_apple_pay.yml +++ b/tests/Api/DataFixtures/shop/paying_for_orders_by_apple_pay.yml @@ -14,15 +14,14 @@ Sylius\Component\Core\Model\PaymentMethod: Sylius\Bundle\PayumBundle\Model\GatewayConfig: gateway_tpay_apple_pay: - gatewayName: 'tpay' - factoryName: 'tpay' + gatewayName: 'tpay_apple_pay' + factoryName: 'tpay_apple_pay' config: client_id: 'encrypted_' client_secret: 'encrypted_' notification_security_code: 'encrypted_' merchant_id: 'encrypted_' apple_pay_merchant_id: 'encrypted_' - type: 'apple_pay' production_mode: false encrypted: true