Пример #1
0
 protected function processPayment($row)
 {
     if ($row) {
         $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
         // $accountRepo = $manager->getRepository('TSK\PaymentBundle\Entity\Account');
         // $account = $accountRepo->findOneBy(array('name' => 'Inc Fm Students', 'organization' => $this->org));
         $paymentTypeRepo = $manager->getRepository('TSK\\PaymentBundle\\Entity\\PaymentType');
         $paymentMethodRepo = $manager->getRepository('TSK\\PaymentBundle\\Entity\\PaymentMethod');
         // $incomeTypeRepo = $manager->getRepository('TSK\PaymentBundle\Entity\IncomeType');
         // $incomeType = $incomeTypeRepo->findOneBy(array('name' => 'TUITION', 'organization' => $this->org));
         $paymentRepo = $manager->getRepository('TSK\\PaymentBundle\\Entity\\Payment');
         $oldPayment = $paymentRepo->findOneBy(array('legacyPaymentId' => $row[1]));
         $isCash = true;
         if (!$oldPayment) {
             switch ($row[4]) {
                 case 'VISA':
                     $row[4] = 'VISA';
                     break;
                 case 'MC':
                     $row[4] = 'MASTERCARD';
                     break;
                 case 'SCHOOL CREDIT':
                 case 'CREDIT':
                     $row[4] = 'CREDIT';
                     $isCash = false;
                     break;
                 case 'AMEX':
                     $row[4] = 'AMERICAN EXPRESS';
                     break;
                 case 'CHECK':
                     $row[4] = 'CHECK';
                     break;
                 case 'DISCOVER':
                     $row[4] = 'DISCOVER';
                     break;
                 case 'CASH':
                     $row[4] = 'CASH';
                     break;
             }
             $payment = new Payment();
             $payment->setLegacyPaymentId($row[1]);
             $payment->setSchool($this->school);
             $payment->setPaymentType($paymentTypeRepo->findOneBy(array('name' => $row[3], 'organization' => $this->org)));
             $paymentMethod = $paymentMethodRepo->findOneBy(array('name' => $row[4], 'organization' => $this->org));
             if (!$paymentMethod) {
                 print "cannot find paymentMethod for " . $row[4];
                 exit;
             }
             $payment->setPaymentMethod($paymentMethod);
             $payment->setPaymentAmount($row[5]);
             $payment->setCreatedDate(new \DateTime($row[6]));
             $payment->setCreatedUser('mhill');
             $payment->setDescription($row[7]);
             $payment->setRefNumber($row[8]);
             $payment->setIsVoided($row[9]);
             $payment->setIsCash($isCash);
             $chargeRepo = $manager->getRepository('TSK\\PaymentBundle\\Entity\\Charge');
             $charge = $chargeRepo->findOneBy(array('legacyChargeId' => $row[2]));
             if ($charge) {
                 $cp = new ChargePayment();
                 $cp->setCharge($charge);
                 $cp->setPayment($payment);
                 $cp->setAmount(min($charge->getAmount(), $payment->getPaymentAmount()));
                 $manager->persist($cp);
             }
             $manager->persist($payment);
             $manager->flush();
         }
     }
 }
Пример #2
0
 /**
  * Saves a payment
  *
  * @Route("/", name="credit_save")
  * @Method("POST")
  * @Template("TSKPaymentBundle:Default:credit.html.twig")
  */
 public function creditSaveAction(Request $request)
 {
     $session = $this->getRequest()->getSession();
     $sessionKey = $this->container->getParameter('tsk_user.session.org_key');
     $schoolKey = $this->container->getParameter('tsk_user.session.school_key');
     $schoolId = $session->get($schoolKey);
     $em = $this->getDoctrine()->getManager();
     $school = $em->getRepository('TSKSchoolBundle:School')->find($schoolId);
     // this is a little hokey ... searching for payment type when we could otherwise embed it.
     $paymentType = $em->getRepository('TSKPaymentBundle:PaymentType')->findOneBy(array('organization' => $session->get($sessionKey), 'name' => 'credit'));
     $payment = new ReceivePayment();
     if ($paymentType) {
         $payment->setPaymentType($paymentType);
     } else {
         throw new HttpException(404, "Invalid payment type");
     }
     $form = $this->createForm($this->get('tsk_payment.form.type.receivePayment'), $payment, array('is_credit' => true, 'show_date' => $this->canModifyDate()));
     $form->bind($request);
     if ($form->isValid()) {
         $authorizationNum = '';
         if ($payment->getPaymentMethod()->getPaymentType() == 'CREDIT CARD') {
             // if credit card run payment through E4
             $paymentGateway = $this->container->get('tsk_payment.gateway.service');
             $paymentGateway->setCardHoldersName((string) $payment->getContact());
             $paymentGateway->setCreditCardNumber($payment->getCreditCardNumber());
             $paymentGateway->setCreditCardExpiration($payment->getCreditCardExpirationDate());
             $paymentGateway->setCreditCardVerification($payment->getCvvNumber());
             $paymentGateway->setCreditCardType($payment->getPaymentMethod()->getName());
             try {
                 $result = $paymentGateway->purchase($payment->getPaymentAmount());
                 $session->getFlashBag()->add('error', 'There was an error saving your payment!');
                 return $this->redirect($this->generateUrl('tsk_student_default_registerstudent'));
             } catch (\Exception $e) {
             }
             $obj = json_decode($result);
             $authorizationNum = $obj->authorization_num;
         }
         $pmt = new Payment();
         $pmt->setSchool($school);
         $pmt->setPaymentAmount($payment->getPaymentAmount());
         $pmt->setPaymentMethod($payment->getPaymentMethod());
         $pmt->setPaymentType($payment->getPaymentType());
         $pmt->setDescription($payment->getMemo());
         $pmt->setRefNumber($payment->getRefNumber());
         $paymentDate = $payment->getPaymentDate() ? $payment->getPaymentDate() : new \DateTime();
         // $pmt->setCreatedDate($paymentDate);
         $pmt->setAuthorizationNum($authorizationNum);
         $em->persist($pmt);
         $payments = $this->get('request')->request->get('payments');
         foreach ($payment->getCharges() as $charge) {
             if (!empty($payments[$charge->getId()])) {
                 $cp = new ChargePayment();
                 $cp->setCharge($charge);
                 $cp->setPayment($pmt);
                 $cp->setAmount($payments[$charge->getId()]);
                 $em->persist($cp);
             }
         }
         // write to journal?
         $em->flush();
         $dispatcher = $this->get('event_dispatcher');
         $paymentEvent = new PaymentEvent($pmt);
         try {
             $dispatcher->dispatch(PaymentEvents::RECEIVE, $paymentEvent);
         } catch (\Exception $e) {
             throw $e;
         }
         $session->getFlashBag()->add('success', 'Payment saved and applied!');
         return $this->redirect($this->generateUrl('tsk_payment_default_index', array('contactID' => $payment->getContact()->getId())));
     } else {
         $session->getFlashBag()->add('error', 'There was an error saving your payment!');
     }
     return array('entity' => $payment, 'form' => $form->createView());
 }