/// <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 }); }
/// <summary> /// Get the current balance of an account /// </summary> public async Task <ProjectionFunctionResponse> GetAccountBalance(HttpClient httpclient, string accountnumber) { if (null != httpclient) { string key = ""; key = _commands.FirstOrDefault(f => f.CommandName == "Get Balance")?.ApiKey; HttpRequestMessage message = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri(RetailBankApi.GetBase(), RetailBankApi.GetBalance(accountnumber, key)) }; var response = await httpclient.SendAsync(message); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <ProjectionFunctionResponse>(jsonString)); } else { return(new ProjectionFunctionResponse() { Message = $"Unable to get balance - {response.StatusCode}", InError = true }); } } return(new ProjectionFunctionResponse() { Message = $"Not connected to retail bank API", InError = true }); }