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/SBogers10/zelfverkopen.komma.pro/app/KommaApp/Forms/BuyHouseController.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 26/09/17
 * Time: 15:24
 */

namespace App\KommaApp\Forms;


use App\Http\Controllers\Controller;
use App\Http\Requests\BuyHouseRequest;
use App\KommaApp\Customers\CustomerService;
use App\KommaApp\Orders\OrderService;
use App\KommaApp\Pages\PageController;
use App\Mail\SendAdminOrderMail;
use App\Mail\SendClientOrderMail;
use Illuminate\Support\Facades\Redirect;

class BuyHouseController extends Controller
{
    /**
     * @var FormService
     */
    private $formService;

    private $customerService;
    private $orderService;

    /**
     * ContactController constructor.
     * @param  FormService  $formService
     * @param  CustomerService  $customerService
     * @param  OrderService  $orderService
     */
    public function __construct(FormService $formService, CustomerService $customerService, OrderService $orderService)
    {
        parent::__construct();

        $this->formService = $formService;
        $this->formService->setOrigin('buyHouse');

        $this->customerService = $customerService;
        $this->orderService = $orderService;
    }

    /**
     * Store the request and send it by e-mail
     * Note: Validation is done in the request itself
     *
     * @param  BuyHouseRequest  $request
     * @return mixed
     */
    public function process(BuyHouseRequest $request)
    {

        // Store customer in the database
        $customer = $this->customerService->createCustomer($request, true);

        $order = $this->orderService->createOrderForProduct($customer, $request->get('buyHouseProduct'));

        \Mail::send( new SendAdminOrderMail($order) );
        \Mail::send( new SendClientOrderMail($order) );

        // Send to the success route
        return Redirect::route('buyHouse.success');
    }

    /**
     * Show page where we thank the user
     *
     * @return mixed
     */
    public function paymentReceived()
    {
        $pageController = new PageController();
        return $pageController->show($this->pageService->getPageByCodeName('buyHouseForm'))->with('payment', true);
    }

    /**
     * Show page where we thank the user
     *
     * @return mixed
     */
    public function paymentError()
    {
        $pageController = new PageController();
        return $pageController->show($this->pageService->getPageByCodeName('buyHouseForm'))->with('payment', false);
    }

    /**
     * Show page where we thank the user
     *
     * @return mixed
     */
    public function success()
    {
        $pageController = new PageController();
        return $pageController->show($this->pageService->getPageByCodeName('buyHouseForm'))->with('send', true);
    }
}