File: D:/HostingSpaces/fire-tech/fire-tech.nl/app/KommaApp/Shop/Checkout/CheckoutController.php
<?php
namespace App\KommaApp\Shop\Checkout;
use App\Http\Controllers\Controller;
use App\KommaApp\Shop\Cart\ShoppingCartItemInterface;
use App\KommaApp\Shop\Cart\ShoppingCartService;
use App\KommaApp\Shop\Cart\ShoppingCartServiceInterface;
use App\KommaApp\Shop\Orders\Kms\OrderMailServiceInterface;
use Illuminate\View\View;
/**
* Handles the checkout process and the different views
*
* Class ShoppingCartService
* @package App\KommaApp\Shop\Cart
*/
class CheckoutController extends Controller
{
/** @var CheckoutServiceInterface $checkoutService */
private $checkoutService;
/** @var ShoppingCartService $shoppingCartService */
private $shoppingCartService;
/** @var OrderMailServiceInterface $orderMailService */
private $orderMailService;
/**
* CheckoutController constructor.
* @param CheckoutServiceInterface $checkoutService
* @param OrderMailServiceInterface $orderMailService
* @param ShoppingCartServiceInterface $shoppingCartService
*/
public function __construct(CheckoutServiceInterface $checkoutService, OrderMailServiceInterface $orderMailService, ShoppingCartServiceInterface $shoppingCartService)
{
$this->checkoutService = $checkoutService;
$this->shoppingCartService = $shoppingCartService;
$this->orderMailService = $orderMailService;
}
/**
* Triggered in response of a push on a checkout button
* @throws \Throwable
*/
public function checkout()
{
/** @var ShoppingCartItemInterface[] $items */
$order = $this->checkoutService->createOrderFromShoppingCartItemsForCustomer($this->shoppingCartService->getItems(), \Auth::user());
$this->orderMailService->mailCustomerAboutCurrentOrderStatus($order, \Auth::user());
$this->orderMailService->mailStaffAboutCurrentOrderStatus($order);
//TODO: Push the order to a payment service provider
}
/**
* @return View
*/
public function index()
{
return $this->checkoutView();
}
/**
* @return View
*/
protected function checkoutView(): View
{
return view('shop.pages.checkout.index');
}
}