Update a new payment method as default if current default is deleted

This commit is contained in:
David Bomba 2025-01-27 15:02:54 +11:00
parent c3d717972b
commit aea0236068
1 changed files with 12 additions and 0 deletions

View File

@ -417,6 +417,18 @@ class ClientGatewayTokenController extends BaseController
{
$this->client_gateway_token_repo->delete($client_gateway_token);
if($client_gateway_token->is_default) {
$cgt = ClientGatewayToken::where('client_id', $client_gateway_token->client_id)
->where('company_gateway_id', $client_gateway_token->company_gateway_id)
->first();
if($cgt){
$cgt->is_default = true;
$cgt->save();
}
}
return $this->itemResponse($client_gateway_token->fresh());
}