osb/app/Http/Controllers/CheckoutController.php

68 lines
1.5 KiB
PHP
Raw Normal View History

2020-07-27 04:49:59 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
2020-07-27 04:49:59 +00:00
use Illuminate\Http\Request;
use App\Http\Requests\CheckoutAddEdit;
use App\Models\{Checkout,Invoice};
2020-07-27 04:49:59 +00:00
class CheckoutController extends Controller
{
/**
* Update a checkout details
*
* @param CheckoutAddEdit $request
* @param Checkout $o
* @return RedirectResponse
*/
public function addedit(CheckoutAddEdit $request,Checkout $o): RedirectResponse
{
foreach ($request->validated() as $key => $item)
$o->{$key} = $item;
$o->active = (bool)$request->validated('active',FALSE);
try {
$o->save();
} catch (\Exception $e) {
return redirect()
->back()
->withErrors($e->getMessage())->withInput();
}
return $o->wasRecentlyCreated
? redirect()
->to('a/checkout/'.$o->id)
->with('success','Checkout added')
: redirect()
->back()
->with('success','Checkout 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');
2020-07-27 04:49:59 +00:00
return view('theme.backend.adminlte.u.invoice.cart')
2020-07-27 04:49:59 +00:00
->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));
}
public function pay(Request $request,Checkout $o)
{
return redirect('pay/paypal/authorise');
}
}