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

Introduce the BlikPayment namespace #198

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
4 changes: 2 additions & 2 deletions config/config/api_platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use CommerceWeavers\SyliusTpayPlugin\Api\Command\Exception\PaymentFailedException;
use CommerceWeavers\SyliusTpayPlugin\Api\Exception\BlikAliasAmbiguousValueException;
use CommerceWeavers\SyliusTpayPlugin\Api\Factory\Exception\UnresolvableNextCommandException;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\PreconditionGuard\Exception\BlikAliasExpiredException;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\PreconditionGuard\Exception\BlikAliasNotRegisteredException;
use CommerceWeavers\SyliusTpayPlugin\Payment\Exception\PaymentCannotBeCancelledException;
use CommerceWeavers\SyliusTpayPlugin\PreconditionGuard\Exception\BlikAliasExpiredException;
use CommerceWeavers\SyliusTpayPlugin\PreconditionGuard\Exception\BlikAliasNotRegisteredException;

return function(ContainerConfigurator $configurator): void {
$configurator->extension('api_platform', [
Expand Down
6 changes: 3 additions & 3 deletions config/config/sylius_fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
'blik' => [
'code' => 'tpay_blik',
'name' => 'Blik (Tpay)',
'gatewayFactory' => 'tpay',
'gatewayName' => 'tpay',
'gatewayConfig' => $tpayConfig + ['type' => PaymentType::BLIK],
'gatewayFactory' => 'tpay_blik',
'gatewayName' => 'tpay_blik',
'gatewayConfig' => $tpayConfig,
'channels' => [
'FASHION_WEB',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="CommerceWeavers\SyliusTpayPlugin\Entity\BlikAlias" table="cw_sylius_tpay_blik_alias">
<mapped-superclass name="CommerceWeavers\SyliusTpayPlugin\BlikPayment\Entity\BlikAlias" table="cw_sylius_tpay_blik_alias">
<id name="id" column="id" type="integer">
<generator />
</id>
Expand Down
4 changes: 2 additions & 2 deletions config/services/api/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
$services->set('commerce_weavers_sylius_tpay.api.command.pay_by_blik_handler', PayByBlikHandler::class)
->parent('commerce_weavers_sylius_tpay.api.command.abstract_pay_by_handler')
->args([
service('commerce_weavers_sylius_tpay.resolver.blik_alias'),
service('commerce_weavers_sylius_tpay.blik_payment.resolver.blik_alias'),
service('commerce_weavers_sylius_tpay.manager.blik_alias'),
service('commerce_weavers_sylius_tpay.precondition_guard.active_blik_alias'),
service('commerce_weavers_sylius_tpay.blik_payment.precondition_guard.active_blik_alias'),
])
->tag('messenger.message_handler')
;
Expand Down
16 changes: 16 additions & 0 deletions config/services/api/validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfBlikAliasActionIsRegisterValidator;
use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayConfigTypeEqualsValidator;
use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayNameEqualsValidator;
use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayConfigTypeEqualsValidator;
use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayNameEqualsValidator;
use CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\TpayChannelIdEligibilityValidator;

return static function(ContainerConfigurator $container): void {
Expand All @@ -24,6 +26,13 @@
->tag('validator.constraint_validator')
;

$services->set('commerce_weavers_sylius_tpay.api.validator.constraint.not_blank_if_gateway_name_equals', NotBlankIfGatewayNameEqualsValidator::class)
->args([
service('sylius.repository.order'),
])
->tag('validator.constraint_validator')
;

$services->set('commerce_weavers_sylius_tpay.api.validator.constraint.one_of_properties_required_if_gateway_config_type_equals', OneOfPropertiesRequiredIfGatewayConfigTypeEqualsValidator::class)
->args([
service('sylius.repository.order'),
Expand All @@ -32,6 +41,13 @@
->tag('validator.constraint_validator')
;

$services->set('commerce_weavers_sylius_tpay.api.validator.constraint.one_of_properties_required_if_gateway_name_equals', OneOfPropertiesRequiredIfGatewayNameEqualsValidator::class)
->args([
service('sylius.repository.order'),
])
->tag('validator.constraint_validator')
;

$services->set('commerce_weavers_sylius_tpay.api.validator.constraint.tpay_channel_id_eligibility_validator', TpayChannelIdEligibilityValidator::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.resolver.cached_tpay_transaction_channel_resolver'),
Expand Down
9 changes: 9 additions & 0 deletions config/services/blik_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/blik_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\BlikPayment\Form\Type\GatewayConfigurationType;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Payum\Factory\GatewayFactory;

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

$services->set('commerce_weavers_sylius_tpay.blik_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_blik', 'type' => GatewayFactory::NAME])
->tag('form.type')
;
};
9 changes: 9 additions & 0 deletions config/services/blik_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');
};
25 changes: 25 additions & 0 deletions config/services/blik_payment/payum/action.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\BlikPayment\Payum\Action\CreateBlikLevelZeroTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Payum\Factory\GatewayFactory;

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

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

$services->set('commerce_weavers_sylius_tpay.blik_payment.payum.action.create_blik_level_zero_transaction', CreateBlikLevelZeroTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_blik_level_zero_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
service('commerce_weavers_sylius_tpay.repository.blik_alias'),
])
->tag('payum.action', ['factory' => GatewayFactory::NAME, 'alias' => 'cw.tpay_blik.create_blik_level_zero_transaction'])
;
};
19 changes: 19 additions & 0 deletions config/services/blik_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\BlikPayment\Payum\Factory\GatewayFactory;
use Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder;

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

$services->set('commerce_weavers_sylius_tpay.blik_payment.payum.factory.gateway', GatewayFactoryBuilder::class)
->args([
GatewayFactory::class,
])
->tag('payum.gateway_factory_builder', ['factory' => GatewayFactory::NAME])
;
};
20 changes: 20 additions & 0 deletions config/services/blik_payment/precondition_guard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\BlikPayment\PreconditionGuard\ActiveBlikAliasPreconditionGuard;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\PreconditionGuard\ActiveBlikAliasPreconditionGuardInterface;
use Sylius\Calendar\Provider\DateTimeProviderInterface;

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

$services->set('commerce_weavers_sylius_tpay.blik_payment.precondition_guard.active_blik_alias', ActiveBlikAliasPreconditionGuard::class)
->args([
service(DateTimeProviderInterface::class),
])
->alias(ActiveBlikAliasPreconditionGuardInterface::class, 'commerce_weavers_sylius_tpay.blik_payment.precondition_guard.active_blik_alias')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use CommerceWeavers\SyliusTpayPlugin\Resolver\BlikAliasResolver;
use CommerceWeavers\SyliusTpayPlugin\Resolver\BlikAliasResolverInterface;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Resolver\BlikAliasResolver;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Resolver\BlikAliasResolverInterface;

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

$services->set('commerce_weavers_sylius_tpay.resolver.blik_alias', BlikAliasResolver::class)
$services->set('commerce_weavers_sylius_tpay.blik_payment.resolver.blik_alias', BlikAliasResolver::class)
->args([
service('commerce_weavers_sylius_tpay.repository.blik_alias'),
service('commerce_weavers_sylius_tpay.factory.blik_alias'),
service('sylius.context.channel'),
])
->alias(BlikAliasResolverInterface::class, 'commerce_weavers_sylius_tpay.resolver.blik_alias')
->alias(BlikAliasResolverInterface::class, 'commerce_weavers_sylius_tpay.blik_payment.resolver.blik_alias')
;
};
17 changes: 7 additions & 10 deletions config/services/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\BlikPayment\Payum\Factory\GatewayFactory as BlikGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Payum\Factory\GatewayFactory as CardGatewayFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateBlikLevelZeroTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreatePayByLinkTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateRedirectBasedTransactionAction;
Expand All @@ -31,6 +31,7 @@
->args([
service('commerce_weavers_sylius_tpay.payum.factory.create_transaction'),
])
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.capture'])
;
Expand All @@ -51,15 +52,6 @@
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.create_google_pay_transaction'])
;

$services->set(CreateBlikLevelZeroTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_blik_level_zero_payment_payload'),
service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
service('commerce_weavers_sylius_tpay.repository.blik_alias'),
])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.create_blik_level_zero_transaction'])
;

$services->set(CreateRedirectBasedTransactionAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_redirect_based_payment_payload'),
Expand All @@ -82,21 +74,25 @@
service('commerce_weavers_sylius_tpay.tpay.security.notification.verifier.checksum'),
service('commerce_weavers_sylius_tpay.tpay.security.notification.verifier.signature'),
])
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.notify'])
;

$services->set(GetStatusAction::class)
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.get_status'])
;

$services->set(PartialRefundAction::class)
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.partial_refund'])
;

$services->set(RefundAction::class)
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.refund'])
;
Expand All @@ -121,6 +117,7 @@
;

$services->set(ResolveNextRouteAction::class)
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.resolve_next_route'])
;
Expand Down
20 changes: 0 additions & 20 deletions config/services/precondition_guard.php

This file was deleted.

8 changes: 4 additions & 4 deletions config/validation/Pay.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
<class name="CommerceWeavers\SyliusTpayPlugin\Api\Command\Pay">
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayConfigTypeEquals">
<option name="paymentMethodType">blik</option>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayNameEquals">
<option name="gatewayName">tpay_blik</option>
<option name="properties">
<value>blikToken</value>
<value>blikAliasAction</value>
Expand All @@ -12,8 +12,8 @@
<value>commerce_weavers_sylius_tpay:shop:order:pay</value>
</option>
</constraint>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayConfigTypeEquals">
<option name="paymentMethodType">card</option>
<constraint name="CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayNameEquals">
<option name="gatewayName">tpay_card</option>
<option name="properties">
<value>encodedCardData</value>
<value>savedCardId</value>
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Command/PayByBlikHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use CommerceWeavers\SyliusTpayPlugin\Api\Enum\BlikAliasAction;
use CommerceWeavers\SyliusTpayPlugin\Api\Exception\BlikAliasAmbiguousValueException;
use CommerceWeavers\SyliusTpayPlugin\Entity\BlikAliasInterface;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Entity\BlikAliasInterface;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Payum\Exception\BlikAliasAmbiguousValueException as PayumBlikAliasAmbiguousValueException;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\PreconditionGuard\ActiveBlikAliasPreconditionGuardInterface;
use CommerceWeavers\SyliusTpayPlugin\BlikPayment\Resolver\BlikAliasResolverInterface;
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails;
use CommerceWeavers\SyliusTpayPlugin\Payum\Exception\BlikAliasAmbiguousValueException as PayumBlikAliasAmbiguousValueException;
use CommerceWeavers\SyliusTpayPlugin\Payum\Processor\CreateTransactionProcessorInterface;
use CommerceWeavers\SyliusTpayPlugin\PreconditionGuard\ActiveBlikAliasPreconditionGuardInterface;
use CommerceWeavers\SyliusTpayPlugin\Resolver\BlikAliasResolverInterface;
use Doctrine\Persistence\ObjectManager;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\PaymentInterface;
Expand Down
32 changes: 32 additions & 0 deletions src/Api/Validator/Constraint/NotBlankIfGatewayNameEquals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint;

use Symfony\Component\Validator\Constraint;

final class NotBlankIfGatewayNameEquals extends Constraint
{
public const FIELD_REQUIRED_ERROR = '4102be3c-1c38-4cef-8265-714ad4968d9f';

public string $fieldRequiredErrorMessage = 'commerce_weavers_sylius_tpay.shop.pay.field.not_blank';

protected static $errorNames = [
self::FIELD_REQUIRED_ERROR => 'FIELD_REQUIRED_ERROR',
];

public function __construct(
mixed $options = null,
public ?string $gatewayName = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct($options, $groups, $payload);
}

public function getTargets(): string
{
return self::PROPERTY_CONSTRAINT;
}
}
Loading
Loading