Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/checkout", name="order_checkout", schemes={"%secure_channel%"})
- * @Security("is_granted('ROLE_USER')")
- */
- public function checkoutAction(Request $request)
- {
- $products = $this->get('shopping_cart')->getProducts();
- /*if (!$this->get('shopping_cart')->getProducts()) {
- $this->addFlash('error', 'It looks like your cart is empty!');
- return $this->redirectToRoute('homepage');
- }*/
- $error = false;
- if ($request->isMethod('POST')) {
- $token = $request->request->get('stripeToken');
- try {
- $this->chargeCustomer($token);
- } catch (\Stripe\Error\Card $e) {
- $error = 'There was a problem charging your card: '.$e->getMessage();
- }
- if (!$error) {
- $this->get('shopping_cart')->emptyCart();
- $this->addFlash('success', 'Order Complete! Yay!');
- return $this->redirectToRoute('homepage');
- }
- }
- return $this->render('order/checkout.html.twig', array(
- 'products' => $products,
- 'cart' => $this->get('shopping_cart'),
- 'stripe_public_key' => $this->getParameter('stripe_public_key'),
- 'error' => $error,
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement