public static function savePurchase() { $Purchase = new Purchase(); $Purchase->user_id = User::getTestUser()->id; $Purchase->price = Input::get('amountInput'); $Purchase->name_on_card = Input::get('nameOnCardInput'); $Purchase->card_number = Input::get('cardNumberInput1') . '-' . Input::get('cardNumberInput2') . '-' . Input::get('cardNumberInput3') . '-' . Input::get('cardNumberInput4'); $Purchase->expiry_date = Input::get('expiry_date_month') . '/' . Input::get('expiry_date_year'); $Purchase->address = Input::get('address1Input'); $Purchase->alt_address = Input::get('address2Input'); $Purchase->city = Input::get('cityInput'); $Purchase->post_code = Input::get('postcodeInput'); $Purchase->state = Input::get('stateInput'); $Purchase->country = Input::get('countryInput'); $Purchase->save(); return $Purchase; }
public function submitPaymentForm(Request $request) { //Check Validation with custom messages $messages = array('cardNumberInput1.number' => 'Card Number has to be a number', 'cardNumberInput2.number' => 'Card Number has to be a number', 'cardNumberInput3.number' => 'Card Number has to be a number', 'cardNumberInput4.number' => 'Card Number has to be a number'); $validator = Validator::make($request->all(), ['memberName' => 'required', 'amountInput' => 'required', 'nameOnCardInput' => 'required||max:255', 'cardNumberInput1' => 'required|numeric', 'cardNumberInput2' => 'required|numeric', 'cardNumberInput3' => 'required|numeric', 'cardNumberInput4' => 'required|numeric', 'expiry_date_month' => 'required|numeric|between:1,12', 'address1Input' => 'required|max:255', 'address2Input' => 'max:255', 'cityInput' => 'required|max:255', 'postcodeInput' => 'required|max:255', 'stateInput' => 'required|max:255', 'countryInput' => 'required|max:255'], $messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Purchase::savePurchase(); return Redirect::to('/')->with('success', 'Congratulations! Your Purchase Saved Successfully.'); }
public function savePurchases(array $data) { if (is_array($data) === true) { foreach ($data as $data) { Purchase::create(['purchaser_name' => $data[0], 'item_description' => $data[1], 'item_price' => $data[2], 'purchase_count' => $data[3], 'merchant_address' => $data[4], 'merchant_name' => $data[5]]); } return true; } else { return false; } }
public function checkout() { $cart = Cart::where('user_id', Auth::user()->id)->first(); $items = $cart->cartItems; foreach ($items as $item) { CartItem::destroy($item->id); $productID = $item['product_id']; $product = Product::where('id', $productID)->first(); if ($product->stock > 0) { $newStock = $product->stock; $newStock -= 1; Product::where('id', $productID)->update(['stock' => $newStock]); $purchase = new Purchase(); $purchase->user_id = Auth::user()->id; $purchase->product_id = $productID; $purchase->save(); } } $products = Product::all(); return view('main.index', ['products' => $products]); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $squares = $request->input('chosen'); $purchase = Purchase::create(array('name' => $request->input('name'), 'email' => $request->input('email'))); foreach ($squares as $square_id) { $s = Square::find($square_id); $s->class = 'taken'; $s->status = 'purchased'; $s->save(); PurchaseSquare::create(array('purchase_id' => $purchase->id, 'square_id' => $s->id)); } return PurchaseSquare::where('purchase_id', $purchase->id)->get(); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { \Stripe\Stripe::setApiKey(env('STRIPE_PRI', null)); // Create a Customer $customer = \Stripe\Customer::create(array("source" => $request->input('token_id'), "description" => $request->input('name') . ' ' . $request->input('email'))); // Charge the Customer instead of the card \Stripe\Charge::create(array("amount" => $request->input('price') * 100, "currency" => "usd", "customer" => $customer->id)); $set = Set::find(1); $data = array('set_id' => $set->id, 'customer_id' => $customer->id, 'price' => $request->input('price'), 'name' => $request->input('name'), 'email' => $request->input('email'), 'optin' => $request->input('optin')); if ($request->has('media_id')) { $data['media_id'] = $request->input('media_id'); } else { if ($request->has('color')) { $data['color'] = $request->input('color'); } } $purchase = Purchase::create($data); // Mobile doesn't have chosen array if ($request->has('mobile')) { $squares = Square::where('status', 'available')->where('set_id', $set->id)->take($request->input('blocks'))->get(); foreach ($squares as $s) { $s->class = 'taken'; $s->status = 'unavailable'; $s->save(); PurchaseSquare::create(array('purchase_id' => $purchase->id, 'square_id' => $s->id, 'set_id' => $set->id)); } } else { $squares = $request->input('chosen'); foreach ($squares as $square_id) { $s = Square::find($square_id); $s->class = 'taken'; $s->status = 'unavailable'; $s->save(); PurchaseSquare::create(array('purchase_id' => $purchase->id, 'square_id' => $s->id, 'set_id' => $set->id)); } } return $purchase; }
public function Delete($task_id) { $task = Purchase::destroy($task_id); return Response::json($task); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $purchases = Purchase::where('user_id', Auth::user()->id)->get(); return view('purchases.index', ['purchases' => $purchases]); }
public function getHistorico() { $sale = Transaction::whereHas('book', function ($q) { $q->where('id_user', '=', \Auth::user()->id); })->get(); $sale->sum('price'); $myRental = Aluguer::whereHas('book', function ($q) { $q->where('id_user', '=', \Auth::user()->id); })->get(); $purchases = Purchase::where('user_id', '=', \Auth::user()->id)->get(); $rental = Aluguer::where('user_id', '=', \Auth::user()->id)->get(); $user = \App\User::find(\Auth::user()->id); return view('historico', ['purchases' => $purchases, 'sales' => $sale, 'rentals' => $rental, 'myRentals' => $myRental, 'user' => $user]); }
/** * Destroy the given purchase. * * @param Request $request * @param Task $task * @return Response */ public function destroy(Request $request, Purchase $purchase) { //$this->authorize('destroy', $product); $purchase->delete(); return redirect('/purchase'); }
public function saveAluguer($articles, $payment_id) { foreach ($articles as $article) { if ($article['option'] == 'rent' && $article['days'] > 0) { $rent = new Aluguer(); $rent->start = date('Y-m-d H:i:s'); $rent->end = date('Y-m-d H:i:s', strtotime('+' . $article['days'] . ' days', strtotime($rent->start))); $rent->book_id = $article['id']; $rent->user_id = Auth::user()->id; $rent->payment_id = $payment_id; $rent->save(); } else { $purchase = new Purchase(); $purchase->book_id = $article['id']; $purchase->user_id = Auth::user()->id; $purchase->payment_id = $payment_id; $purchase->save(); } } }
/** * Display a listing of the resource. * /api/admin/purchases * @return Response */ public function index() { $purchases = Purchase::with('squares', 'media')->orderby('created_at', 'desc')->paginate(10); $purchases->setPath('purchases'); return view('admin.purchases', ['purchases' => $purchases]); }
/** * Display a listing of the resource. * * @return Response */ public function thanks($purchase_id) { $purchase = Purchase::find($purchase_id); $set = Set::with('squares.purchase.media')->where('id', 1)->first(); return view('public.thanks', ['set' => $set, 'purchase' => $purchase]); }