/// <summary> /// Function transmit the Form 941 Return to Efile /// </summary> /// <param name="submissionId">SubmissionId passed to transmit the 941 return</param> /// <returns>TransmitFormW2Response</returns> public ActionResult _TransmitReturn(Guid submissionId) { var transmitForm941 = new TransmitForm(); var transmitForm941Response = new TransmitForm941Response(); var transmitForm941ResponseJSON = string.Empty; if (submissionId != null && submissionId != Guid.Empty) { // Getting the RecordIds for SubmissionId transmitForm941 = APISession.GetForm941RecordIdsBySubmissionId(submissionId); // Generate JSON for TransmitForm 941 var requestJson = JsonConvert.SerializeObject(transmitForm941, Formatting.Indented); if (transmitForm941 != null) { using (var client = new PublicAPIClient()) { //API URL to Transmit Form 941 Return string requestUri = "Form941/Transmit"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, transmitForm941).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result; if (createResponse != null) { transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCode.Success) { //Updating Filing Status (Transmitted) for a specific SubmissionId in Session APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); } } } } return(PartialView(transmitForm941Response)); }
/// <summary> /// Function transmit the Form 941 Return to Efile /// </summary> /// <param name="submissionId">SubmissionId passed to transmit the 941 return</param> /// <returns>TransmitFormW2Response</returns> public ActionResult _TransmitReturn(Guid submissionId) { var transmitForm941 = new TransmitForm(); var transmitForm941Response = new TransmitForm941Response(); var transmitForm941ResponseJSON = string.Empty; if (submissionId != null && submissionId != Guid.Empty) { // Getting the RecordIds for SubmissionId transmitForm941 = APISession.GetForm941RecordIdsBySubmissionId(submissionId); // Generate JSON for TransmitForm 941 var requestJson = JsonConvert.SerializeObject(transmitForm941, Formatting.Indented); if (transmitForm941 != null) { 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/Transmit"; 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, transmitForm941).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result; if (createResponse != null) { transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCode.Success) { //Updating Filing Status (Transmitted) for a specific SubmissionId in Session APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); } } } } } } } else { using (var client = new PublicAPIClient()) { //API URL to Transmit Form 941 Return string requestUri = "Form941/Transmit"; //POST APIGenerateAuthHeader.GenerateAuthHeader(client, requestUri, "POST"); //Get Response var _response = client.PostAsJsonAsync(requestUri, transmitForm941).Result; if (_response != null && _response.IsSuccessStatusCode) { //Read Response var createResponse = _response.Content.ReadAsAsync <TransmitForm941Response>().Result; if (createResponse != null) { transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); if (transmitForm941Response.SubmissionId != null && transmitForm941Response.SubmissionId != Guid.Empty && transmitForm941Response.StatusCode == (int)StatusCode.Success) { //Updating Filing Status (Transmitted) for a specific SubmissionId in Session APISession.UpdateForm941ReturnFilingStatus(transmitForm941Response.SubmissionId); } } } else { var createResponse = _response.Content.ReadAsAsync <Object>().Result; transmitForm941ResponseJSON = JsonConvert.SerializeObject(createResponse, Formatting.Indented); transmitForm941Response = new JavaScriptSerializer().Deserialize <TransmitForm941Response>(transmitForm941ResponseJSON); } } } } } return(PartialView(transmitForm941Response)); }