Exemple #1
0
 /**
  * @ParamConverter("paymentMethod", options={"mapping": {"method": "gatewayName"}})
  *
  * @param Request       $request
  * @param PaymentMethod $paymentMethod
  *
  * @return JsonResponse
  */
 public function loadSettingsAction(Request $request, PaymentMethod $paymentMethod = null)
 {
     $methodName = $request->attributes->get('method');
     $paymentFactories = $this->get('payum.factories');
     if (null === $paymentMethod) {
         $paymentMethod = new PaymentMethod();
         $paymentMethod->setGatewayName($methodName);
         $paymentMethod->setFactoryName($paymentFactories->getFactory($methodName));
         $paymentMethod->setName(ucwords(str_replace('_', ' ', $methodName)));
     }
     $originalSettings = $paymentMethod->getConfig();
     $form = $this->createForm(PaymentMethodForm::class, $paymentMethod, ['config' => $paymentFactories->getForm($paymentMethod->getGatewayName()), 'internal' => $paymentFactories->isOffline($paymentMethod->getGatewayName()), 'action' => $this->generateUrl('_payment_method_settings', ['method' => $methodName])]);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $settings = (array) $paymentMethod->getConfig();
         foreach ($settings as $key => $value) {
             if ('password' === $key && null === $value && !empty($originalSettings[$key])) {
                 $settings[$key] = $originalSettings[$key];
             }
         }
         $paymentMethod->setConfig($settings);
         $this->save($paymentMethod);
         $this->flash($this->trans('payment.method.updated'), 'success');
     }
     return $this->json(['content' => $this->renderView('CSBillPaymentBundle:Ajax:loadmethodsettings.html.twig', ['form' => $form->createView(), 'method' => $paymentMethod->getGatewayName()])]);
 }