Skip to content

Commit

Permalink
Move all Google Pay-related services under the GooglePayPayment n…
Browse files Browse the repository at this point in the history
…amespace
  • Loading branch information
jakubtobiasz committed Nov 26, 2024
1 parent c46b9ef commit 6b91f99
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 39 deletions.
11 changes: 11 additions & 0 deletions config/services/google_pay_payment/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Payum\Action\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Payum\Factory\GatewayFactory as GooglePayGatewayFactory;

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

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

$services->set(CreateGooglePayTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_google_pay_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
])
->tag('payum.action', ['factory' => GooglePayGatewayFactory::NAME, 'alias' => 'cw.tpay_google_pay.create_google_pay_transaction'])
;
};
2 changes: 1 addition & 1 deletion config/services/google_pay_payment/payum/factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return function(ContainerConfigurator $container): void {
$services = $container->services();

$services->set('commerce_weavers_sylius_tpay.apple_pay_payment.payum.factory.gateway', GatewayFactoryBuilder::class)
$services->set('commerce_weavers_sylius_tpay.google_pay_payment.payum.factory.gateway', GatewayFactoryBuilder::class)
->args([
GatewayFactory::class,
])
Expand Down
15 changes: 15 additions & 0 deletions config/services/google_pay_payment/validator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayTokenValidator;

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

$services->set('commerce_weavers_sylius_tpay.google_pay_payment.validator.constraint.encoded_google_pay_token', EncodedGooglePayTokenValidator::class)
->tag('validator.constraint_validator')
;
};
9 changes: 0 additions & 9 deletions config/services/payum/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Payum\Factory\GatewayFactory as CardGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Payum\Factory\GatewayFactory as GooglePayGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GatewayFactory as PayByLinkGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateVisaMobileTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\NotifyAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\CaptureAction;
Expand Down Expand Up @@ -39,14 +38,6 @@
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.capture'])
;

$services->set(CreateGooglePayTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_google_pay_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
])
->tag('payum.action', ['factory' => GooglePayGatewayFactory::NAME, 'alias' => 'cw.tpay_google_pay.create_google_pay_transaction'])
;

$services->set(CreateVisaMobileTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_visa_mobile_payment_payload'),
Expand Down
2 changes: 1 addition & 1 deletion config/services/validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayTokenValidator;
use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannelValidator;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayTokenValidator;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ForAuthorizedUserOnlyValidator;

return static function(ContainerConfigurator $container): void {
Expand Down
6 changes: 3 additions & 3 deletions config/validation/Pay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
</constraint>
</property>
<property name="googlePayToken">
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayConfigTypeEquals">
<option name="paymentMethodType">google_pay</option>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayNameEquals">
<option name="gatewayName">tpay_google_pay</option>
<option name="fieldRequiredErrorMessage">commerce_weavers_sylius_tpay.shop.pay.google_pay_token.required</option>
<option name="groups">
<value>commerce_weavers_sylius_tpay:shop:order:pay</value>
</option>
</constraint>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayToken">
<constraint name="CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayToken">
<option name="groups">
<value>commerce_weavers_sylius_tpay:shop:order:pay</value>
</option>
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/TpayPaymentDetailsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use CommerceWeavers\SyliusTpayPlugin\CardPayment\Form\Type\TpayCardType;
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Form\Type\TpayCreditCardChoiceType;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayToken;
use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannel;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayToken;
use Sylius\Component\Core\Model\ShopUserInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand Down
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\GooglePayPayment\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\CreateGooglePayPaymentPayloadFactoryInterface;
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\Validator\Constraint;
namespace CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint;

use Symfony\Component\Validator\Constraint;

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\Validator\Constraint;
namespace CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

{# >>> SyliusTpayPlugin customization #}
{% if payment is null %}
{% set gateway_name = null %}
{% set payment_type = null %}
{% set gateway_name = 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 ['google_pay'] or gateway_name in ['tpay_apple_pay'] %}
{% if gateway_name in ['tpay_apple_pay', 'tpay_google_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') }}>
Expand Down
4 changes: 1 addition & 3 deletions templates/shop/cart/complete/_google_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::GOOGLE_PAY')
%}
{% if payment is not null and payment.method.gatewayConfig.gatewayName == 'tpay_google_pay' %}
{% set payment = order.lastCartPayment() %}
{% set gatewayConfig = payment.method.gatewayConfig %}
{% set productionMode = gatewayConfig.config['production_mode'] ?? true %}
Expand Down
5 changes: 1 addition & 4 deletions templates/shop/order/pay/_apple_pay_regulations.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{% if cw_tpay_get_gateway_config_value(method.gatewayConfig, 'type') ==
constant('CommerceWeavers\\SyliusTpayPlugin\\Tpay\\PaymentType::APPLE_PAY')
and form.vars.value.state != 'cart'
%}
{% if method.gatewayConfig.gatewayName == 'tpay_apple_pay' and form.vars.value.state != 'cart' %}
<div class="ui stackable grid" style="display: none;" data-payment-details="apple_pay">
<div class="ui stackable grid">
<div class="ui column eight wide">
Expand Down
5 changes: 1 addition & 4 deletions templates/shop/order/pay/_google_pay_regulations.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{% if cw_tpay_get_gateway_config_value(method.gatewayConfig, 'type') ==
constant('CommerceWeavers\\SyliusTpayPlugin\\Tpay\\PaymentType::GOOGLE_PAY')
and form.vars.value.state != 'cart'
%}
{% if method.gatewayConfig.gatewayName == 'tpay_google_pay' and form.vars.value.state != 'cart' %}
<div class="ui stackable grid" style="display: none;" data-payment-details="google_pay">
<div class="ui stackable grid">
<div class="ui column eight wide">
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/Shop/PayingForOrdersByGooglePayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Api\Shop;

use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayConfigTypeEquals;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayToken;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayToken;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Tests\CommerceWeavers\SyliusTpayPlugin\Api\JsonApiTestCase;
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\GooglePayPayment\Payum\Action;

use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Payum\Action\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\Token\NotifyTokenFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreateGooglePayPaymentPayloadFactoryInterface;
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\Validator\Constraint;
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\GooglePayPayment\Validator\Constraint;

use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayToken;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayTokenValidator;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayToken;
use CommerceWeavers\SyliusTpayPlugin\GooglePayPayment\Validator\Constraint\EncodedGooglePayTokenValidator;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
Expand Down

0 comments on commit 6b91f99

Please sign in to comment.