public async Task <TransactionCreditDTO> CreateCreditTransaction(TransactionCreditRequest transactionCreditRequest) { if (transactionCreditRequest == null) { throw new ArgumentNullException(nameof(transactionCreditRequest)); } else { var urlRequest = _interchecksApiSettings.BaseUrl + _interchecksApiSettings .ApiTransactionsCreateCreditCall .Replace("{{PayerId}}", _interchecksApiSettings.PayerId) .Replace("{{RecipientId}}", transactionCreditRequest.RecipientId); using (var _httpClient = HttpClientHelper.GetClient(_interchecksApiSettings.AccountId, _interchecksApiSettings.SecretKey)) { TransactionCreditIntercheckRequest requestObject = Mapper.Map <TransactionCreditRequest, TransactionCreditIntercheckRequest>(transactionCreditRequest); 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; TransactionCreditDTO transactionDTO = JsonConvert.DeserializeObject <TransactionCreditDTO>(responseValue); return(transactionDTO); } } } }
public async Task <HttpResponseMessage> CreateCreditTransactionAsync(TransactionCreditRequest transactionCreditRequest) { try { var transactionDTO = await _transactionsService.CreateCreditTransaction(transactionCreditRequest); 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)); } }