/** * Store a newly created orderitem in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Orderitem::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Orderitem::create($data); return Redirect::route('orderitems.index'); }
public function buy($id) { if (Useradd::where('user_id', '=', Auth::user()->id)->first()) { $product = Product::find($id); $quantity = Input::get("quantity"); if (intval($quantity) < $product->stock) { $name = $product->name; $price = intval($product->price); $tax = intval($product->price) * 0.2; $fdp = 4.0; $total = (intval($product->price) + $tax) * intval($quantity) + $fdp; $user = "******"; $password = "******"; $signature = "AoGYbXCKniGwhG49iNKxRHnnmLrYAFTKM07RzfsOtBl3ppaYNM3k0CEj"; $params = array('METHOD' => 'SetExpressCheckout', 'VERSION' => '93', 'USER' => $user, 'SIGNATURE' => $signature, 'PWD' => $password, 'RETURNURL' => "http://dcmstore.io/paypal/success", 'CANCELURL' => "http://dcmstore.io/paypal/error", 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'L_PAYMENTREQUEST_0_NAME0' => $name, 'L_PAYMENTREQUEST_0_AMT0' => strval($price), 'L_PAYMENTREQUEST_0_QTY0' => $quantity, 'PAYMENTREQUEST_0_ITEMAMT' => strval($price * intval($quantity)), 'PAYMENTREQUEST_0_TAXAMT' => strval($tax * $quantity), 'PAYMENTREQUEST_0_SHIPPINGAMT' => strval($fdp), 'PAYMENTREQUEST_0_HANDLINGAMT' => '0.00', 'PAYMENTREQUEST_0_SHIPDISCAMT' => '0.00', 'PAYMENTREQUEST_0_INSURANCEAMT' => '0.00', 'PAYMENTREQUEST_0_AMT' => strval($total), 'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR', 'ALLOWNOTE' => '1'); $params = http_build_query($params); $endpoint = 'https://api-3T.sandbox.paypal.com/nvp'; $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_URL => $endpoint, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_VERBOSE => 1)); $response = curl_exec($curl); $responseArray = array(); parse_str($response, $responseArray); curl_close($curl); if ($responseArray['ACK'] == 'Success') { $user = Useradd::where('user_id', '=', Auth::user()->id)->first(); $order_id = Order::insertGetId(array('user_id' => auth::user()->id, 'date' => \Carbon\Carbon::now(), 'price' => $total, 'add_id' => $user->id, 'rcp_id' => $user->id, 'note' => 'null', 'status' => 0, 'token' => $responseArray['TOKEN'])); $oders_items = Orderitem::create(array('order_id' => $order_id, 'item_id' => $id, 'item_qt' => $quantity, 'unit_price' => $price)); $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $responseArray['TOKEN']; return Redirect::to($url); } } else { return Redirect::to('product/' . $id)->with('message', 'Stock insuffisant'); } } else { return Redirect::to('product/' . $id)->with('message', 'Veuillez renseigner une addresse dans le dashboard!'); } }
public function add($listings) { foreach ($listings as $idx => $listing) { Orderitem::create(['listing_id' => $listing->id, 'order_id' => $this->id]); } }