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 <AccountCardDTO> CreateAccount(AccountCardCreateRequest accountCardCreateRequest)
        {
            if (accountCardCreateRequest == null)
            {
                throw new ArgumentNullException(nameof(accountCardCreateRequest));
            }
            else
            {
                var         urlRequest = $"{_interchecksApiSettings.Value.ApiAccountsCreateCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId).Replace("{{RecipientId}}", accountCardCreateRequest.RecipientID)}";
                var         accountCardCreateInterchecksRequest = _mapper.Map <AccountCardCreateInterchecksRequest>(accountCardCreateRequest);
                HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(accountCardCreateInterchecksRequest).ToString(), Encoding.UTF8, "application/json");
                var         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);
                    _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}");
                    return((AccountCardDTO)IntercheckApiErrorHandler.Handle(apiError));
                }
                else
                {
                    AccountCardDTO accountCardDTO = JsonConvert.DeserializeObject <AccountCardDTO>(response.Content.ReadAsStringAsync().Result);
                    return(accountCardDTO);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Create recipient with first name, last name, and email.
        /// </summary>
        /// <param name="recipientCreateRequest">
        /// request object that contains the parameters for using the api method of Interchecks Api Create Recipients
        /// </param>
        /// <returns>
        /// response object Recipient Created
        /// </returns>
        public async Task <RecipientDTO> CreateRecipient(RecipientCreateRequest recipientCreateRequest)
        {
            if (recipientCreateRequest == null)
            {
                throw new ArgumentNullException(nameof(recipientCreateRequest));
            }
            else
            {
                var         urlRequest  = $"{_interchecksApiSettings.Value.ApiRecipientsCreateCall}/{_interchecksApiSettings.Value.PayerId}";
                HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(recipientCreateRequest).ToString(), Encoding.UTF8, "application/json");
                var         response    = await _httpClient.PostAsync(urlRequest, httpContent);

                if (response.IsSuccessStatusCode)
                {
                    RecipientDTO recipientDTO = JsonConvert.DeserializeObject <RecipientDTO>(response.Content.ReadAsStringAsync().Result);
                    return(recipientDTO);
                }
                else
                {
                    string respError             = response.Content.ReadAsStringAsync().Result;
                    InterchecksApiError apiError = JsonConvert.DeserializeObject <InterchecksApiError>(respError);
                    _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}");
                    return((RecipientDTO)IntercheckApiErrorHandler.Handle(apiError));
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Get recipient using the recipient ID.
        /// </summary>
        /// <param name="recipient_id">
        /// Recipient id
        /// </param>
        /// <returns>
        /// response object Recipient
        /// </returns>
        public async Task <RecipientDTO> GetRecipientById(string recipientId)
        {
            if (String.IsNullOrEmpty(recipientId))
            {
                return(null);
            }
            else
            {
                var urlRequest = $"{_interchecksApiSettings.Value.ApiRecipientsGetCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId).Replace("{{RecipientId}}", recipientId)}";
                var response   = await _httpClient.GetAsync(urlRequest);

                if (response.IsSuccessStatusCode)
                {
                    RecipientDTO recipientDTO = JsonConvert.DeserializeObject <RecipientDTO>(response.Content.ReadAsStringAsync().Result);
                    return(recipientDTO);
                }
                else
                {
                    string respError             = response.Content.ReadAsStringAsync().Result;
                    InterchecksApiError apiError = JsonConvert.DeserializeObject <InterchecksApiError>(respError);
                    _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}");
                    return((RecipientDTO)IntercheckApiErrorHandler.Handle(apiError));
                }
            }
        }
 public static object Handle(InterchecksApiError interchecksApiError)
 {
     if (interchecksApiError == null)
     {
         throw new ArgumentNullException(nameof(interchecksApiError));
     }
     else
     {
         if ("401".Equals(interchecksApiError.ErrorCode.ToUpper()))
         {
             throw new UnauthorizedAccessException($"Interchecks Api Authorization Error, Error Code:{interchecksApiError.ErrorCode}|{interchecksApiError.ErrorMessage}");
         }
         else if ("R05".Equals(interchecksApiError.ErrorCode.ToUpper()))
         {
             return(null);
         }
         else
         {
             throw new HttpRequestException($"Interchecks Api Error, Error Code:{interchecksApiError.ErrorCode}|{interchecksApiError.ErrorMessage}");
         }
     }
 }
예제 #6
0
 public IntercheckApiException(InterchecksApiError error)
 {
     Error = error;
 }