diff --git a/config/config/sylius_fixtures.php b/config/config/sylius_fixtures.php
index 8e2419de..636296a4 100644
--- a/config/config/sylius_fixtures.php
+++ b/config/config/sylius_fixtures.php
@@ -110,9 +110,9 @@
'pbl' => [
'code' => 'tpay_pbl',
'name' => 'Pay by Link (Tpay)',
- 'gatewayFactory' => 'tpay',
- 'gatewayName' => 'tpay',
- 'gatewayConfig' => $tpayConfig + ['type' => PaymentType::PAY_BY_LINK],
+ 'gatewayFactory' => 'tpay_pbl',
+ 'gatewayName' => 'tpay_pbl',
+ 'gatewayConfig' => $tpayConfig,
'channels' => [
'FASHION_WEB',
],
diff --git a/config/services/context_provider.php b/config/services/context_provider.php
index 05bb58a2..1acb4a01 100644
--- a/config/services/context_provider.php
+++ b/config/services/context_provider.php
@@ -4,8 +4,8 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
-use CommerceWeavers\SyliusTpayPlugin\ContextProvider\BankListContextProvider;
use CommerceWeavers\SyliusTpayPlugin\ContextProvider\RegulationsUrlContextProvider;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\ContextProvider\BankListContextProvider;
return static function(ContainerConfigurator $container): void {
$services = $container->services();
diff --git a/config/services/pay_by_link_payment/context_provider.php b/config/services/pay_by_link_payment/context_provider.php
new file mode 100644
index 00000000..9e511ce3
--- /dev/null
+++ b/config/services/pay_by_link_payment/context_provider.php
@@ -0,0 +1,18 @@
+services();
+
+ $services->set('commerce_weavers_sylius_tpay.pay_by_link_payment.context_provider.bank_list', BankListContextProvider::class)
+ ->args([
+ service('commerce_weavers_sylius_tpay.tpay.provider.validated_tpay_api_bank_list'),
+ ])
+ ->tag('sylius.ui.template_event.context_provider')
+ ;
+};
diff --git a/config/services/pay_by_link_payment/form.php b/config/services/pay_by_link_payment/form.php
new file mode 100644
index 00000000..a650bf3e
--- /dev/null
+++ b/config/services/pay_by_link_payment/form.php
@@ -0,0 +1,9 @@
+import('form/**/*.php');
+};
diff --git a/config/services/pay_by_link_payment/form/type.php b/config/services/pay_by_link_payment/form/type.php
new file mode 100644
index 00000000..41645abd
--- /dev/null
+++ b/config/services/pay_by_link_payment/form/type.php
@@ -0,0 +1,19 @@
+services();
+
+ $services->set('commerce_weavers_sylius_tpay.pay_by_link_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_pbl', 'type' => GatewayFactory::NAME])
+ ->tag('form.type')
+ ;
+};
diff --git a/config/services/pay_by_link_payment/payum.php b/config/services/pay_by_link_payment/payum.php
new file mode 100644
index 00000000..cbc99101
--- /dev/null
+++ b/config/services/pay_by_link_payment/payum.php
@@ -0,0 +1,9 @@
+import('payum/**/*.php');
+};
diff --git a/config/services/pay_by_link_payment/payum/action.php b/config/services/pay_by_link_payment/payum/action.php
new file mode 100644
index 00000000..5685291d
--- /dev/null
+++ b/config/services/pay_by_link_payment/payum/action.php
@@ -0,0 +1,29 @@
+services();
+
+ $services->defaults()
+ ->public()
+ ;
+
+ $services->set(CreatePayByLinkTransactionAction::class)
+ ->args([
+ service('commerce_weavers_sylius_tpay.tpay.factory.create_pay_by_link_payment_payload'),
+ service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
+ ])
+ ->tag('payum.action', ['factory' => GatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.create_pay_by_link_transaction'])
+ ;
+
+ $services->set(GetTpayTransactionsChannelsAction::class)
+ ->tag('payum.action', ['factory' => GatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.get_transactions_channels'])
+ ;
+};
diff --git a/config/services/pay_by_link_payment/payum/factory.php b/config/services/pay_by_link_payment/payum/factory.php
new file mode 100644
index 00000000..6e5048e8
--- /dev/null
+++ b/config/services/pay_by_link_payment/payum/factory.php
@@ -0,0 +1,25 @@
+services();
+
+ $services->set('commerce_weavers_sylius_tpay.pay_by_link_payment.payum.factory.gateway', GatewayFactoryBuilder::class)
+ ->args([
+ GatewayFactory::class,
+ ])
+ ->tag('payum.gateway_factory_builder', ['factory' => GatewayFactory::NAME])
+ ;
+
+ $services->set('commerce_weavers_sylius_tpay.pay_by_link_payment.payum.factory.get_tpay_transactions_channels', GetTpayTransactionsChannelsFactory::class)
+ ->alias(GetTpayTransactionsChannelsFactoryInterface::class, 'commerce_weavers_sylius_tpay.pay_by_link_payment.payum.factory.get_tpay_transactions_channels')
+ ;
+};
diff --git a/config/services/pay_by_link_payment/validator.php b/config/services/pay_by_link_payment/validator.php
new file mode 100644
index 00000000..a87524b7
--- /dev/null
+++ b/config/services/pay_by_link_payment/validator.php
@@ -0,0 +1,18 @@
+services();
+
+ $services->set('commerce_weavers_sylius_tpay.pay_by_link_payment.validator.constraint.valid_tpay_channel', ValidTpayChannelValidator::class)
+ ->args([
+ service('commerce_weavers_sylius_tpay.tpay.provider.validated_tpay_api_bank_list'),
+ ])
+ ->tag('validator.constraint_validator')
+ ;
+};
diff --git a/config/services/payum/action.php b/config/services/payum/action.php
index b0960e19..19dc8e99 100644
--- a/config/services/payum/action.php
+++ b/config/services/payum/action.php
@@ -6,12 +6,11 @@
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\Payum\Action\Api\CreateApplePayTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateGooglePayTransactionAction;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreatePayByLinkTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateRedirectBasedTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateVisaMobileTransactionAction;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\GetTpayTransactionsChannelsAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\InitializeApplePayPaymentAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\NotifyAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\CaptureAction;
@@ -33,6 +32,7 @@
])
->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' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.capture'])
;
@@ -76,31 +76,31 @@
])
->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'])
->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' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.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' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.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' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.refund'])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.refund'])
;
- $services->set(GetTpayTransactionsChannelsAction::class)
- ->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.get_transactions_channels'])
- ;
-
$services->set(InitializeApplePayPaymentAction::class)
->args([
service('commerce_weavers_sylius_tpay.tpay.factory.create_initialize_apple_pay_payment_payload'),
@@ -108,17 +108,10 @@
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.initialize_apple_pay_payment'])
;
- $services->set(CreatePayByLinkTransactionAction::class)
- ->args([
- service('commerce_weavers_sylius_tpay.tpay.factory.create_pay_by_link_payment_payload'),
- service('commerce_weavers_sylius_tpay.payum.factory.token.notify'),
- ])
- ->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.create_pay_by_link_transaction'])
- ;
-
$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' => PayByLinkGatewayFactory::NAME, 'alias' => 'cw.tpay_pbl.resolve_next_route'])
->tag('payum.action', ['factory' => TpayGatewayFactory::NAME, 'alias' => 'cw.tpay.resolve_next_route'])
;
};
diff --git a/config/services/payum/factory.php b/config/services/payum/factory.php
index 472947e2..0466c94e 100644
--- a/config/services/payum/factory.php
+++ b/config/services/payum/factory.php
@@ -6,8 +6,6 @@
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\CreateTransactionFactoryInterface;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\GetTpayTransactionsChannelsFactory;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\GetTpayTransactionsChannelsFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactory;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\InitializeApplePayPaymentFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\NotifyDataFactory;
@@ -37,10 +35,6 @@
->alias(CreateTransactionFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.create_transaction')
;
- $services->set('commerce_weavers_sylius_tpay.payum.factory.get_tpay_transactions_channels', GetTpayTransactionsChannelsFactory::class)
- ->alias(GetTpayTransactionsChannelsFactoryInterface::class, 'commerce_weavers_sylius_tpay.payum.factory.get_tpay_transactions_channels')
- ;
-
$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')
;
diff --git a/config/services/tpay.php b/config/services/tpay.php
index f7d1847b..9cff0333 100644
--- a/config/services/tpay.php
+++ b/config/services/tpay.php
@@ -169,7 +169,7 @@
$services->set('commerce_weavers_sylius_tpay.tpay.resolver.tpay_transaction_channel_resolver', TpayTransactionChannelResolver::class)
->args([
service('payum'),
- service('commerce_weavers_sylius_tpay.payum.factory.get_tpay_transactions_channels'),
+ service('commerce_weavers_sylius_tpay.pay_by_link_payment.payum.factory.get_tpay_transactions_channels'),
service('logger')->nullOnInvalid(),
])
->tag('monolog.logger', ['channel' => 'sylius_tpay'])
diff --git a/config/services/validator.php b/config/services/validator.php
index b0028ecb..c0f3dbfd 100644
--- a/config/services/validator.php
+++ b/config/services/validator.php
@@ -4,9 +4,9 @@
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannelValidator;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayTokenValidator;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ForAuthorizedUserOnlyValidator;
-use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ValidTpayChannelValidator;
return static function(ContainerConfigurator $container): void {
$services = $container->services();
diff --git a/src/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidator.php b/src/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidator.php
index 149bec14..6ddc98e5 100644
--- a/src/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidator.php
+++ b/src/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidator.php
@@ -45,11 +45,7 @@ public function validate(mixed $value, Constraint $constraint): void
/** @var PaymentMethodInterface|null $lastPaymentMethod */
$lastPaymentMethod = $order?->getLastPayment(PaymentInterface::STATE_NEW)?->getMethod();
- if (null === $lastPaymentMethod) {
- return;
- }
-
- $gatewayName = $lastPaymentMethod->getGatewayConfig()?->getGatewayName();
+ $gatewayName = $lastPaymentMethod?->getGatewayConfig()?->getGatewayName();
if ($gatewayName !== $constraint->gatewayName) {
return;
diff --git a/src/Form/Type/TpayPaymentDetailsType.php b/src/Form/Type/TpayPaymentDetailsType.php
index e35de3a8..fbfc0c72 100644
--- a/src/Form/Type/TpayPaymentDetailsType.php
+++ b/src/Form/Type/TpayPaymentDetailsType.php
@@ -6,8 +6,8 @@
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Form\Type\TpayCardType;
use CommerceWeavers\SyliusTpayPlugin\CardPayment\Form\Type\TpayCreditCardChoiceType;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannel;
use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\EncodedGooglePayToken;
-use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ValidTpayChannel;
use Sylius\Component\Core\Model\ShopUserInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
diff --git a/src/ContextProvider/BankListContextProvider.php b/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php
similarity index 94%
rename from src/ContextProvider/BankListContextProvider.php
rename to src/PayByLinkPayment/ContextProvider/BankListContextProvider.php
index 7bea178c..36f8239f 100644
--- a/src/ContextProvider/BankListContextProvider.php
+++ b/src/PayByLinkPayment/ContextProvider/BankListContextProvider.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace CommerceWeavers\SyliusTpayPlugin\ContextProvider;
+namespace CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\ContextProvider;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProviderInterface;
use Sylius\Bundle\UiBundle\ContextProvider\ContextProviderInterface;
diff --git a/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php b/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php
new file mode 100644
index 00000000..92134556
--- /dev/null
+++ b/src/PayByLinkPayment/Form/Type/GatewayConfigurationType.php
@@ -0,0 +1,11 @@
+availableTpayApiBankListProvider->provide();
-
/** @var PaymentMethodInterface[] $paymentMethods */
$paymentMethods = $this->paymentMethodRepository->findByChannelAndGatewayConfigNameWithGatewayConfig(
$this->channelContext->getChannel(),
@@ -41,8 +40,20 @@ public function provide(): array
Assert::notEmpty($paymentMethods, 'There is no payment method of Tpay type available');
+ /** @var PaymentMethodInterface[] $payByLinkPaymentMethods */
+ $payByLinkPaymentMethods = $this->paymentMethodRepository->findByChannelAndGatewayConfigNameWithGatewayConfig(
+ $this->channelContext->getChannel(),
+ GatewayFactory::NAME,
+ );
+
+ if ([] === $payByLinkPaymentMethods) {
+ throw new UnableToGetBankListException(
+ 'Bank list cannot be retrieved if there is no payment method with PayByLink type configured',
+ );
+ }
+
+ $availableChannels = $this->availableTpayApiBankListProvider->provide();
$paymentMethodsToRemoveByGroupId = [];
- $hasPblPaymentAvailable = false;
foreach ($paymentMethods as $paymentMethod) {
/** @var (GatewayConfigInterface&CryptedInterface)|null $tpayGatewayConfig */
$tpayGatewayConfig = $paymentMethod->getGatewayConfig();
@@ -58,10 +69,6 @@ public function provide(): array
continue;
}
- if ($hasPblPaymentAvailable === false && $config['type'] === PaymentType::PAY_BY_LINK) {
- $hasPblPaymentAvailable = true;
- }
-
match ($config['type']) {
PaymentType::VISA_MOBILE => array_push(
$paymentMethodsToRemoveByGroupId,
@@ -76,12 +83,6 @@ public function provide(): array
};
}
- if (!$hasPblPaymentAvailable) {
- throw new UnableToGetBankListException(
- 'Bank list cannot be retrieved if there is no payment method with PayByLink type configured',
- );
- }
-
return array_filter($availableChannels, static function (array $channel) use ($paymentMethodsToRemoveByGroupId): bool {
$groupId = (int) $channel['groups'][0]['id'];
diff --git a/src/Tpay/Resolver/TpayTransactionChannelResolver.php b/src/Tpay/Resolver/TpayTransactionChannelResolver.php
index 0116773f..ab145ba0 100644
--- a/src/Tpay/Resolver/TpayTransactionChannelResolver.php
+++ b/src/Tpay/Resolver/TpayTransactionChannelResolver.php
@@ -4,8 +4,9 @@
namespace CommerceWeavers\SyliusTpayPlugin\Tpay\Resolver;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\GetTpayTransactionsChannelsFactoryInterface;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\GetTpayTransactionsChannels;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GatewayFactory;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GetTpayTransactionsChannelsFactoryInterface;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Request\GetTpayTransactionsChannels;
use Payum\Core\Model\ArrayObject;
use Payum\Core\Payum;
use Psr\Log\LoggerInterface;
@@ -30,7 +31,7 @@ public function __construct(
public function resolve(): array
{
- $gateway = $this->payum->getGateway('tpay');
+ $gateway = $this->payum->getGateway(GatewayFactory::NAME);
$value = $this->getTpayTransactionsChannelsFactory?->createNewEmpty()
?? new GetTpayTransactionsChannels(new ArrayObject());
diff --git a/templates/shop/cart/complete/_payByLink.html.twig b/templates/shop/cart/complete/_payByLink.html.twig
index 27631e4b..b30a31f9 100644
--- a/templates/shop/cart/complete/_payByLink.html.twig
+++ b/templates/shop/cart/complete/_payByLink.html.twig
@@ -1,7 +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::PAY_BY_LINK')
+{% if payment is not null and payment.method.gatewayConfig.gatewayName == 'tpay_pbl'
%}
{% for bank in banks %}
diff --git a/templates/shop/order/pay/_payByLink.html.twig b/templates/shop/order/pay/_payByLink.html.twig
index 89bea638..60fbb378 100644
--- a/templates/shop/order/pay/_payByLink.html.twig
+++ b/templates/shop/order/pay/_payByLink.html.twig
@@ -1,6 +1,4 @@
-{% if cw_tpay_get_gateway_config_value(method.gatewayConfig, 'type') == constant('CommerceWeavers\\SyliusTpayPlugin\\Tpay\\PaymentType::PAY_BY_LINK')
- and form.vars.value.state != 'cart'
-%}
+{% if method.gatewayConfig.gatewayName == 'tpay_pbl' and form.vars.value.state != 'cart' %}
{% include '@CommerceWeaversSyliusTpayPlugin/shop/payment/_payByLink.html.twig' %}
diff --git a/tests/Api/DataFixtures/shop/blik_payment_method.yml b/tests/Api/DataFixtures/shop/blik_payment_method.yml
index a63fd27c..864d5fb4 100644
--- a/tests/Api/DataFixtures/shop/blik_payment_method.yml
+++ b/tests/Api/DataFixtures/shop/blik_payment_method.yml
@@ -50,7 +50,6 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
client_id: 'encrypted_
'
client_secret: 'encrypted_'
cards_api: 'encrypted_'
- type: 'card'
production_mode: false
encrypted: true
gateway_tpay_blik:
@@ -62,12 +61,11 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
production_mode: false
encrypted: true
gateway_tpay_pbl:
- gatewayName: 'tpay'
- factoryName: 'tpay'
+ gatewayName: 'tpay_pbl'
+ factoryName: 'tpay_pbl'
config:
client_id: 'encrypted_'
client_secret: 'encrypted_'
- type: 'pay_by_link'
production_mode: false
encrypted: true
diff --git a/tests/Api/DataFixtures/shop/paying_for_orders_by_card/payment_method.yml b/tests/Api/DataFixtures/shop/paying_for_orders_by_card/payment_method.yml
index 170ebfad..39c156ce 100644
--- a/tests/Api/DataFixtures/shop/paying_for_orders_by_card/payment_method.yml
+++ b/tests/Api/DataFixtures/shop/paying_for_orders_by_card/payment_method.yml
@@ -52,7 +52,6 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
client_id: 'encrypted_'
client_secret: 'encrypted_'
cards_api: 'encrypted_'
- type: 'card'
production_mode: false
encrypted: true
gateway_tpay_blik:
@@ -64,12 +63,11 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
production_mode: false
encrypted: true
gateway_tpay_pbl:
- gatewayName: 'tpay'
- factoryName: 'tpay'
+ gatewayName: 'tpay_pbl'
+ factoryName: 'tpay_pbl'
config:
client_id: 'encrypted_'
client_secret: 'encrypted_'
- type: 'pay_by_link'
production_mode: false
encrypted: true
gateway_tpay_visa_mobile:
diff --git a/tests/E2E/Resources/fixtures/common/payment_method.yaml b/tests/E2E/Resources/fixtures/common/payment_method.yaml
index e16a6ec5..2e6541db 100644
--- a/tests/E2E/Resources/fixtures/common/payment_method.yaml
+++ b/tests/E2E/Resources/fixtures/common/payment_method.yaml
@@ -78,8 +78,8 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
production_mode: false
encrypted: true
gateway_tpay_pbl:
- gatewayName: 'tpay'
- factoryName: 'tpay'
+ gatewayName: 'tpay_pbl'
+ factoryName: 'tpay_pbl'
config:
client_id: 'encrypted_'
client_secret: 'encrypted_'
diff --git a/tests/Unit/Api/Validator/Constraint/NotBlankIfGatewayNameEqualsValidatorTest.php b/tests/Unit/Api/Validator/Constraint/NotBlankIfGatewayNameEqualsValidatorTest.php
new file mode 100644
index 00000000..ddb4bc21
--- /dev/null
+++ b/tests/Unit/Api/Validator/Constraint/NotBlankIfGatewayNameEqualsValidatorTest.php
@@ -0,0 +1,206 @@
+orderRepository = $this->prophesize(OrderRepositoryInterface::class);
+
+ parent::setUp();
+ }
+
+ public function test_it_throws_an_exception_if_unsupported_constraint_passed(): void
+ {
+ $this->expectException(UnexpectedTypeException::class);
+ $this->expectExceptionMessage('Expected argument of type "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayNameEquals", "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\TpayChannelIdEligibility" given');
+
+ $this->validator->validate('foo', new TpayChannelIdEligibility());
+ }
+
+ public function test_it_throws_an_exception_if_gateway_name_is_not_passed(): void
+ {
+ $this->expectException(MissingOptionsException::class);
+ $this->expectExceptionMessage('Option "gatewayName" must be given for constraint "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\NotBlankIfGatewayNameEqualsValidator".');
+
+ $this->validator->validate('foo', new NotBlankIfGatewayNameEquals());
+ }
+
+ public function test_it_throws_an_exception_if_a_context_object_is_unsupported(): void
+ {
+ $this->expectException(UnexpectedTypeException::class);
+ $this->expectExceptionMessage('Expected argument of type "CommerceWeavers\SyliusTpayPlugin\Api\Command\Pay", "null" given');
+
+ $this->validator->validate(new \stdClass(), new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+ }
+
+ public function test_it_does_nothing_if_value_is_integer(): void
+ {
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $context = $this->prophesize(ExecutionContextInterface::class);
+ $context->getObject()->willReturn($pay);
+
+ $this->validator->initialize($context->reveal());
+ $this->validator->validate(5, new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_value_is_bool(): void
+ {
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $context = $this->prophesize(ExecutionContextInterface::class);
+ $context->getObject()->willReturn($pay);
+
+ $this->validator->initialize($context->reveal());
+ $this->validator->validate(true, new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_value_is_not_an_empty_string(): void
+ {
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $context = $this->prophesize(ExecutionContextInterface::class);
+ $context->getObject()->willReturn($pay);
+
+ $this->validator->initialize($context->reveal());
+ $this->validator->validate('test', new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_gateway_name_for_a_given_order_is_missing(): void
+ {
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn(null);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $context = $this->prophesize(ExecutionContextInterface::class);
+ $context->getObject()->willReturn($pay);
+
+ $this->validator->initialize($context->reveal());
+ $this->validator->validate('test', new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_gateway_names_are_different(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $context = $this->prophesize(ExecutionContextInterface::class);
+ $context->getObject()->willReturn($pay);
+
+ $this->validator->initialize($context->reveal());
+ $this->validator->validate('test', new NotBlankIfGatewayNameEquals(gatewayName: 'bar'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_adds_a_violation_if_value_is_null_and_gateway_names_matches(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->setObject($pay);
+
+ $this->validator->validate(null, new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this
+ ->buildViolation('commerce_weavers_sylius_tpay.shop.pay.field.not_blank')
+ ->setCode(NotBlankIfGatewayNameEquals::FIELD_REQUIRED_ERROR)
+ ->assertRaised()
+ ;
+ }
+
+ public function test_it_adds_a_violation_if_value_is_an_empty_string_and_gateway_names_matches(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->setObject($pay);
+
+ $this->validator->validate('', new NotBlankIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this
+ ->buildViolation('commerce_weavers_sylius_tpay.shop.pay.field.not_blank')
+ ->setCode(NotBlankIfGatewayNameEquals::FIELD_REQUIRED_ERROR)
+ ->assertRaised()
+ ;
+ }
+
+ protected function createValidator(): NotBlankIfGatewayNameEqualsValidator
+ {
+ return new NotBlankIfGatewayNameEqualsValidator($this->orderRepository->reveal());
+ }
+}
diff --git a/tests/Unit/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidatorTest.php b/tests/Unit/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidatorTest.php
new file mode 100644
index 00000000..df6b4f0b
--- /dev/null
+++ b/tests/Unit/Api/Validator/Constraint/OneOfPropertiesRequiredIfGatewayNameEqualsValidatorTest.php
@@ -0,0 +1,194 @@
+orderRepository = $this->prophesize(OrderRepositoryInterface::class);
+
+ parent::setUp();
+ }
+
+ public function test_it_throws_an_exception_if_unsupported_constraint_passed(): void
+ {
+ $this->expectException(UnexpectedTypeException::class);
+ $this->expectExceptionMessage('Expected argument of type "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayNameEquals", "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\TpayChannelIdEligibility" given');
+
+ $this->validator->validate('foo', new TpayChannelIdEligibility());
+ }
+
+ public function test_it_throws_an_exception_if_gateway_name_is_not_passed(): void
+ {
+ $this->expectException(MissingOptionsException::class);
+ $this->expectExceptionMessage('Option "gatewayName" must be given for constraint "CommerceWeavers\SyliusTpayPlugin\Api\Validator\Constraint\OneOfPropertiesRequiredIfGatewayNameEqualsValidator".');
+
+ $this->validator->validate('foo', new OneOfPropertiesRequiredIfGatewayNameEquals());
+ }
+
+ public function test_it_throws_an_exception_if_a_value_is_unsupported(): void
+ {
+ $this->expectException(UnexpectedTypeException::class);
+ $this->expectExceptionMessage('Expected argument of type "CommerceWeavers\SyliusTpayPlugin\Api\Command\Pay", "stdClass" given');
+
+ $this->validator->validate(new \stdClass(), new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo'));
+ }
+
+ public function test_it_does_nothing_if_order_cannot_be_found(): void
+ {
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn(null);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_payment_method_cannot_be_found(): void
+ {
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn(null);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_payment_cannot_be_found(): void
+ {
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn(null);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_gateway_config_cannot_be_found(): void
+ {
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn(null);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_gateway_names_are_different(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'bar'));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_does_nothing_if_gateway_names_are_same_and_all_properties_are_set(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com', blikToken: '123456');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo', properties: ['blikToken']));
+
+ $this->assertNoViolation();
+ }
+
+ public function test_it_adds_violation_if_gateway_names_are_same_and_any_of_required_properties_is_not_set(): void
+ {
+ $gatewayConfig = $this->prophesize(GatewayConfigInterface::class);
+ $gatewayConfig->getGatewayName()->willReturn('foo');
+
+ $paymentMethod = $this->prophesize(PaymentMethodInterface::class);
+ $paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
+
+ $payment = $this->prophesize(PaymentInterface::class);
+ $payment->getMethod()->willReturn($paymentMethod);
+
+ $order = $this->prophesize(OrderInterface::class);
+ $order->getLastPayment('new')->willReturn($payment);
+
+ $this->orderRepository->findOneByTokenValue('t0k3n')->willReturn($order);
+
+ $pay = new Pay(orderToken: 't0k3n', successUrl: 'https://success.com', failureUrl: 'https://failure.com', blikToken: '123456');
+
+ $this->validator->validate($pay, new OneOfPropertiesRequiredIfGatewayNameEquals(gatewayName: 'foo', properties: ['googlePayToken']));
+
+ $this->buildViolation('commerce_weavers_sylius_tpay.shop.pay.fields_required')
+ ->setCode('c64630dd-3766-4a69-9d83-66aabf8f68fe')
+ ->assertRaised()
+ ;
+ }
+
+ protected function createValidator(): OneOfPropertiesRequiredIfGatewayNameEqualsValidator
+ {
+ return new OneOfPropertiesRequiredIfGatewayNameEqualsValidator($this->orderRepository->reveal());
+ }
+}
diff --git a/tests/Unit/ContextProvider/BankListContextProviderTest.php b/tests/Unit/PayByLinkPayment/ContextProvider/BankListContextProviderTest.php
similarity index 95%
rename from tests/Unit/ContextProvider/BankListContextProviderTest.php
rename to tests/Unit/PayByLinkPayment/ContextProvider/BankListContextProviderTest.php
index 7758785c..c88561b0 100644
--- a/tests/Unit/ContextProvider/BankListContextProviderTest.php
+++ b/tests/Unit/PayByLinkPayment/ContextProvider/BankListContextProviderTest.php
@@ -2,9 +2,9 @@
declare(strict_types=1);
-namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\ContextProvider;
+namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\PayByLinkPayment\ContextProvider;
-use CommerceWeavers\SyliusTpayPlugin\ContextProvider\BankListContextProvider;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\ContextProvider\BankListContextProvider;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProviderInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
diff --git a/tests/Unit/Payum/Action/Api/CreatePayByLinkTransactionActionTest.php b/tests/Unit/PayByLinkPayment/Payum/Action/CreatePayByLinkTransactionActionTest.php
similarity index 97%
rename from tests/Unit/Payum/Action/Api/CreatePayByLinkTransactionActionTest.php
rename to tests/Unit/PayByLinkPayment/Payum/Action/CreatePayByLinkTransactionActionTest.php
index 374b2854..5316b2e1 100644
--- a/tests/Unit/Payum/Action/Api/CreatePayByLinkTransactionActionTest.php
+++ b/tests/Unit/PayByLinkPayment/Payum/Action/CreatePayByLinkTransactionActionTest.php
@@ -2,9 +2,9 @@
declare(strict_types=1);
-namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Action\Api;
+namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\PayByLinkPayment\Payum\Action;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreatePayByLinkTransactionAction;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Action\CreatePayByLinkTransactionAction;
use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\Token\NotifyTokenFactoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Factory\CreatePayByLinkPayloadFactoryInterface;
diff --git a/tests/Unit/Payum/Action/Api/GetTpayTransactionsChannelsActionTest.php b/tests/Unit/PayByLinkPayment/Payum/Action/GetTpayTransactionsChannelsActionTest.php
similarity index 87%
rename from tests/Unit/Payum/Action/Api/GetTpayTransactionsChannelsActionTest.php
rename to tests/Unit/PayByLinkPayment/Payum/Action/GetTpayTransactionsChannelsActionTest.php
index 3097ca0e..3de68530 100644
--- a/tests/Unit/Payum/Action/Api/GetTpayTransactionsChannelsActionTest.php
+++ b/tests/Unit/PayByLinkPayment/Payum/Action/GetTpayTransactionsChannelsActionTest.php
@@ -2,10 +2,10 @@
declare(strict_types=1);
-namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Action\Api;
+namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\PayByLinkPayment\Payum\Action;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\GetTpayTransactionsChannelsAction;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\GetTpayTransactionsChannels;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Action\GetTpayTransactionsChannelsAction;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Request\GetTpayTransactionsChannels;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\Notify;
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\Notify\NotifyData;
use CommerceWeavers\SyliusTpayPlugin\Tpay\TpayApi;
diff --git a/tests/Unit/Validator/Constraint/ValidTpayChannelValidatorTest.php b/tests/Unit/PayByLinkPayment/Validator/Constraint/ValidTpayChannelValidatorTest.php
similarity index 89%
rename from tests/Unit/Validator/Constraint/ValidTpayChannelValidatorTest.php
rename to tests/Unit/PayByLinkPayment/Validator/Constraint/ValidTpayChannelValidatorTest.php
index 0801493d..9dea8b19 100644
--- a/tests/Unit/Validator/Constraint/ValidTpayChannelValidatorTest.php
+++ b/tests/Unit/PayByLinkPayment/Validator/Constraint/ValidTpayChannelValidatorTest.php
@@ -2,11 +2,11 @@
declare(strict_types=1);
-namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Validator\Constraint;
+namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\PayByLinkPayment\Validator\Constraint;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannel;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\ValidTpayChannelValidator;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProviderInterface;
-use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ValidTpayChannel;
-use CommerceWeavers\SyliusTpayPlugin\Validator\Constraint\ValidTpayChannelValidator;
use InvalidArgumentException;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
diff --git a/tests/Unit/Tpay/Provider/ValidTpayChannelListProviderTest.php b/tests/Unit/Tpay/Provider/ValidTpayChannelListProviderTest.php
index ea67e7a1..7aa06a24 100644
--- a/tests/Unit/Tpay/Provider/ValidTpayChannelListProviderTest.php
+++ b/tests/Unit/Tpay/Provider/ValidTpayChannelListProviderTest.php
@@ -4,7 +4,7 @@
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Tpay\Provider;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Exception\UnableToGetBankListException;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Exception\UnableToGetBankListException;
use CommerceWeavers\SyliusTpayPlugin\Repository\PaymentMethodRepositoryInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\AvailableTpayChannelListProviderInterface;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Provider\ValidTpayChannelListProvider;
@@ -120,26 +120,20 @@ public function test_it_throws_exception_if_there_is_no_gateway_config_that_is_p
$this->expectExceptionMessage('Bank list cannot be retrieved if there is no payment method with PayByLink type configured');
$notTpayBasedPaymentMethod = $this->prophesize(PaymentMethodInterface::class);
- $notTpayBasedGatewayConfig = $this->prophesize(GatewayConfig::class);
- $notTpayBasedGatewayConfigConfig = [
- 'type' => 'visa_mobile',
- ];
- $notTpayBasedPaymentMethod->getGatewayConfig()->willReturn($notTpayBasedGatewayConfig);
-
- $this->availableTpayApiBankListProvider->provide()->willReturn(self::BANK_LIST);
$channel = $this->prophesize(ChannelInterface::class);
$this->channelContext->getChannel()->willReturn($channel->reveal());
- $notTpayBasedGatewayConfig->decrypt($this->cypher)->shouldBeCalled();
- $notTpayBasedGatewayConfig->getConfig()->willReturn($notTpayBasedGatewayConfigConfig);
-
$this->paymentMethodRepository
->findByChannelAndGatewayConfigNameWithGatewayConfig($channel, 'tpay')
->willReturn([
$notTpayBasedPaymentMethod
])
;
+ $this->paymentMethodRepository
+ ->findByChannelAndGatewayConfigNameWithGatewayConfig($channel, 'tpay_pbl')
+ ->willReturn([])
+ ;
$this->createTestSubject()->provide();
}
@@ -167,6 +161,12 @@ public function test_it_returns_all_available_payments_if_only_tpay_payment_meth
$tpayBasedPaymentMethod->reveal(),
])
;
+ $this->paymentMethodRepository
+ ->findByChannelAndGatewayConfigNameWithGatewayConfig($channel, 'tpay_pbl')
+ ->willReturn([
+ $this->prophesize(PaymentMethodInterface::class)->reveal(),
+ ])
+ ;
$result = $this->createTestSubject()->provide();
@@ -205,6 +205,12 @@ public function test_it_returns_valid_payments_according_to_available_tpay_payme
$anotherTpayPblPaymentMethod->reveal(),
])
;
+ $this->paymentMethodRepository
+ ->findByChannelAndGatewayConfigNameWithGatewayConfig($channel, 'tpay_pbl')
+ ->willReturn([
+ $this->prophesize(PaymentMethodInterface::class)->reveal(),
+ ])
+ ;
$result = $this->createTestSubject()->provide();
@@ -247,6 +253,12 @@ public function test_it_returns_valid_payments_even_if_gateway_config_lacks_type
$anotherTpayPblPaymentMethod->reveal(),
])
;
+ $this->paymentMethodRepository
+ ->findByChannelAndGatewayConfigNameWithGatewayConfig($channel, 'tpay_pbl')
+ ->willReturn([
+ $this->prophesize(PaymentMethodInterface::class)->reveal(),
+ ])
+ ;
$result = $this->createTestSubject()->provide();
diff --git a/tests/Unit/Tpay/Resolver/TpayTransactionChannelResolverTest.php b/tests/Unit/Tpay/Resolver/TpayTransactionChannelResolverTest.php
index 12e9aeaf..7f8e978f 100644
--- a/tests/Unit/Tpay/Resolver/TpayTransactionChannelResolverTest.php
+++ b/tests/Unit/Tpay/Resolver/TpayTransactionChannelResolverTest.php
@@ -5,9 +5,8 @@
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Tpay\Resolver;
-use ArrayObject;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Factory\GetTpayTransactionsChannelsFactoryInterface;
-use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\GetTpayTransactionsChannels;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Factory\GetTpayTransactionsChannelsFactoryInterface;
+use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Payum\Request\GetTpayTransactionsChannels;
use CommerceWeavers\SyliusTpayPlugin\Tpay\Resolver\TpayTransactionChannelResolver;
use Payum\Core\GatewayInterface;
use Payum\Core\Payum;
@@ -17,7 +16,6 @@
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Log\LoggerInterface;
use Tpay\OpenApi\Utilities\TpayException;
-use Webmozart\Assert\Assert;
final class TpayTransactionChannelResolverTest extends TestCase
{
@@ -40,7 +38,7 @@ public function test_it_resolves_tpay_transaction_channels(): void
{
$gateway = $this->prophesize(GatewayInterface::class);
$value = $this->prophesize(GetTpayTransactionsChannels::class);
- $this->payum->getGateway('tpay')->willReturn($gateway);
+ $this->payum->getGateway('tpay_pbl')->willReturn($gateway);
$this->getTpayTransactionsChannelsFactory->createNewEmpty()->willReturn($value);
$gateway->execute($value, true)->shouldBeCalled();
$value->getResult()->willReturn([
@@ -63,7 +61,7 @@ public function test_it_resolves_an_empty_array_when_tpay_exception_is_thrown():
{
$gateway = $this->prophesize(GatewayInterface::class);
$value = $this->prophesize(GetTpayTransactionsChannels::class);
- $this->payum->getGateway('tpay')->willReturn($gateway);
+ $this->payum->getGateway('tpay_pbl')->willReturn($gateway);
$this->getTpayTransactionsChannelsFactory->createNewEmpty()->willReturn($value);
$gateway
->execute($value, true)
@@ -83,7 +81,7 @@ public function test_it_resolves_an_empty_array_when_the_result_is_not_success()
{
$gateway = $this->prophesize(GatewayInterface::class);
$value = $this->prophesize(GetTpayTransactionsChannels::class);
- $this->payum->getGateway('tpay')->willReturn($gateway);
+ $this->payum->getGateway('tpay_pbl')->willReturn($gateway);
$value->getResult()->willReturn(['result' => 'failure']);
$this->getTpayTransactionsChannelsFactory->createNewEmpty()->willReturn($value);
$gateway->execute($value, true)->shouldBeCalled();
@@ -102,7 +100,7 @@ public function test_it_resolves_an_empty_array_when_the_channels_key_is_missing
{
$gateway = $this->prophesize(GatewayInterface::class);
$value = $this->prophesize(GetTpayTransactionsChannels::class);
- $this->payum->getGateway('tpay')->willReturn($gateway);
+ $this->payum->getGateway('tpay_pbl')->willReturn($gateway);
$value->getResult()->willReturn(['result' => 'success']);
$this->getTpayTransactionsChannelsFactory->createNewEmpty()->willReturn($value);
$gateway->execute($value, true)->shouldBeCalled();
@@ -121,7 +119,7 @@ public function test_it_does_not_log_errors_if_logger_is_null(): void
{
$gateway = $this->prophesize(GatewayInterface::class);
$value = $this->prophesize(GetTpayTransactionsChannels::class);
- $this->payum->getGateway('tpay')->willReturn($gateway);
+ $this->payum->getGateway('tpay_pbl')->willReturn($gateway);
$value->getResult()->willReturn(['result' => 'failure']);
$this->getTpayTransactionsChannelsFactory->createNewEmpty()->willReturn($value);
$gateway->execute($value, true)->shouldBeCalled();
diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml
index e095ecc4..d0682a09 100644
--- a/translations/messages.en.yaml
+++ b/translations/messages.en.yaml
@@ -4,6 +4,7 @@ commerce_weavers_sylius_tpay:
gateway_name:
tpay_blik: 'BLIK (Tpay)'
tpay_card: 'Card (Tpay)'
+ tpay_pbl: 'Pay-by-Link (Tpay)'
gateway_configuration:
cards_api: 'RSA key'
client_id: 'Client ID'
diff --git a/translations/messages.pl.yaml b/translations/messages.pl.yaml
index 22b0cc86..12c82c0c 100644
--- a/translations/messages.pl.yaml
+++ b/translations/messages.pl.yaml
@@ -4,6 +4,7 @@ commerce_weavers_sylius_tpay:
gateway_name:
tpay_blik: 'BLIK (Tpay)'
tpay_card: 'Karta (Tpay)'
+ tpay_pbl: 'Pay-by-Link (Tpay)'
gateway_configuration:
cards_api: 'Klucz RSA'
client_id: 'Client ID'