Пример #1
0
 public Task <ProjectionFunctionResponse> WithdrawMoney(HttpClient httpClient, string accountnumber, MoneyWithdrawnData payload)
 {
     return(Task <ProjectionFunctionResponse> .FromResult(new ProjectionFunctionResponse()
     {
         Message = "This is a mock withdrawal",
         InError = false
     }));
 }
        public async Task <ProjectionFunctionResponse> WithdrawMoney(HttpClient httpClient, string accountnumber, MoneyWithdrawnData payload)
        {
            if (null != httpClient)
            {
                string key = "";

                key = _commands.FirstOrDefault(f => f.CommandName == "Withdraw Money")?.ApiKey;

                Uri postTarget = new Uri(RetailBankApi.GetBase(), RetailBankApi.WithdrawMoney(accountnumber, key));

                string jsonContent = JsonConvert.SerializeObject(payload);
                // Turn the payload into a JSON
                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 <ProjectionFunctionResponse>(jsonString));
                }
                else
                {
                    return(new ProjectionFunctionResponse()
                    {
                        Message = $"Unable to withdraw money - {response.StatusCode}", InError = true
                    });
                }
            }

            return(new ProjectionFunctionResponse()
            {
                Message = $"Not connected to retail bank API", InError = true
            });
        }