2020-07-27 04:49:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2022-07-29 06:06:19 +00:00
|
|
|
use Illuminate\View\View;
|
2020-07-27 04:49:59 +00:00
|
|
|
|
2022-07-29 06:06:19 +00:00
|
|
|
use App\Http\Requests\CheckoutAddEdit;
|
|
|
|
use App\Models\{Checkout,Invoice};
|
2020-07-27 04:49:59 +00:00
|
|
|
|
|
|
|
class CheckoutController extends Controller
|
|
|
|
{
|
2022-07-29 06:06:19 +00:00
|
|
|
/**
|
|
|
|
* Update a suppliers details
|
|
|
|
*
|
|
|
|
* @param CheckoutAddEdit $request
|
|
|
|
* @param Checkout $o
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function addedit(CheckoutAddEdit $request,Checkout $o)
|
|
|
|
{
|
|
|
|
$this->middleware(['auth','wholesaler']);
|
|
|
|
|
|
|
|
foreach ($request->except(['_token','active','submit']) as $key => $item)
|
|
|
|
$o->{$key} = $item;
|
|
|
|
|
|
|
|
$o->active = (bool)$request->active;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$o->save();
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return redirect()->back()->withErrors($e->getMessage())->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back()
|
|
|
|
->with('success','Payment saved');
|
|
|
|
}
|
|
|
|
|
2020-07-27 04:49:59 +00:00
|
|
|
public function cart_invoice(Request $request,Invoice $o=NULL)
|
|
|
|
{
|
|
|
|
if ($o) {
|
|
|
|
$request->session()->put('invoice.cart.'.$o->id,$o->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $request->session()->get('invoice.cart'))
|
|
|
|
return redirect()->to('u/home');
|
|
|
|
|
|
|
|
return View('u.invoice.cart')
|
|
|
|
->with('invoices',Invoice::find(array_values($request->session()->get('invoice.cart'))));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fee(Request $request,Checkout $o): float
|
|
|
|
{
|
|
|
|
return $o->fee($request->post('total',0));
|
|
|
|
}
|
|
|
|
|
2022-07-29 06:06:19 +00:00
|
|
|
/**
|
|
|
|
* Render a specific invoice for the user
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function home(): View
|
|
|
|
{
|
|
|
|
return View('payment.home');
|
|
|
|
}
|
|
|
|
|
2020-07-27 04:49:59 +00:00
|
|
|
public function pay(Request $request,Checkout $o)
|
|
|
|
{
|
|
|
|
return redirect('pay/paypal/authorise');
|
|
|
|
}
|
2022-07-29 06:06:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View details on a specific payment method
|
|
|
|
*
|
|
|
|
* @param Checkout $o
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function view(Checkout $o): View
|
|
|
|
{
|
|
|
|
return View('payment.view',['o'=>$o]);
|
|
|
|
}
|
2020-07-27 04:49:59 +00:00
|
|
|
}
|