File: D:/HostingSpaces/Neopoints/momsecurity.be/app/Komma/Shop/Payment/PSPResponseController.php
<?php
namespace App\Komma\Shop\Payment;
use App\Komma\Shop\Orders\Kms\OrderMailServiceInterface;
use App\Komma\Shop\Orders\Models\Order;
/**
* 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
{
/** @var PaymentServiceInterface $paymentService */
private $paymentService;
/** @var OrderMailServiceInterface */
private $orderMailService;
/**
* PSPResponseController constructor.
*/
public function __construct()
{
$this->paymentService = \App::make(PaymentServiceInterface::class);
$this->orderMailService = \App::make(OrderMailServiceInterface::class);
}
/**
* 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
$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
]);
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
], 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
], 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
], 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
], 200);
return $viewResponse;
}
}