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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user