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