Skip to content

Commit

Permalink
Refactor PaymentService to use handler by unique name
Browse files Browse the repository at this point in the history
  • Loading branch information
damms005 committed Oct 15, 2024
1 parent 4ec11bf commit dae5024
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Http/Controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function sendToPaymentGateway(Request $request)
}

/** @var PaymentHandlerInterface */
$handler = app()->make(PaymentHandlerInterface::class);
$basePaymentHandler = PaymentService::getHandlerFqcn($payment->payment_processor_name);

return $handler->proceedToPaymentGateway($payment, route('payment.finished.callback_url'), true);
return $basePaymentHandler->proceedToPaymentGateway($payment, route('payment.finished.callback_url'), true);
}

public function handlePaymentGatewayResponse(Request $request)
Expand Down
6 changes: 3 additions & 3 deletions src/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static function storePaymentAndShowUserBeforeProcessing(?int $user_id, fl
return $basePaymentHandler->storePaymentAndShowUserBeforeProcessing($user_id, $amount, $description, $currency, $transaction_reference, null, null, $view, $metadata);
}

private static function getHandlerFqcn(string $uniqueName): BasePaymentHandler
public static function getHandlerFqcn(string $uniqueName): BasePaymentHandler
{
$handler = BasePaymentHandler::getNamesOfPaymentHandlers()->filter(fn($name) => $name === $uniqueName);
$handler = BasePaymentHandler::getNamesOfPaymentHandlers()->filter(fn ($name) => $name === $uniqueName);

if ($handler->isEmpty()) {
throw new \Exception("No handler found with name '{$uniqueName}'");
Expand All @@ -32,7 +32,7 @@ private static function getHandlerFqcn(string $uniqueName): BasePaymentHandler
}

return $handler
->map(fn($name, $key) => new $key)
->map(fn ($name, $key) => new $key())
->sole();
}

Expand Down

0 comments on commit dae5024

Please sign in to comment.