/// <summary> /// Function inputs Form W-2 details, POST all those details to the API and returns the response. /// Successful response contains SubmissionId, StatusCode and RecordSuccessStatus details (Sequence, RecordId, RecordStatus etc) /// Error response contains StatusCode and RecordErrorStatus details (RecordId, Sequence and list of Error information such as Code, Name, Message and Type) /// </summary> /// <param name="formw2">Form W-2 details passed through formw2 parameter</param> /// <returns>W2CreateReturnResponse</returns> public ActionResult APIResponseStatus(FormW2 formw2) { //Hardcoded values for Sequence and TaxYear var responseJson = string.Empty; formw2.TaxYear = 2017; formw2.Sequence = "Record1"; W2CreateReturnResponse w2response = new W2CreateReturnResponse(); W2CreateReturnRequest w2ReturnList = new W2CreateReturnRequest(); w2ReturnList.W2Forms = new List <FormW2>(); w2ReturnList.W2Forms.Add(formw2); // Generate JSON for Form W-2 var requestJson = JsonConvert.SerializeObject(w2ReturnList, Formatting.Indented); using (var client = new PublicAPIClient()) { //API URL to Create Form W-2 Return string requestUri = "FormW2/Create"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, w2ReturnList).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <W2CreateReturnResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to W2CreateReturnResponse object w2response = new JavaScriptSerializer().Deserialize <W2CreateReturnResponse>(responseJson); if (w2response.SubmissionId != null && w2response.SubmissionId != Guid.Empty) { //Adding W2CreateReturnResponse Response to Session APISession.AddAPIResponse(w2response); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to W2CreateReturnResponse object w2response = new JavaScriptSerializer().Deserialize <W2CreateReturnResponse>(responseJson); } } return(PartialView(w2response)); }
/// <summary> /// Function transmit the Form W-2 Return to Efile /// </summary> /// <param name="submissionId">SubmissionId passed to transmit the W-2 return</param> /// <returns>TransmitFormW2Response</returns> public ActionResult _TransmitReturn(Guid submissionId) { TransmitForm transmitFormW2 = new TransmitForm(); TransmitFormW2Response transmitFormW2Response = new TransmitFormW2Response(); var transmitFormW2ResponseJSON = string.Empty; if (submissionId != null && submissionId != Guid.Empty) { // Getting the RecordIds for SubmissionId transmitFormW2 = APISession.GetRecordIdsBySubmissionId(submissionId); // Generate JSON for TransmitFormW2 var requestJson = JsonConvert.SerializeObject(transmitFormW2, Formatting.Indented); if (transmitFormW2 != null) { using (var client = new PublicAPIClient()) { //API URL to Transmit Form W-2 Return string requestUri = "FormW2/Transmit"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, transmitFormW2).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <TransmitFormW2Response>().Result; if (createResponse != null) { transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitFormW2Response = new JavaScriptSerializer().Deserialize <TransmitFormW2Response>(transmitFormW2ResponseJSON); if (transmitFormW2Response.SubmissionId != null && transmitFormW2Response.SubmissionId != Guid.Empty && transmitFormW2Response.StatusCode == (int)StatusCode.Success) { //Updating Filing Status (Transmitted) for a specific SubmissionId in Session APISession.UpdateFilingStatus(transmitFormW2Response.SubmissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitFormW2Response = new JavaScriptSerializer().Deserialize <TransmitFormW2Response>(transmitFormW2ResponseJSON); } } } } return(PartialView(transmitFormW2Response)); }
/// <summary> /// Function returns the Efile status of Form 941 /// </summary> /// <param name="submissionId">SubmissionId is passed to get the efile status</param> /// <returns>Form941StatusResponse</returns> public ActionResult _GetEfileStatusResponse(Guid submissionId) { var efileStatusResponse = new Form941SCHRStatusResponse(); if (submissionId != null && submissionId != Guid.Empty) { var efileRequest = new EfileStatusGetRequest { SubmissionId = submissionId }; var recordIds = APISession.GetForm941RecordIdsBySubmissionId(submissionId); if (recordIds != null && recordIds.RecordIds != null && recordIds.RecordIds.Count > 0) { efileRequest.RecordIds = recordIds.RecordIds; } var transmitFormW2ResponseJSON = string.Empty; // Request JSON var requestJson = JsonConvert.SerializeObject(efileRequest, Formatting.Indented); if (submissionId != null && submissionId != Guid.Empty) { using (var client = new PublicAPIClient()) { //POST string requestUri = "Form941SCHR/Status"; //Get Response APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Read Response var _response = client.PostAsJsonAsync(requestUri, efileRequest).Result; if (_response != null && _response.IsSuccessStatusCode) { var createResponse = _response.Content.ReadAsAsync <Form941SCHRStatusResponse>().Result; if (createResponse != null) { transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); efileStatusResponse = new JavaScriptSerializer().Deserialize <Form941SCHRStatusResponse>(transmitFormW2ResponseJSON); } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; transmitFormW2ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); efileStatusResponse = new JavaScriptSerializer().Deserialize <Form941SCHRStatusResponse>(transmitFormW2ResponseJSON); } } } } return(PartialView(efileStatusResponse)); }
/// <summary> /// Function delete the Form 941SCHR Return to Efile /// </summary> /// <param name="submissionId">SubmissionId passed to delete the 941SCHR return</param> /// <returns>DeleteReturnResponse</returns> public ActionResult Delete(Guid submissionId) { var deleteReturnRequest = new DeleteReturnRequest(); var deleteReturnResponse = new DeleteReturnResponse(); var deleteReturnResponseJSON = string.Empty; if (submissionId != null && submissionId != Guid.Empty) { deleteReturnRequest.SubmissionId = submissionId; // Getting the RecordIds for SubmissionId var recordIdsFromSession = APISession.GetForm941SCHRRecordIdsBySubmissionId(submissionId); deleteReturnRequest.RecordIds = recordIdsFromSession != null ? recordIdsFromSession.RecordIds : null; if (deleteReturnRequest.RecordIds != null && deleteReturnRequest.RecordIds.Count > 0) { using (var client = new PublicAPIClient()) { //API URL to Delete Form 941SCHR Return string requestUri = "Form941SCHR/Delete"; //Delete APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, deleteReturnRequest).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <DeleteReturnResponse>().Result; if (createResponse != null) { deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success) { //Remove Submission and RecordId from session APISession.DeleteForm941SCHRAPIResponse(submissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); } } } } return(PartialView(deleteReturnResponse)); }
public ActionResult GetVINStatus(IRSVehicleCheckRequest vinCheckRequest) { var responseJson = string.Empty; IRSVehicleCheckResponse vehicleCheckResponse = new IRSVehicleCheckResponse(); using (var client = new PublicAPIClient()) { //API URL to Get VIN Status string requestUri = "hvutvalidation/irsvehiclecheck"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var response = client.PostAsJsonAsync(requestUri, vinCheckRequest).Result; if (response != null && response.IsSuccessStatusCode) { //Read Response var createResponse = response.Content.ReadAsAsync <IRSVehicleCheckResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to IRSVehicleCheckResponse object vehicleCheckResponse = new JavaScriptSerializer().Deserialize <IRSVehicleCheckResponse>(responseJson); } } else { var createResponse = response.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to IRSVehicleCheckResponse object vehicleCheckResponse = new JavaScriptSerializer().Deserialize <IRSVehicleCheckResponse>(responseJson); } } return(Json(responseJson, JsonRequestBehavior.AllowGet)); }
public ActionResult APIResponseStatus(Form941SchRRecords form941SchRRecords) { //Hardcoded values for Sequence var responseJson = string.Empty; form941SchRRecords.Sequence = "Record1"; form941SchRRecords.RecordId = null; form941SchRRecords.ReturnHeader.ReturnType = null; form941SchRRecords.ReturnHeader.Business.IsEIN = true; form941SchRRecords.ReturnHeader.Business.IsForeign = false; if (form941SchRRecords?.ReturnHeader?.ThirdPartyDesignee != null && (!string.IsNullOrEmpty(form941SchRRecords.ReturnHeader.ThirdPartyDesignee.Name) || !string.IsNullOrEmpty(form941SchRRecords.ReturnHeader.ThirdPartyDesignee.Phone) || !string.IsNullOrEmpty(form941SchRRecords.ReturnHeader.ThirdPartyDesignee.PIN))) { form941SchRRecords.ReturnHeader.IsThirdPartyDesignee = true; } if (form941SchRRecords?.ReturnHeader?.BusinessStatusDetails != null) { if (form941SchRRecords.ReturnHeader.BusinessStatusDetails.IsBusinessClosed == false) { form941SchRRecords.ReturnHeader.BusinessStatusDetails.BusinessClosedDetails = new BusinessClosedDetails(); } if (form941SchRRecords.ReturnHeader.BusinessStatusDetails.IsBusinessTransferred == false) { form941SchRRecords.ReturnHeader.BusinessStatusDetails.BusinessTransferredDetails = new BusinessTransferredDetails(); } } var form941SchRResponse = new Form941SchRCreateReturnResponse(); var form941SchRReturnList = new Form941SchRCreateReturnRequest { Form941SchRRecords = new List <Form941SchRRecords>() }; form941SchRReturnList.Form941SchRRecords.Add(form941SchRRecords); // Generate JSON for Form 941SCHR var requestJson = JsonConvert.SerializeObject(form941SchRReturnList, Formatting.Indented); using (var client = new PublicAPIClient()) { //API URL to Create Form 941SCHR Return string requestUri = "Form941SCHR/Create"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, HttpMethod.Post.ToString()); //Get Response var response = client.PostAsJsonAsync(requestUri, form941SchRReturnList).Result; if (response != null && response.IsSuccessStatusCode) { //Read Response var createResponse = response.Content.ReadAsAsync <Form941SchRCreateReturnResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to Form941CreateReturnResponse object form941SchRResponse = new JavaScriptSerializer().Deserialize <Form941SchRCreateReturnResponse>(responseJson); if (form941SchRResponse.SubmissionId != null && form941SchRResponse.SubmissionId != Guid.Empty) { //Adding Form941CreateReturnResponse Response to Session APISession.AddForm941SCHRAPIResponse(form941SchRResponse); } } } else { var createResponse = response.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to Form941CreateReturnResponse object form941SchRResponse = new JavaScriptSerializer().Deserialize <Form941SchRCreateReturnResponse>(responseJson); } } return(PartialView(form941SchRResponse)); }
/// <summary> /// Function delete the Form 941 Return to Efile /// </summary> /// <param name="submissionId">SubmissionId passed to delete the 941 return</param> /// <returns>DeleteReturnResponse</returns> public ActionResult Delete(Guid submissionId) { var deleteReturnRequest = new DeleteReturnRequest(); var deleteReturnResponse = new DeleteReturnResponse(); var deleteReturnResponseJSON = string.Empty; if (submissionId != null && submissionId != Guid.Empty) { deleteReturnRequest.SubmissionId = submissionId; // Getting the RecordIds for SubmissionId var recordIdsFromSession = APISession.GetForm941RecordIdsBySubmissionId(submissionId); deleteReturnRequest.RecordIds = recordIdsFromSession != null ? recordIdsFromSession.RecordIds : null; if (deleteReturnRequest.RecordIds != null && deleteReturnRequest.RecordIds.Count > 0) { string authType = Utility.GetAppSettings("AuthenticationType"); if (!string.IsNullOrWhiteSpace(authType) && authType.ToUpper() == "JWT") { //Get URLs from App.Config string oAuthApiUrl = Utility.GetAppSettings("OAuthApiUrl"); string apiUrl = Utility.GetAppSettings("PublicAPIUrlWithJWT"); //Call OAuth API using (var oAuthClient = new HttpClient()) { string oAuthRequestUri = Utility.GetAppSettings("OAuthApiMethodRoute"); oAuthClient.BaseAddress = new Uri(oAuthApiUrl); //Generate JWS and get access token (JWT) OAuthGenerator.GenerateJWSAndGetAccessToken(oAuthClient); //Read OAuth API response var response = oAuthClient.GetAsync(oAuthRequestUri).Result; if (response != null && response.IsSuccessStatusCode) { var oauthApiResponse = response.Content.ReadAsAsync <AccessTokenResponse>().Result; if (oauthApiResponse != null && oauthApiResponse.StatusCode == 200) { //Get Access token from OAuth API response string accessToken = oauthApiResponse.AccessToken; //Access token is valid for one hour. After that call OAuth API again & get new Access token. if (!string.IsNullOrWhiteSpace(accessToken)) { //Call TaxBandits API using the Access token //Access token is valid for one hour. After that call OAuth API again & get new Access token. using (var apiClient = new HttpClient()) { //API URL to Transmit Form 941 Return string requestUri = "Form941/Delete"; apiClient.BaseAddress = new Uri(apiUrl); //Construct HTTP headers //If Access token got expired, call OAuth API again & get new Access token. OAuthGenerator.ConstructHeadersWithAccessToken(apiClient, accessToken); //Get Response var _response = apiClient.PostAsJsonAsync(requestUri, deleteReturnRequest).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <DeleteReturnResponse>().Result; if (createResponse != null) { deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success) { //Remove Submission and RecordId from session APISession.DeleteForm941APIResponse(submissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); } } } } } } } else { using (var client = new PublicAPIClient()) { //API URL to Transmit Form 941 Return string requestUri = "Form941/Delete"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, deleteReturnRequest).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <DeleteReturnResponse>().Result; if (createResponse != null) { deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); if (deleteReturnResponse != null && deleteReturnResponse.StatusCode == (int)StatusCode.Success) { //Remove Submission and RecordId from session APISession.DeleteForm941APIResponse(submissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; deleteReturnResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); deleteReturnResponse = new JavaScriptSerializer().Deserialize <DeleteReturnResponse>(deleteReturnResponseJSON); } } } } } return(PartialView(deleteReturnResponse)); }
public ActionResult APIResponseStatus(Form941Data form941) { //Hardcoded values for Sequence var responseJson = string.Empty; form941.Sequence = "Record1"; form941.RecordId = null; form941.ReturnHeader.ReturnType = null; form941.ReturnHeader.Business.IsEIN = true; form941.ReturnHeader.Business.IsForeign = false; if (form941?.ReturnHeader?.ThirdPartyDesignee != null && (!string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.Name) || !string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.Phone) || !string.IsNullOrEmpty(form941.ReturnHeader.ThirdPartyDesignee.PIN))) { form941.ReturnHeader.IsThirdPartyDesignee = true; } if (form941?.ReturnHeader?.BusinessStatusDetails != null) { if (form941.ReturnHeader.BusinessStatusDetails.IsBusinessClosed == false) { form941.ReturnHeader.BusinessStatusDetails.BusinessClosedDetails = new BusinessClosedDetails(); } if (form941.ReturnHeader.BusinessStatusDetails.IsBusinessTransferred == false) { form941.ReturnHeader.BusinessStatusDetails.BusinessTransferredDetails = new BusinessTransferredDetails(); } } var form941Response = new Form941CreateReturnResponse(); var form941ReturnList = new Form941CreateReturnRequest { Form941Records = new List <Form941Data>() }; form941ReturnList.Form941Records.Add(form941); // Generate JSON for Form 941 var requestJson = JsonConvert.SerializeObject(form941ReturnList, Formatting.Indented); string authType = Utility.GetAppSettings("AuthenticationType"); if (!string.IsNullOrWhiteSpace(authType) && authType.ToUpper() == "JWT") { //Get URLs from App.Config string oAuthApiUrl = Utility.GetAppSettings("OAuthApiUrl"); string apiUrl = Utility.GetAppSettings("PublicAPIUrlWithJWT"); //Call OAuth API using (var oAuthClient = new HttpClient()) { string oAuthRequestUri = Utility.GetAppSettings("OAuthApiMethodRoute"); oAuthClient.BaseAddress = new Uri(oAuthApiUrl); //Generate JWS and get access token (JWT) OAuthGenerator.GenerateJWSAndGetAccessToken(oAuthClient); //Read OAuth API response var response = oAuthClient.GetAsync(oAuthRequestUri).Result; if (response != null && response.IsSuccessStatusCode) { var oauthApiResponse = response.Content.ReadAsAsync <AccessTokenResponse>().Result; if (oauthApiResponse != null && oauthApiResponse.StatusCode == 200) { //Get Access token from OAuth API response string accessToken = oauthApiResponse.AccessToken; //Access token is valid for one hour. After that call OAuth API again & get new Access token. if (!string.IsNullOrWhiteSpace(accessToken)) { //Call TaxBandits API using the Access token //Access token is valid for one hour. After that call OAuth API again & get new Access token. using (var apiClient = new HttpClient()) { //API URL to Create Form 941 Return string requestUri = "Form941/Create"; apiClient.BaseAddress = new Uri(apiUrl); //Construct HTTP headers //If Access token got expired, call OAuth API again & get new Access token. OAuthGenerator.ConstructHeadersWithAccessToken(apiClient, accessToken); //Get Response var apiResponse = apiClient.PostAsJsonAsync(requestUri, form941ReturnList).Result; if (apiResponse != null && response.IsSuccessStatusCode) { //Read Response var createResponse = apiResponse.Content.ReadAsAsync <Form941CreateReturnResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to Form941CreateReturnResponse object form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson); if (form941Response.SubmissionId != null && form941Response.SubmissionId != Guid.Empty) { //Adding Form941CreateReturnResponse Response to Session APISession.AddForm941APIResponse(form941Response); } } } else { var createResponse = apiResponse.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to Form941CreateReturnResponse object form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson); } } } } } } } else { using (var client = new PublicAPIClient()) { //API URL to Create Form 941 Return string requestUri = "Form941/Create"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, HttpMethod.Post.ToString()); //Get Response var response = client.PostAsJsonAsync(requestUri, form941ReturnList).Result; if (response != null && response.IsSuccessStatusCode) { //Read Response var createResponse = response.Content.ReadAsAsync <Form941CreateReturnResponse>().Result; if (createResponse != null) { responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Success Response) to Form941CreateReturnResponse object form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson); if (form941Response.SubmissionId != null && form941Response.SubmissionId != Guid.Empty) { //Adding Form941CreateReturnResponse Response to Session APISession.AddForm941APIResponse(form941Response); } } } else { var createResponse = response.Content.ReadAsAsync <Object>().Result; responseJson = JsonConvert.SerializeObject(createResponse, Formatting.Indented); //Deserializing JSON (Error Response) to Form941CreateReturnResponse object form941Response = new JavaScriptSerializer().Deserialize <Form941CreateReturnResponse>(responseJson); } } } return(PartialView(form941Response)); }