File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Payment/PaymentService.php
<?php
namespace App\Payment;
use App\Payment\PSPAdapters\AbstractPSPAdapter;
/**
* Class PaymentService
*
* The payment service returns Adapters which help handling
* payments for different PSPs. It can also help with manual payments
*
* @package App\Payment
*/
class PaymentService
{
/**
* Returns the concrete adapter.
* e.g. An adapter that extends this class.
*
* The adapter knows how to both work with KMS and
* a script from a PSP to process payments
*
* @return AbstractPSPAdapter
*/
public function getAdapter(): AbstractPSPAdapter
{
$psp = config('payment.payment_service_provider');
$adapterConfigKey = 'payment.payment_service_providers.'.$psp.'.adapter';
$adapter = config($adapterConfigKey);
if(!$adapter || !is_a($adapter, AbstractPSPAdapter::class, true))
throw new \RuntimeException('The following payment configuration key did not exist or did not return a childclass of "'.AbstractPSPAdapter::class.'": '.$adapterConfigKey);
return new $adapter;
}
}