Exemplo n.º 1
0
        /// <summary>
        /// Search for a recipient using an email address. will return a Not Found exception if Recimpient doesn't exist
        /// </summary>
        /// <param name="recipientSearchRequest">
        /// request object that contains the parameters for using the api method of Interchecks Api Searc Recipients
        /// </param>
        /// <returns>
        /// /// response object Recipient Searched or a Not Found exception if Recimpient doesn't exist
        /// </returns>
        public async Task <RecipientDTO> SearchRecipient(RecipientSearchRequest recipientSearchRequest)
        {
            if (recipientSearchRequest == null)
            {
                throw new ArgumentNullException(nameof(recipientSearchRequest));
            }
            else
            {
                var         urlRequest  = $"{_interchecksApiSettings.Value.ApiRecipientsSearchCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId)}";
                HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(recipientSearchRequest).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));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SearchRecipient(RecipientSearchRequest recipientSearchRequest)
        {
            var recipientDTO = await _recipientsService.SearchRecipient(recipientSearchRequest);

            if (recipientDTO == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(recipientDTO));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// First search a recipient by email, if Recimpient doesn't exist then
        /// this method create a recipient with first name, last name, and email
        /// if Recimpient does exist will be returned
        /// </summary>
        /// <param name="recipientCreateRequest">
        /// request object that contains the parameters for using the api method of Interchecks Api Search and Create Recipients
        /// </param>
        /// <returns>
        /// response object Recipient Searched or Created
        /// </returns>
        public async Task <RecipientDTO> CreateIntegralRecipient(RecipientCreateRequest recipientCreateRequest)
        {
            if (recipientCreateRequest == null)
            {
                throw new ArgumentNullException(nameof(recipientCreateRequest));
            }
            else
            {
                RecipientSearchRequest recipientSearchRequest = _mapper.Map <RecipientSearchRequest>(recipientCreateRequest);
                RecipientDTO           recipientSearched      = await this.SearchRecipient(recipientSearchRequest);

                if (recipientSearched == null)
                {
                    RecipientDTO recipientCreated = await this.CreateRecipient(recipientCreateRequest);

                    return(recipientCreated);
                }
                else
                {
                    return(recipientSearched);
                }
            }
        }