File: D:/HostingSpaces/SBogers10/zelfverkopen.komma.pro/app/KommaApp/Forms/StartSaleController.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\ContactRequest;
use App\Http\Requests\StartSaleRequest;
use App\KommaApp\CustomerProperties\CustomerPropertyService;
use App\KommaApp\Customers\CustomerService;
use App\KommaApp\Customers\Models\Customer;
use App\KommaApp\Orders\OrderService;
use App\KommaApp\Pages\PageController;
use Illuminate\Support\Facades\Redirect;
class StartSaleController extends Controller
{
/**
* @var FormService
*/
private $formService;
private $customerService;
private $customerPropertyService;
private $orderService;
/**
* ContactController constructor.
* @param FormService $formService
*/
public function __construct(FormService $formService, CustomerPropertyService $customerPropertyService, CustomerService $customerService, OrderService $orderService)
{
parent::__construct();
$this->formService = $formService;
$this->formService->setOrigin('startSale');
$this->customerService = $customerService;
$this->customerPropertyService = $customerPropertyService;
$this->orderService = $orderService;
}
/**
* Store the request and send it by e-mail
* Note: Validation is done in the request itself
*
* @param ContactRequest $request
*/
public function process(StartSaleRequest $request)
{
// Store customer in the database
$customer = $this->customerService->createCustomer($request);
// Store property in the database
$this->customerPropertyService->createCustomerProperty($request, $customer);
// Create new default order
$this->orderService->createDefaultOrder($customer);
// Send request to the site owner
$this->formService->sendRequest($request);
$this->formService->sendRequestClient($request, $request['sellerEmail']);
// Send to the success route
return Redirect::route('startSale.success');
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function paymentReceived()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('startSale'))->with('payment', true);
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function paymentError()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('startSale'))->with('payment', false);
}
/**
* Show page for old invoice routes
*
* @return mixed
*/
public function oldInvoice()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('startSale'))->with('oldInvoice', true);
}
/**
* Show page where we thank the user
*
* @return mixed
*/
public function success()
{
$pageController = new PageController();
return $pageController->show($this->pageService->getPageByCodeName('startSale'))->with('send', true);
}
}