Esempio n. 1
0
 /**
  * @param FormEvent $event
  */
 public function buildCredentials(FormEvent $event)
 {
     /** @var array $data */
     $data = $event->getData();
     if (is_null($data)) {
         return;
     }
     $propertyPath = is_array($data) ? '[factoryName]' : 'factoryName';
     $factoryName = PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     if (empty($factoryName)) {
         return;
     }
     $form = $event->getForm();
     $form->add('config', 'form');
     $configForm = $form->get('config');
     $gatewayFactory = $this->registry->getGatewayFactory($factoryName);
     $config = $gatewayFactory->createConfig();
     $propertyPath = is_array($data) ? '[config]' : 'config';
     $firstTime = false == PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     foreach ($config['payum.default_options'] as $name => $value) {
         $propertyPath = is_array($data) ? "[config][{$name}]" : "config[{$name}]";
         if ($firstTime) {
             PropertyAccess::createPropertyAccessor()->setValue($data, $propertyPath, $value);
         }
         $type = is_bool($value) ? 'checkbox' : 'text';
         $options = array();
         $options['required'] = in_array($name, $config['payum.required_options']);
         $configForm->add($name, $type, $options);
     }
     $event->setData($data);
 }
 /**
  * @return JsonResponse
  */
 public function getAllAction()
 {
     $normalizedFactories = [];
     foreach ($this->registry->getGatewayFactories() as $name => $factory) {
         $gatewayConfig = new GatewayConfig();
         $gatewayConfig->setFactoryName($name);
         $form = $this->formFactory->create('payum_gateway_config', $gatewayConfig, ['csrf_protection' => false, 'data_class' => GatewayConfig::class]);
         $normalizedFactories[$name]['config'] = $this->formToJsonConverter->convertMeta($form->get('config'));
     }
     $form = $this->formFactory->create('payum_gateway_config', null, ['csrf_protection' => false, 'data_class' => GatewayConfig::class]);
     return new JsonResponse(array('generic' => $this->formToJsonConverter->convertMeta($form), 'meta' => $normalizedFactories));
 }
Esempio n. 3
0
 /**
  * @param GatewayConfigInterface $gatewayConfig
  * 
  * @return GatewayInterface
  */
 protected function createGateway(GatewayConfigInterface $gatewayConfig)
 {
     $config = $gatewayConfig->getConfig();
     if (isset($config['factory'])) {
         $factory = $this->gatewayFactoryRegistry->getGatewayFactory($config['factory']);
         unset($config['factory']);
     } else {
         // BC
         $factory = $this->gatewayFactoryRegistry->getGatewayFactory($gatewayConfig->getFactoryName());
     }
     return $factory->create($config);
 }