Skip to content

Commit

Permalink
Extract Tpay Apple Pay as a separate payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Nov 26, 2024
1 parent fba6100 commit 253d10d
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 33 deletions.
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
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\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();

$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'])
;
};
19 changes: 19 additions & 0 deletions config/services/apple_pay_payment/payum/factory.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\Payum\Factory\GatewayFactory;
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])
;
};
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
29 changes: 29 additions & 0 deletions src/ApplePayPayment/Form/Type/GatewayConfigurationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Form\Type;

use CommerceWeavers\SyliusTpayPlugin\Form\Type\AbstractTpayGatewayConfigurationType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class GatewayConfigurationType extends AbstractTpayGatewayConfigurationType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
parent::buildForm($builder, $options);

$builder
->add(
'apple_pay_merchant_id',
TextType::class,
[
'empty_data' => '',
'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.apple_pay_merchant_id',
'required' => true,
],
)
;
}
}
17 changes: 17 additions & 0 deletions src/ApplePayPayment/Payum/Factory/GatewayFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\ApplePayPayment\Payum\Factory;

use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\TpayGatewayFactory;

final class GatewayFactory extends TpayGatewayFactory
{
public const NAME = 'tpay_apple_pay';

public function getName(): string
{
return self::NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
{% if payment is null %}
{% set payment_type = null %}
{% else %}
{% set gateway_name = payment.method.gatewayConfig.gatewayName %}
{% set payment_type = cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'type') %}
{% endif %}

{% if payment_type in ['apple_pay', 'google_pay'] %}
{% if payment_type in ['google_pay'] or gateway_name in ['tpay_apple_pay'] %}
{{ sylius_template_event('cw.tpay.shop.checkout.complete.navigation', { form, order, payment }) }}
{% else %}
<button type="submit" class="ui huge primary fluid icon labeled button" {{ sylius_test_html_attribute('confirmation-button') }}>
<i class="check icon"></i> {{ 'sylius.ui.place_order'|trans }}
</button>
{% endif %}
{# SyliusTpayPlugin customization <<< #}

4 changes: 1 addition & 3 deletions templates/shop/cart/complete/_apple_pay.html.twig
Original file line number Diff line number Diff line change
@@ -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' %}
<input type="hidden" data-apple-pay-amount value="{{ order.total|cw_tpay_convert_minor_to_major_currency }}">
<input type="hidden" data-apple-pay-merchant-identifier value="{{ cw_tpay_get_gateway_config_value(payment.method.gatewayConfig, 'apple_pay_merchant_id') }}">
<input type="hidden" data-apple-pay-currency value="{{ order.currencyCode }}">
Expand Down
Original file line number Diff line number Diff line change
@@ -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' %}
<div class="ui stackable grid">
<div class="ui column eight wide">
<div class="content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_<getenv("TPAY_CLIENT_ID")>'
client_secret: 'encrypted_<getenv("TPAY_CLIENT_SECRET")>'
notification_security_code: 'encrypted_<getenv("TPAY_NOTIFICATION_SECURITY_CODE")>'
merchant_id: 'encrypted_<getenv("TPAY_MERCHANT_ID")>'
apple_pay_merchant_id: 'encrypted_<getenv("TPAY_APPLE_PAY_MERCHANT_ID")>'
type: 'apple_pay'
production_mode: false
encrypted: true

Expand Down

0 comments on commit 253d10d

Please sign in to comment.