30 lines
1.0 KiB
PHP
30 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Payment\Services;
|
|
|
|
use Modules\Core\Payment\Contracts\PaymentDriver;
|
|
|
|
/**
|
|
* Resolves a payment type key (e.g. 'stripe', 'cash-on-delivery') to its
|
|
* registered PaymentDriver — extracted out of CheckoutService so both it
|
|
* and anything else needing the same lookup (e.g. a listener reacting to
|
|
* OrderPlaced, which has no reason to depend on Checkout's own service)
|
|
* share one implementation instead of duplicating this config read.
|
|
*/
|
|
class PaymentDriverResolver
|
|
{
|
|
/**
|
|
* Null if $type has no 'payment_driver' registered in
|
|
* config('lunar.payments.types.<type>') at all — deliberately
|
|
* non-throwing so a caller like CheckoutService::getPaymentMethods()
|
|
* can filter unresolvable types silently rather than treating "not
|
|
* registered" as an error condition when just checking availability.
|
|
*/
|
|
public function resolve(string $type): ?PaymentDriver
|
|
{
|
|
$driverClass = config("lunar.payments.types.{$type}.payment_driver");
|
|
|
|
return $driverClass ? app($driverClass) : null;
|
|
}
|
|
}
|