Fix 500 when saving payment gateway credentials.
Deploy Ladill POS / deploy (push) Successful in 1m32s

Implement the missing SettingsController::persistGateway method so merchant Paystack/Flutterwave/Hubtel keys can be saved, and cover create + keep-blank-secrets paths with tests.
This commit is contained in:
isaacclad
2026-07-15 13:11:02 +00:00
parent 3c0172f098
commit 69ec45eea6
2 changed files with 116 additions and 0 deletions
@@ -8,6 +8,7 @@ use App\Models\PosLocation;
use App\Models\PosMember;
use App\Models\PaymentGatewaySetting;
use App\Models\PosTable;
use App\Models\User;
use App\Services\Import\CrmProductImportService;
use App\Services\Import\MerchantCatalogImportService;
use App\Services\Payments\MerchantGatewayService;
@@ -118,6 +119,47 @@ class SettingsController extends Controller
return back()->with('success', 'Settings saved.');
}
/**
* Upsert merchant gateway credentials for the acting account.
* Blank secret fields keep the previously stored encrypted values.
*/
protected function persistGateway(Request $request, User $user): void
{
$ownerRef = (string) $user->public_id;
$existing = PaymentGatewaySetting::query()->where('owner_ref', $ownerRef)->first();
$provider = trim((string) $request->input('gateway_provider', ''));
$publicKey = trim((string) $request->input('gateway_public_key', ''));
$secretKey = trim((string) $request->input('gateway_secret_key', ''));
$webhookSecret = trim((string) $request->input('gateway_webhook_secret', ''));
// No provider chosen and no prior config — nothing to persist.
if ($provider === '' && $existing === null) {
return;
}
$attributes = [
'provider' => $provider !== '' ? $provider : $existing->provider,
'is_active' => $request->boolean('gateway_is_active'),
];
// Leave blank on the form means "keep the saved credential".
if ($publicKey !== '') {
$attributes['public_key'] = $publicKey;
}
if ($secretKey !== '') {
$attributes['secret_key'] = $secretKey;
}
if ($webhookSecret !== '') {
$attributes['webhook_secret'] = $webhookSecret;
}
PaymentGatewaySetting::query()->updateOrCreate(
['owner_ref' => $ownerRef],
$attributes,
);
}
public function storeTable(Request $request): RedirectResponse
{
$data = $request->validate([