File: D:/HostingSpaces/stafa/werkenbijstafa.nl/app/Komma/Shop/Payment/PSPResponseController.php
<?php
namespace App\Komma\Shop\Payment;
use App\Komma\Base\Controller;
use App\Komma\Shop\Orders\Kms\OrderMailServiceInterface;
use App\Komma\Shop\Orders\Models\Order;
use Illuminate\Http\Request;
/**
* Class PSPResponseController
*
* Responds to requests from a payment service provider.
* Wheter they are api calls or redirect calls that should display views.
*
* @package App\Komma\Shop\Payment
*/
class PSPResponseController extends Controller
{
/** @var PaymentServiceInterface $paymentService */
private $paymentService;
/** @var OrderMailServiceInterface */
private $orderMailService;
/**
* PSPResponseController constructor.
*/
public function __construct()
{
$this->paymentService = app(PaymentServiceInterface::class);
$this->orderMailService = app(OrderMailServiceInterface::class);
parent::__construct();
}
/**
* Called by the Payment service provider to tell us that something happened with a transaction.
* Used for updating a transaction
*/
public function processPaymentProviderResponse()
{
$order = request()->route()->parameter('order'); //May or may not be present
if($order && !is_a($order, Order::class)) throw new \RuntimeException('The order from the route was not an order but a '.gettype($order).'.');
$adapter = $this->paymentService->getAdapter();
return $adapter->processPSPResponse($order);
}
/**
* Shows a general thanks page to the user after the user was redirected to the psp for payment.
*
* Important: This method MUST NOT cause the side effect of updating a transaction. It must only return a view.
*/
public function showGeneralTransactionResult()
{
/** @var Order $order */
$order = request()->route()->parameter('order'); //May or may not be present
$transaction = null;
if($order) {
$transaction = $order->transactions()->latest()->first();
}
$viewResponse = response()->view('shop.pages.checkout.transaction.general', [
'order' => $order,
'transaction' => $transaction,
'links' => $this->links,
]);
return $viewResponse;
}
/**
* Shows a accepted page to the user after the user was redirected to the psp for payment.
* This page indicates that the user paid for the order and what the shop is going to next.
*
* Important: This method MUST NOT cause the side effect of updating a transaction. It must only return a view.
*/
public function showAcceptedTransactionResult()
{
$order = request()->route()->parameter('order'); //May or may not be present
if($order) $order->load('transactions');
$viewResponse = response()->view('shop.pages.checkout.transaction.accepted', [
'order' => $order,
'links' => $this->links,
], 200);
return $viewResponse;
}
/**
* Shows a declined page to the user after the user was redirected to the psp for payment.
* This page indicates that failed to do the payment. Maybe because he entered his pin code wrongly too many
* times.
*
* Important: This method MUST NOT cause the side effect of updating a transaction. It must only return a view.
*/
public function showDeclinedTransactionResult()
{
$order = request()->route()->parameter('order'); //May or may not be present
$viewResponse = response()->view('shop.pages.checkout.transaction.declined', [
'order' => $order,
'links' => $this->links,
], 200);
return $viewResponse;
}
/**
* Shows an exception page to the user after the user was redirected to the psp for payment.
* This page indicates that an exception occurred at the PSP side.
*
* Important: This method MUST NOT cause the side effect of updating a transaction. It must only return a view.
*/
public function showExceptionTransactionResult()
{
$order = request()->route()->parameter('order'); //May or may not be present
$viewResponse = response()->view('shop.pages.checkout.transaction.exception', [
'order' => $order,
'links' => $this->links,
], 400);
return $viewResponse;
}
/**
* Shows an canceled page to the user after the user was redirected to the psp for payment.
* This page indicates that the user canceled the payment.
*
* Important: This method MUST NOT cause the side effect of updating a transaction. It must only return a view.
*/
public function showCanceledTransactionResult()
{
$order = request()->route()->parameter('order'); //May or may not be present
$viewResponse = response()->view('shop.pages.checkout.transaction.cancel', [
'order' => $order,
'links' => $this->links,
], 200);
return $viewResponse;
}
/**
* Shows the user a fake psp page that can redirect the user back to this controller
*
* @param Request $request
* @param Order $order
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showFakePSPPage(Request $request, Order $order)
{
return view('shop.pages.checkout.fakepsp', ['order' => $order, 'links' => $this->links,]);
}
}