diff --git a/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs b/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs index 1d5e234fe..b08d1f16a 100644 --- a/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs +++ b/Sheaft.Application.Handlers/Commands/PaymentCommandsHandler.cs @@ -71,13 +71,6 @@ public async Task> Handle(UpdateBankAccountCommand request, Cancell request.Address.Country) : null; - bankAccount.SetAddress(address); - bankAccount.SetName(request.Name); - bankAccount.SetOwner(request.Owner); - bankAccount.SetIban(request.IBAN); - bankAccount.SetBic(request.BIC); - - await _context.SaveChangesAsync(token); if (!string.IsNullOrWhiteSpace(bankAccount.Identifier)) { @@ -88,6 +81,14 @@ public async Task> Handle(UpdateBankAccountCommand request, Cancell bankAccount.SetIdentifier(string.Empty); } + bankAccount.SetAddress(address); + bankAccount.SetName(request.Name); + bankAccount.SetOwner(request.Owner); + bankAccount.SetIban(request.IBAN); + bankAccount.SetBic(request.BIC); + + await _context.SaveChangesAsync(token); + var result = await _pspService.CreateBankIbanAsync(bankAccount, token); if (!result.Success) return Failed(result.Exception); diff --git a/Sheaft.Exceptions/Enums/MessageKind.cs b/Sheaft.Exceptions/Enums/MessageKind.cs index f1bf53c84..7cacafa51 100644 --- a/Sheaft.Exceptions/Enums/MessageKind.cs +++ b/Sheaft.Exceptions/Enums/MessageKind.cs @@ -223,8 +223,8 @@ public enum MessageKind Oidc_UpdateProfile_Error = 104004, PsP_CannotCreate_Wallet_User_Not_Exists = 105001, PsP_CannotCreate_Wallet_Wallet_Exists = 105002, - PsP_CannotCreate_Transfer_User_Not_Exists = 105003, - PsP_CannotCreate_Transfer_BankIBAN_Exists = 105004, + PsP_CannotCreate_Bank_User_Not_Exists = 105003, + PsP_CannotCreate_Bank_Already_Exists = 105004, PsP_CannotCreate_Card_User_Not_Exists = 105005, PsP_CannotCreate_Card_Card_Exists = 105006, PsP_CannotValidate_Card_Card_Not_Exists = 105007, @@ -262,5 +262,7 @@ public enum MessageKind PsP_CannotUpdateUbo_Ubo_Not_Exists = 105039, PsP_CannotCreate_User_User_Exists = 105040, PsP_CannotUpdate_User_User_Not_Exists = 105041, + PsP_CannotUpdate_Bank_User_Not_Exists = 105042, + PsP_CannotUpdate_Bank_Not_Exists = 105043, } } \ No newline at end of file diff --git a/Sheaft.Infrastructure.Services/PspService.cs b/Sheaft.Infrastructure.Services/PspService.cs index a0e393134..e6e99ee01 100644 --- a/Sheaft.Infrastructure.Services/PspService.cs +++ b/Sheaft.Infrastructure.Services/PspService.cs @@ -181,10 +181,10 @@ public async Task> CreateBankIbanAsync(BankAccount payment, Cance return await ExecuteAsync(async () => { if (string.IsNullOrWhiteSpace(payment.User.Identifier)) - return BadRequest(MessageKind.PsP_CannotCreate_Transfer_User_Not_Exists); + return BadRequest(MessageKind.PsP_CannotCreate_Bank_User_Not_Exists); - if (!string.IsNullOrWhiteSpace(payment.Identifier)) - return BadRequest(MessageKind.PsP_CannotCreate_Transfer_BankIBAN_Exists); + if (payment.Identifier.Length > 0) + return BadRequest(MessageKind.PsP_CannotCreate_Bank_Already_Exists); await EnsureAccessTokenIsValidAsync(token); @@ -215,10 +215,10 @@ public async Task> UpdateBankIbanAsync(BankAccount payment, bool is return await ExecuteAsync(async () => { if (string.IsNullOrWhiteSpace(payment.User.Identifier)) - return BadRequest(MessageKind.PsP_CannotCreate_Transfer_User_Not_Exists); + return BadRequest(MessageKind.PsP_CannotUpdate_Bank_User_Not_Exists); - if (!string.IsNullOrWhiteSpace(payment.Identifier)) - return BadRequest(MessageKind.PsP_CannotCreate_Transfer_BankIBAN_Exists); + if (string.IsNullOrWhiteSpace(payment.Identifier)) + return BadRequest(MessageKind.PsP_CannotUpdate_Bank_Not_Exists); await EnsureAccessTokenIsValidAsync(token);