Skip to content
Closed
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file must be deleted, as it's unnecessary in the new impl.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
{
public function __invoke(FormEvent $event): void
{
return;
/** @var array{card?: string, blik_token?: string, tpay_channel_id?: string} $data */
$data = $event->getData() ?? [];

Check failure on line 15 in src/Form/EventListener/RemoveUnnecessaryPaymentDetailsFieldsListener.php

View workflow job for this annotation

GitHub Actions / CI / Sylius ~2.0.0, PHP 8.2, Symfony ~6.4.0, MySQL 8.0, State Machine winzou_state_machine

Unreachable statement - code above always terminates.

Check failure on line 15 in src/Form/EventListener/RemoveUnnecessaryPaymentDetailsFieldsListener.php

View workflow job for this annotation

GitHub Actions / CI / Sylius ~2.1.0, PHP 8.4, Symfony ~7.3.0, MySQL 8.0, State Machine symfony_workflow

Unreachable statement - code above always terminates.
$form = $event->getForm();

if (!isset($data['card'])) {
Expand Down
9 changes: 8 additions & 1 deletion src/Form/Extension/CompleteTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace CommerceWeavers\SyliusTpayPlugin\Form\Extension;

use CommerceWeavers\SyliusTpayPlugin\Form\Type\TpayPaymentDetailsType;
use CommerceWeavers\SyliusTpayPlugin\Model\OrderLastNewPaymentAwareInterface;
use CommerceWeavers\SyliusTpayPlugin\PayByLinkPayment\Validator\Constraint\RequiresTpayChannelId;
use Sylius\Bundle\CoreBundle\Form\Type\Checkout\CompleteType;
use Sylius\Component\Core\Model\OrderInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraints\Valid;

final class CompleteTypeExtension extends AbstractTypeExtension
Expand All @@ -34,7 +36,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
'error_bubbling' => false,
'property_path' => 'last_cart_payment.details[tpay]',
'validation_groups' => ['sylius_checkout_complete'],
'validation_groups' => static function (FormInterface $form) {
$order = $form->getRoot()->getData();
assert($order instanceof OrderLastNewPaymentAwareInterface);

return [$order->getLastCartPayment()?->getMethod()?->getGatewayConfig()?->getFactoryName()];
},
],
)
;
Expand Down
14 changes: 14 additions & 0 deletions src/Form/Extension/PaymentTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace CommerceWeavers\SyliusTpayPlugin\Form\Extension;

use CommerceWeavers\SyliusTpayPlugin\Form\Type\TpayPaymentDetailsType;
use CommerceWeavers\SyliusTpayPlugin\Model\OrderLastNewPaymentAwareInterface;
use Sylius\Bundle\CoreBundle\Form\Type\Checkout\PaymentType;
use Sylius\Component\Core\Model\OrderInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;

final class PaymentTypeExtension extends AbstractTypeExtension
{
Expand All @@ -19,6 +22,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
TpayPaymentDetailsType::class,
[
'property_path' => 'details[tpay]',
'validation_groups' => static function (FormInterface $form) {
$order = $form->getRoot()->getData();
assert($order instanceof OrderInterface);
assert($order instanceof OrderLastNewPaymentAwareInterface);

if ($order->getState() === OrderInterface::STATE_CART) {
return ['Default'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it should be Default or Default with sylius.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should inject the sylius.form.type.checkout_payment.validation_groups param, return it if the state is equal to the STATE_CART, return it with the factory name otherwise.

}

return [$order->getLastPayment('new')?->getMethod()?->getGatewayConfig()?->getFactoryName()];
},
],
)
;
Expand Down
23 changes: 13 additions & 10 deletions src/Form/Type/TpayPaymentDetailsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;

final class TpayPaymentDetailsType extends AbstractType
Expand Down Expand Up @@ -48,9 +49,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'data' => null,
'property_path' => '[blik_token]',
'label' => 'commerce_weavers_sylius_tpay.shop.order_summary.blik.token',
'validation_groups' => ['sylius_checkout_complete'],
'constraints' => [
new Length(exactly: 6, groups: ['sylius_checkout_complete']),
new NotBlank(groups: ['tpay_blik']),
new Length(exactly: 6, groups: ['tpay_blik']),
],
],
)
Expand All @@ -60,9 +61,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
[
'property_path' => '[google_pay_token]',
'label' => false,
'validation_groups' => ['sylius_checkout_complete'],
'constraints' => [
new EncodedGooglePayToken(groups: ['sylius_checkout_complete']),
new NotBlank(groups: ['tpay_google_pay']),
new EncodedGooglePayToken(groups: ['tpay_google_pay']),
],
],
)
Expand All @@ -72,19 +73,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
[
'property_path' => '[apple_pay_token]',
'label' => false,
'validation_groups' => ['sylius_checkout_complete'],
'constraints' => [
new NotBlank(groups: ['tpay_apple_pay']),
],
],
)
->add(
'tpay_channel_id',
HiddenType::class,
[
'constraints' => [
new ValidTpayChannel(groups: ['sylius_checkout_complete']),
new NotBlank(groups: ['tpay_pbl']),
new ValidTpayChannel(groups: ['tpay_pbl']),
],
'error_bubbling' => false,
'property_path' => '[tpay_channel_id]',
'validation_groups' => ['sylius_checkout_complete'],
],
)
->add(
Expand All @@ -96,13 +99,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'placeholder' => 'commerce_weavers_sylius_tpay.shop.order_summary.visa_mobile.placeholder',
'maxLength' => 15,
],
'validation_groups' => ['sylius_checkout_complete'],
'constraints' => [
new Length(min: 7, max: 15, groups: ['sylius_checkout_complete']),
new NotBlank(groups: ['tpay_visa_mobile']),
new Length(min: 7, max: 15, groups: ['tpay_visa_mobile']),
new Regex(
'/^\d+$/',
message: 'commerce_weavers_sylius_tpay.shop.pay.visa_mobile.regex',
groups: ['sylius_checkout_complete'],
groups: ['tpay_visa_mobile'],
),
],
'label' => 'sylius.ui.phone_number',
Expand Down
2 changes: 2 additions & 0 deletions templates/shop/order/pay/pay_by_link.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<div data-payment-details="tpay_pbl">
{{ component('cw_tpay_shop:pay_by_link:channel_picker', { 'order': get_hookable_context().resource }) }}

{{ form_errors(form.tpay.tpay_channel_id) }}

{{ form_row(form.tpay.tpay_channel_id, { attr: { 'data-tpay-channel-id': '' } }) }}
</div>

Expand Down
Loading