/** * @ParamConverter("paymentMethod", options={"mapping": {"method": "paymentMethod"}}) * * @param Request $request * @param PaymentMethod $paymentMethod * * @return JsonResponse */ public function loadSettingsAction(Request $request, PaymentMethod $paymentMethod = null) { if (null === $paymentMethod) { $paymentMethod = new PaymentMethod(); $paymentMethod->setPaymentMethod($request->attributes->get('method')); $paymentMethod->setName(ucwords(str_replace('_', ' ', $request->attributes->get('method')))); } $originalSettings = $paymentMethod->getSettings(); /** @var \CSBill\PaymentBundle\Payum $payum */ $payum = $this->get('payum'); $registry = $this->get('form.registry'); $form = $this->createForm(new PaymentMethodForm(), $paymentMethod, array('settings' => $registry->hasType($paymentMethod->getPaymentMethod()) ? $paymentMethod->getPaymentMethod() : null, 'internal' => $payum->isOffline($paymentMethod->getPaymentMethod()))); $form->handleRequest($request); if ($form->isValid()) { $settings = (array) $paymentMethod->getSettings(); foreach ($settings as $key => $value) { if ('password' === $key && null === $value && !empty($originalSettings[$key])) { $settings[$key] = $originalSettings[$key]; } } $paymentMethod->setSettings($settings); $this->save($paymentMethod); $this->flash($this->trans('payment.method.updated'), 'success'); } return new JsonResponse(array('content' => $this->renderView('CSBillPaymentBundle:Ajax:loadmethodsettings.html.twig', array('form' => $form->createView(), 'method' => $paymentMethod->getPaymentMethod())))); }