コード例 #1
0
 /**
  * @Route("/publish/{id}/follow-up/{petition}", requirements={"id"="\d+"})
  * @Template("CivixFrontBundle:PaymentRequest:follow-up-publish.html.twig")
  */
 public function publishFollowUpAction(Request $request, $id, Petition $petition)
 {
     $paymentRequest = $this->getPaymentRequest($id);
     $package = $this->get('civix_core.subscription_manager')->getPackage($this->getUser());
     if ($paymentRequest->getUser() !== $this->getUser() || $paymentRequest->getPublishedAt() || !$package->isTargetedPetitionFundraisingAvailable()) {
         throw new AccessDeniedHttpException();
     }
     $users = $this->getDoctrine()->getRepository(Answer::class)->findSignedUsersByPetition($petition);
     $amount = $package->getTargetedPetitionFundraisingPrice() * count($users);
     $form = $this->createForm('form', null, ['label' => $amount / 100 . '$']);
     if ('POST' === $request->getMethod() && $form->submit($request)->isValid()) {
         if (intval($request->get('user_count')) !== count($users)) {
             $this->get('session')->getFlashBag()->add('notice', 'Users amount has changed. Please review.');
         } else {
             try {
                 $this->get('civix_core.stripe')->chargeUser($this->getUser(), $amount, 'PowerlinePay', 'Powerline Payment:  Payment Request Publishing');
             } catch (\Stripe\Error\Card $e) {
                 $this->get('session')->getFlashBag()->add('error', $e->getJsonBody()['error']['message']);
                 return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_paymentrequest_publishfollowup", ['id' => $id, 'petition' => $petition->getId()]));
             }
             $paymentRequest->setPublishedAt(new \DateTime());
             $ignore = new Option();
             $ignore->setPaymentAmount(0)->setValue('Ignore')->setQuestion($paymentRequest);
             $this->getDoctrine()->getManager()->persist($ignore);
             $this->getDoctrine()->getManager()->flush($paymentRequest);
             $this->getDoctrine()->getManager()->flush($ignore);
             $this->get('civix_core.activity_update')->publishPaymentRequestToActivity($paymentRequest, $users);
             if ($paymentRequest->getIsAllowOutsiders()) {
                 /* @var User $user */
                 foreach ($users as $user) {
                     if (!$user->getIsRegistrationComplete()) {
                         $this->get('civix_core.email_sender')->sendPaymentRequest($paymentRequest, $user);
                     }
                 }
             }
             return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_paymentrequest_index"));
         }
     }
     return ['paymentRequest' => $paymentRequest, 'users' => $users, 'petition' => $petition, 'hasCard' => $this->get('civix_core.stripe')->hasCard($this->getUser()), 'form' => $form->createView()];
 }
 public function setPaymentAmount($payment_amount)
 {
     $this->__load();
     return parent::setPaymentAmount($payment_amount);
 }