fix(payment): validate and filter unavailable methods

Filter user-visible payment methods to only include supported
providers and fail fast when a payment record or plugin cannot be
resolved.

This prevents invalid payment options from being returned by the
API and avoids constructing an undefined fallback payment class.
This commit is contained in:
yinjianm
2026-03-19 20:29:26 +08:00
parent dbffb0a7bd
commit 421844895e
2 changed files with 40 additions and 21 deletions
@@ -173,6 +173,8 @@ class OrderController extends Controller
public function getPaymentMethod()
{
$availableMethods = array_flip(PaymentService::getAllPaymentMethodNames());
$methods = Payment::select([
'id',
'name',
@@ -183,7 +185,11 @@ class OrderController extends Controller
])
->where('enable', 1)
->orderBy('sort', 'ASC')
->get();
->get()
->filter(function ($payment) use ($availableMethods) {
return isset($availableMethods[$payment->payment]);
})
->values();
return $this->success($methods);
}