public async Task <TransactionDebitDTO> CreateDebitTransaction(TransactionDebitRequest transactionDebitRequest)
        {
            if (transactionDebitRequest == null)
            {
                throw new ArgumentNullException(nameof(transactionDebitRequest));
            }
            else
            {
                var urlRequest = _interchecksApiSettings.BaseUrl
                                 + _interchecksApiSettings
                                 .ApiTransactionsCreateDebitCall
                                 .Replace("{{PayerId}}", _interchecksApiSettings.PayerId)
                                 .Replace("{{RecipientId}}", transactionDebitRequest.RecipientId);
                using (var _httpClient = HttpClientHelper.GetClient(_interchecksApiSettings.AccountId, _interchecksApiSettings.SecretKey))
                {
                    TransactionDebitIntercheckRequest requestObject = Mapper.Map <TransactionDebitRequest, TransactionDebitIntercheckRequest>(transactionDebitRequest);
                    HttpContent         httpContent = new StringContent(JsonConvert.SerializeObject(requestObject).ToString(), Encoding.UTF8, "application/json");
                    HttpResponseMessage 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);
                        throw new IntercheckApiException(apiError);
                    }
                    else
                    {
                        string responseValue = response.Content.ReadAsStringAsync().Result;
                        TransactionDebitDTO transactionDTO = JsonConvert.DeserializeObject <TransactionDebitDTO>(responseValue);
                        return(transactionDTO);
                    }
                }
            }
        }
예제 #2
0
        public async Task <HttpResponseMessage> CreateDebitTransactionAsync(TransactionDebitRequest transactionDebitRequest)
        {
            try
            {
                var transactionDTO = await _transactionsService.CreateDebitTransaction(transactionDebitRequest);

                return(Request.CreateResponse(HttpStatusCode.OK, transactionDTO));
            }
            catch (IntercheckApiException apiException)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, apiException.Error));
            }
            catch (Exception exception)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, exception.Message));
            }
        }