SHARE
TWEET

Untitled

a guest Mar 13th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * @Route("/checkout", name="order_checkout", schemes={"%secure_channel%"})
  3.      * @Security("is_granted('ROLE_USER')")
  4.      */
  5.     public function checkoutAction(Request $request)
  6.     {
  7.  
  8.         $products = $this->get('shopping_cart')->getProducts();
  9.  
  10.         /*if (!$this->get('shopping_cart')->getProducts()) {
  11.             $this->addFlash('error', 'It looks like your cart is empty!');
  12.  
  13.             return $this->redirectToRoute('homepage');
  14.         }*/
  15.  
  16.         $error = false;
  17.         if ($request->isMethod('POST')) {
  18.             $token = $request->request->get('stripeToken');
  19.  
  20.             try {
  21.                 $this->chargeCustomer($token);
  22.             } catch (\Stripe\Error\Card $e) {
  23.                 $error = 'There was a problem charging your card: '.$e->getMessage();
  24.             }
  25.  
  26.             if (!$error) {
  27.                 $this->get('shopping_cart')->emptyCart();
  28.                 $this->addFlash('success', 'Order Complete! Yay!');
  29.  
  30.                 return $this->redirectToRoute('homepage');
  31.             }
  32.         }
  33.  
  34.         return $this->render('order/checkout.html.twig', array(
  35.             'products' => $products,
  36.             'cart' => $this->get('shopping_cart'),
  37.             'stripe_public_key' => $this->getParameter('stripe_public_key'),
  38.             'error' => $error,
  39.         ));
  40.  
  41.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top