コード例 #1
0
 /**
  * Execute action
  *
  * @param Request $request
  *
  * @return RedirectResponse
  */
 public function executeAction(Request $request)
 {
     /**
      * @var FormInterface $form
      */
     $form = $this->get('form.factory')->create('paymill_view');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $paymentMethod = new BanwireMethod();
         $paymentMethod->setCardType($data['card_type'])->setCardName($data['card_name'])->setCardNum($data['card_num'])->setCardExpMonth($data['card_exp_month'])->setCardExpYear($data['card_exp_year'])->setCardSecurity($data['card_ccv2']);
         try {
             $this->get('banwire.manager')->processPayment($paymentMethod, $data['amount']);
             $redirectUrl = $this->container->getParameter('banwire.success.route');
             $redirectAppend = $this->container->getParameter('banwire.success.order.append');
             $redirectAppendField = $this->container->getParameter('banwire.success.order.field');
         } catch (PaymentException $e) {
             /**
              * Must redirect to fail route
              */
             $redirectUrl = $this->container->getParameter('banwire.fail.route');
             $redirectAppend = $this->container->getParameter('banwire.fail.order.append');
             $redirectAppendField = $this->container->getParameter('banwire.fail.order.field');
         }
     } else {
         /**
          * If form is not valid, fail return page
          */
         $redirectUrl = $this->container->getParameter('banwire.fail.route');
         $redirectAppend = $this->container->getParameter('banwire.fail.order.append');
         $redirectAppendField = $this->container->getParameter('banwire.fail.order.field');
     }
     $redirectData = $redirectAppend ? array($redirectAppendField => $this->get('payment.bridge')->getOrderId()) : array();
     return $this->redirect($this->generateUrl($redirectUrl, $redirectData));
 }
コード例 #2
0
ファイル: BanwireManager.php プロジェクト: hason/paymentsuite
 /**
  * Given a paymillTransaction response, as an array, prform desired operations
  *
  * @param string        $apiResponse   Api response
  * @param BanwireMethod $paymentMethod Payment method
  *
  * @return BanwireManager Self object
  *
  * @throws PaymentException
  */
 private function processTransaction($apiResponse, BanwireMethod $paymentMethod)
 {
     $banwireParams = json_decode($apiResponse);
     if (isset($banwireParams->order_id)) {
         $paymentMethod->setBanwireTransactionId($banwireParams->order_id);
     }
     if (isset($banwireParams->referencia)) {
         $paymentMethod->setBanwireReference($banwireParams->referencia);
     }
     /**
      * Payment paid done
      *
      * Paid process has ended ( No matters result )
      */
     $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod);
     if ($banwireParams->response == 'ok') {
         $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod);
     } else {
         $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod);
         throw new PaymentException();
     }
     /**
      * Log the response of gateway
      */
     return $this;
 }