Exemplo n.º 1
0
 /**
  * @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()))));
 }
Exemplo n.º 2
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()])]);
 }