Example #1
0
 /**
  * Testing payment error
  *
  */
 public function testPaymentSuccess()
 {
     $this->stripeMethod->expects($this->once())->method('getCreditCartNumber')->will($this->returnValue(self::CART_NUMBER));
     $this->stripeMethod->expects($this->once())->method('getCreditCartExpirationMonth')->will($this->returnValue(self::CART_EXPIRE_MONTH));
     $this->stripeMethod->expects($this->once())->method('getCreditCartExpirationYear')->will($this->returnValue(self::CART_EXPIRE_YEAR));
     $this->paymentBridge->expects($this->once())->method('getOrder')->will($this->returnValue(1));
     $this->stripeMethod->expects($this->any())->method('setTransactionId')->with($this->equalTo('123'))->will($this->returnValue($this->stripeMethod));
     $this->stripeMethod->expects($this->any())->method('setTransactionStatus')->with($this->equalTo('paid'))->will($this->returnValue($this->stripeMethod));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue(self::CURRENCY));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue(self::CART_AMOUNT));
     $cart = array('number' => self::CART_NUMBER, 'exp_month' => self::CART_EXPIRE_MONTH, 'exp_year' => self::CART_EXPIRE_YEAR);
     $chargeParams = array('card' => $cart, 'amount' => self::CART_AMOUNT, 'currency' => strtolower(self::CURRENCY));
     $this->stripeTransactionWrapper->expects($this->once())->method('create')->with($chargeParams)->will($this->returnValue(array('paid' => '1', 'id' => '123')));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderLoad')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderCreated')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->any())->method('notifyPaymentOrderFail');
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->stripeManager->processPayment($this->stripeMethod, self::CART_AMOUNT);
 }
 /**
  * Payment execution.
  *
  * @param Request $request Request element
  *
  * @return RedirectResponse
  *
  * @throws PaymentException
  */
 public function executeAction(Request $request)
 {
     /**
      * @var FormInterface $form
      */
     $form = $this->formFactory->create('stripe_view');
     $form->handleRequest($request);
     $redirect = $this->redirectionRoutes->getRedirectionRoute('success');
     try {
         if (!$form->isValid()) {
             throw new PaymentException();
         }
         $data = $form->getData();
         $paymentMethod = $this->createStripeMethod($data);
         $this->stripeManager->processPayment($paymentMethod, $data['amount']);
     } catch (Exception $e) {
         /**
          * Must redirect to fail route.
          */
         $redirect = $this->redirectionRoutes->getRedirectionRoute('failure');
     }
     $redirectUrl = $this->urlGenerator->generate($redirect->getRoute(), $redirect->getRouteAttributes($this->paymentBridge->getOrderId()));
     return new RedirectResponse($redirectUrl);
 }