03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

E-Commerce 274<br />

43 $orderItem->save();<br />

44<br />

45 $product->stock -= $item->quantity;<br />

46 $product->save();<br />

47<br />

48 $total += $orderItem->quantity * $orderItem->price;<br />

49 }<br />

50<br />

51 $result = $this->gateway->pay(<br />

52 Input::get("number"),<br />

53 Input::get("expiry"),<br />

54 $total,<br />

55 "usd"<br />

56 );<br />

57<br />

58 if (!$result)<br />

59 {<br />

60 return Response::json([<br />

61 "status" => "error",<br />

62 "errors" => [<br />

63 "gateway" => [<br />

64 "Payment error"<br />

65 ]<br />

66 ]<br />

67 ]);<br />

68 }<br />

69<br />

70 $account = $order->account;<br />

71<br />

72 $document = $this->document->create($order);<br />

73 $this->messenger->send($order, $document);<br />

74<br />

75 return Response::json([<br />

76 "status" => "ok",<br />

77 "order" => $order->toArray()<br />

78 ]);<br />

79 }<br />

80<br />

81 return Response::json([<br />

82 "status" => "error",<br />

83 "errors" => $validator->errors()->toArray()<br />

84 ]);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!