public async Task <AccountCardDTO> CreateAccount(AccountCardCreateRequest accountCardCreateRequest) { if (accountCardCreateRequest == null) { throw new ArgumentNullException(nameof(accountCardCreateRequest)); } else { var urlRequest = $"{_interchecksApiSettings.Value.ApiAccountsCreateCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId).Replace("{{RecipientId}}", accountCardCreateRequest.RecipientID)}"; var accountCardCreateInterchecksRequest = _mapper.Map <AccountCardCreateInterchecksRequest>(accountCardCreateRequest); HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(accountCardCreateInterchecksRequest).ToString(), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(urlRequest, httpContent); var responseResult = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode || responseResult.Contains("error")) { string respError = response.Content.ReadAsStringAsync().Result; InterchecksApiError apiError = JsonConvert.DeserializeObject <InterchecksApiError>(respError); _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}"); return((AccountCardDTO)IntercheckApiErrorHandler.Handle(apiError)); } else { AccountCardDTO accountCardDTO = JsonConvert.DeserializeObject <AccountCardDTO>(response.Content.ReadAsStringAsync().Result); return(accountCardDTO); } } }
public async Task <IActionResult> CreateAccount(AccountCardCreateRequest accountCardCreateRequest) { var accountDTO = await _accountsService.CreateAccount(accountCardCreateRequest); return(Ok(accountDTO)); }