HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Shop/Checkout/CheckoutController.php
<?php

namespace App\Komma\Shop\Checkout;

use App\Http\Controllers\Controller;
use App\Komma\Shop\Cart\ShoppingCartItemInterface;
use App\Komma\Shop\Cart\ShoppingCartService;
use App\Komma\Shop\Cart\ShoppingCartServiceInterface;
use App\Komma\Shop\Orders\Kms\OrderMailServiceInterface;
use Illuminate\View\View;

/**
 * Handles the checkout process and the different views
 *
 * Class ShoppingCartService
 */
class CheckoutController extends Controller
{
    /** @var CheckoutServiceInterface */
    private $checkoutService;

    /** @var ShoppingCartService */
    private $shoppingCartService;

    /** @var OrderMailServiceInterface */
    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);

        return $this->checkoutService->startPaymentForOrder($order);
    }

    /**
     * @return View
     */
    public function index()
    {
        return $this->checkoutView();
    }

    /**
     * @return View
     */
    protected function checkoutView(): View
    {
        return view('shop.pages.checkout.index');
    }
}