|
19 | 19 | use Symfony\Component\Form\FormBuilderInterface; |
20 | 20 | use Symfony\Component\Form\FormEvent; |
21 | 21 | use Symfony\Component\Form\FormEvents; |
22 | | -use Symfony\Component\Validator\Constraints\NotBlank; |
23 | 22 |
|
24 | 23 | final class PayPalConfigurationType extends AbstractType |
25 | 24 | { |
26 | | - private const SANDBOX_ATTRIBUTION_ID = 'sylius-ppcp4p-bn-code'; |
27 | | - |
28 | | - private const SANDBOX_SYLIUS_MERCHANT_ID = 'SYLIUS_SANDBOX_MERCHANT_ID'; |
29 | | - |
30 | 25 | private const HIDDEN_FIELDS = [ |
31 | 26 | 'merchant_id', |
32 | 27 | 'sylius_merchant_id', |
33 | 28 | 'partner_attribution_id', |
34 | 29 | 'use_authorize', |
35 | 30 | ]; |
36 | 31 |
|
37 | | - public function __construct(private bool $isSandbox = false) |
38 | | - { |
39 | | - } |
40 | | - |
41 | 32 | public function buildForm(FormBuilderInterface $builder, array $options): void |
42 | 33 | { |
43 | 34 | $originalData = []; |
44 | 35 |
|
45 | | - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { |
46 | | - $form = $event->getForm(); |
47 | | - |
48 | | - if ($this->isSandbox) { |
49 | | - $form |
50 | | - ->add('sylius_merchant_id', HiddenType::class, ['data' => self::SANDBOX_SYLIUS_MERCHANT_ID, 'attr' => ['readonly' => true]]) |
51 | | - ->add('partner_attribution_id', HiddenType::class, ['data' => self::SANDBOX_ATTRIBUTION_ID, 'attr' => ['readonly' => true]]) |
52 | | - ->add('client_id', TextType::class, [ |
53 | | - 'label' => 'sylius_paypal.client_id', |
54 | | - 'constraints' => [new NotBlank(['groups' => 'sylius'])], |
55 | | - ]) |
56 | | - ->add('client_secret', TextType::class, [ |
57 | | - 'label' => 'sylius_paypal.client_secret', |
58 | | - 'constraints' => [new NotBlank(['groups' => 'sylius'])], |
59 | | - ]) |
60 | | - ->add('merchant_id', TextType::class, [ |
61 | | - 'label' => 'sylius_paypal.merchant_id', |
62 | | - 'constraints' => [new NotBlank(['groups' => 'sylius'])], |
63 | | - ]) |
64 | | - ; |
65 | | - } else { |
66 | | - $form |
67 | | - ->add('sylius_merchant_id', HiddenType::class, ['attr' => ['readonly' => true]]) |
68 | | - ->add('partner_attribution_id', HiddenType::class, ['attr' => ['readonly' => true]]) |
69 | | - ->add('client_id', TextType::class, ['label' => 'sylius_paypal.client_id', 'attr' => ['readonly' => true]]) |
70 | | - ->add('client_secret', TextType::class, ['label' => 'sylius_paypal.client_secret', 'attr' => ['readonly' => true]]) |
71 | | - ->add('merchant_id', HiddenType::class, ['attr' => ['readonly' => true]]) |
72 | | - ; |
73 | | - } |
74 | | - |
75 | | - $form |
76 | | - // we need to force Sylius Payum integration to postpone creating an order, it's the easiest way |
77 | | - ->add('use_authorize', HiddenType::class, ['data' => true, 'attr' => ['readonly' => true]]) |
78 | | - ->add('reports_sftp_username', TextType::class, ['label' => 'sylius_paypal.sftp_username', 'required' => false]) |
79 | | - ->add('reports_sftp_password', TextType::class, ['label' => 'sylius_paypal.sftp_password', 'required' => false]) |
80 | | - ; |
81 | | - }); |
| 36 | + $builder |
| 37 | + ->add('client_id', TextType::class, ['label' => 'sylius_paypal.client_id', 'attr' => ['readonly' => true]]) |
| 38 | + ->add('client_secret', TextType::class, ['label' => 'sylius_paypal.client_secret', 'attr' => ['readonly' => true]]) |
| 39 | + ->add('merchant_id', HiddenType::class, ['label' => 'sylius_paypal.client_secret', 'attr' => ['readonly' => true]]) |
| 40 | + ->add('sylius_merchant_id', HiddenType::class, ['label' => 'sylius_paypal.client_secret', 'attr' => ['readonly' => true]]) |
| 41 | + ->add('partner_attribution_id', HiddenType::class, ['label' => 'sylius_paypal.partner_attribution_id', 'attr' => ['readonly' => true]]) |
| 42 | + // we need to force Sylius Payum integration to postpone creating an order, it's the easiest way |
| 43 | + ->add('use_authorize', HiddenType::class, ['data' => true, 'attr' => ['readonly' => true]]) |
| 44 | + ->add('reports_sftp_username', TextType::class, ['label' => 'sylius_paypal.sftp_username', 'required' => false]) |
| 45 | + ->add('reports_sftp_password', TextType::class, ['label' => 'sylius_paypal.sftp_password', 'required' => false]) |
| 46 | + ; |
82 | 47 |
|
83 | 48 | $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use (&$originalData): void { |
84 | 49 | $data = $event->getData(); |
|
0 commit comments