File: D:/HostingSpaces/ZelfVerkopen/zelfverkopen.nl/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
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function process(BuyHouseRequest $request)
{
$this->formService->checkManualExclusions($request);
$this->formService->runRecaptchaValidation();
// 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);
}
}