/// <summary> /// Update recipient with TIN and address. using the recipient ID. /// </summary> /// <param name="recipient_id"> /// Recipient id /// </param> /// <param name="recipientUpdateW9Request"> /// request object that contains the parameters for using the api method of Interchecks Api Update Recipients /// </param> /// <returns> /// response object Recipient Updated /// </returns> public async Task <RecipientW9DTO> UpdateRecipientW9Data(string recipientId, RecipientUpdateW9Request recipientUpdateW9Request) { if (recipientUpdateW9Request == null) { throw new ArgumentNullException(nameof(recipientUpdateW9Request)); } else { var urlRequest = $"{_interchecksApiSettings.Value.ApiRecipientsUpdateW9DataCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId).Replace("{{RecipientId}}", recipientId)}"; HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(recipientUpdateW9Request).ToString(), Encoding.UTF8, "application/json"); var response = await _httpClient.PutAsync(urlRequest, httpContent); if (response.IsSuccessStatusCode) { RecipientW9DTO recipientDTO = JsonConvert.DeserializeObject <RecipientW9DTO>(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((RecipientW9DTO)IntercheckApiErrorHandler.Handle(apiError)); } } }
public async Task <IActionResult> UpdateRecipientW9Data(string recipient_id, RecipientUpdateW9Request recipientUpdateW9Request) { var recipientFromService = await _recipientsService.GetRecipientById(recipient_id); if (recipientFromService == null) { return(NotFound()); } else { var recipientUpdated = await _recipientsService.UpdateRecipientW9Data(recipient_id, recipientUpdateW9Request); if (recipientUpdated == null) { return(NotFound()); } else { return(Ok(recipientUpdated)); } } }