Пример #1
0
        static void Main()
        {
            var container = new ProblemsContainer();

            Console.WriteLine($"Problem 1 solution is {container.SolveProblem01()}");
            Console.WriteLine($"Problem 2 solution is {container.SolveProblem02()}");
            Console.WriteLine($"Problem 3 solution is {container.SolveProblem03()}");
            Console.WriteLine($"Problem 4 solution is {container.SolveProblem04()}");
            Console.ReadKey();
        }
 public CouldNotReversePaymentException(string id, ProblemsContainer problems) : base(problems.ToString())
 {
     Problems = problems;
     Id       = id;
 }
Пример #3
0
 public CouldNotFindTransactionException(Exception inner) : base("Could not find transaction for the given id", inner)
 {
     Problems = new ProblemsContainer("Other", "Could not find transaction for the given id");
 }
Пример #4
0
 public CouldNotFindTransactionException(string id) : base("Could not find transaction for the given id")
 {
     Problems = new ProblemsContainer(nameof(id), "Could not find transaction for the given id");
     Id       = id;
 }
Пример #5
0
 public CouldNotFindTransactionException(string id, ProblemsContainer problems) : base(problems.ToString())
 {
     Problems = problems;
     Id       = id;
 }
Пример #6
0
 public CouldNotFindPaymentException(string id) : base("Could not find payment for the given id")
 {
     Problems = new ProblemsContainer(nameof(id), "Could not find payment for the given id");
     Id       = id;
 }
        private async Task <T> HttpRequest <T>(string httpMethod, string url, Func <ProblemsContainer, Exception> onError, object payload = null)
        {
            var msg = new HttpRequestMessage(new HttpMethod(httpMethod), url);

            if (payload != null)
            {
                var content = JsonConvert.SerializeObject(payload, Settings);
                msg.Content = new StringContent(content, Encoding.UTF8, "application/json");
            }
            msg.Headers.Add("Accept", "application/json");


            HttpResponseMessage response;

            try
            {
                response = await _client.SendAsync(msg);
            }
            catch (HttpRequestException e)
            {
                throw new BadRequestException(e);
            }
            catch (TaskCanceledException te)
            {
                throw new ApiTimeOutException(te);
            }

            if (response.IsSuccessStatusCode)
            {
                var res = await response.Content.ReadAsStringAsync();

                _logger.LogPayExResponse(res);
                return(JsonConvert.DeserializeObject <T>(res, Settings));
            }

            var responseMessage = await response.Content.ReadAsStringAsync();

            _logger.LogPayExResponse(responseMessage);
            ProblemsContainer problems;

            if (!string.IsNullOrEmpty(responseMessage) && IsValidJson(responseMessage))
            {
                problems = JsonConvert.DeserializeObject <ProblemsContainer>(responseMessage);
            }
            else if (response.StatusCode == HttpStatusCode.NotFound)
            {
                problems = new ProblemsContainer("id", "Not found");
            }
            else
            {
                IEnumerable <string> customHeader = null;
                _client.DefaultRequestHeaders.TryGetValues("X-Payex-ClientName", out customHeader);
                var aggr = customHeader != null?customHeader.Aggregate((x, y) => x + "," + y) : "no-name";

                problems = new ProblemsContainer("Other", $"Response when calling PayEx `{aggr}` was: '{response.StatusCode}'");
            }

            var ex = onError(problems);

            throw ex;
        }
 public CouldNotFindPaidPaymentException(Exception inner) : base(Description, inner)
 {
     Problems = new ProblemsContainer("Other", Description);
 }
 public CouldNotFindPaidPaymentException(string id) : base(Description)
 {
     Problems = new ProblemsContainer(nameof(id), Description);
     Id       = id;
 }
 public CouldNotPlacePaymentException(PaymentRequest payment, ProblemsContainer problems) : base(problems.ToString())
 {
     Problems = problems;
     Payment  = payment;
 }