/// <summary> /// Open a new account /// </summary> public async Task <FunctionResponse> OpenAccount(HttpClient httpClient, string accountnumber, AccountOpeningData payload) { if (null != httpClient) { string key = ""; key = _commands.FirstOrDefault(f => f.CommandName == "Open Account")?.ApiKey; Uri postTarget = new Uri(RetailBankApi.GetBase(), RetailBankApi.OpenAccount(accountnumber, key)); string jsonContent = JsonConvert.SerializeObject(payload); // Turn the payload into a JSON // var content = new StringContent()); ; var content = new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes(jsonContent)); content.Headers.ContentType = new MediaTypeHeaderValue(RetailBankApi.PAYLOAD_TYPE); var response = await httpClient.PostAsync(postTarget, content); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <FunctionResponse>(jsonString)); } else { return(new FunctionResponse() { Message = $"Unable to open an account - {response.StatusCode}", InError = true }); } } return(new FunctionResponse() { Message = $"Not connected to retail bank API", InError = true }); }
public Task <FunctionResponse> OpenAccount(HttpClient httpClient, string accountnumber, AccountOpeningData payload) { return(Task <FunctionResponse> .FromResult(new FunctionResponse() { Message = "This is a mock account opening", InError = false })); }