<?php
declare(strict_types=1);
namespace App\Module\ShortSimpleCheckout\Controller;
use App\Module\ShortSimpleCheckout\Controller\Facade\ShippingPaymentControllerFacadeInterface;
use App\Module\ShortSimpleCheckout\Customer\CustomerInterface;
use App\Module\ShortSimpleCheckout\EventListener\Cart\CartFilledInterface;
use Commercetools\Core\Model\Cart\Cart;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment as TwigEnvironment;
/**
* Simple display of the shipping payment page.
*
* @author Michel Chowanski <chowanski@bestit-online.de>
* @package App\Module\ShortSimpleCheckout\Controller
*/
class ShippingPaymentController implements CartFilledInterface
{
private ShippingPaymentControllerFacadeInterface $facade;
private TwigEnvironment $twig;
private string $template;
/**
* @param ShippingPaymentControllerFacadeInterface $facade
* @param TwigEnvironment $twig
* @param string $template
*/
public function __construct(
ShippingPaymentControllerFacadeInterface $facade,
TwigEnvironment $twig,
string $template
) {
$this->facade = $facade;
$this->twig = $twig;
$this->template = $template;
}
/**
* Display the shipping payment page for the given cart.
*
* @param Cart $cart
* @param CustomerInterface $customer
*
* @return Response
*/
public function indexAction(Cart $cart, CustomerInterface $customer): Response
{
$content = $this->twig->render(
$this->template,
['best_it_short_simple_checkout' => $this->facade->getDataForIndexAction($cart, $customer)]
);
return new Response($content);
}
/**
* Sets the payment
*
* @param Cart $cart
* @param CustomerInterface $customer
* @param Request $request
*
* @return JsonResponse
*/
public function selectPaymentTypeAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
{
$paymentType = $request->request->get('paymentType');
return $this->facade->selectPaymentType(
$paymentType,
$cart,
$customer
);
}
/**
* Sets the billing address.
*
* @param Cart $cart
* @param CustomerInterface $customer
* @param Request $request
*
* @return JsonResponse
*/
public function selectBillingAddressAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
{
return $this->facade->selectBillingAddress(
$request->request->get('billingAddressId'),
$cart,
$customer
);
}
/**
* Sets the shipping address.
*
* @param Cart $cart
* @param CustomerInterface $customer
* @param Request $request
*
* @return JsonResponse
*/
public function selectShippingAddressAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
{
return $this->facade->selectShippingAddress(
$request->request->get('shippingAddressId'),
$cart,
$customer
);
}
/**
* Sets the shipping type
*
* @param Cart $cart
* @param CustomerInterface $customer
* @param Request $request
*
* @return JsonResponse
*/
public function selectShippingTypeAction(Cart $cart, CustomerInterface $customer, Request $request): JsonResponse
{
//Differne Shipper HQ types
$shippingType = $request->request->get('shippingType');
return $this->facade->selectShippingType(
$shippingType,
$cart,
$customer
);
}
}