Esempio n. 1
0
        /// <summary>
        /// Retrieve VAT Liabilities
        /// </summary>
        /// <returns></returns>
        public liabilityResponse Liabilities(liabilityRequest request, string testScenario = null)
        {
            RefreshAccessToken();
            string             url         = urlSite + _urlLiabilities.Replace("{vrn}", vrn) + "?from=" + request.from?.ToString("yyyy-MM-dd") + "&to=" + request.to?.ToString("yyyy-MM-dd");
            HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, url);

            httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(_acceptHeader));
            httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

            foreach (var item in fraudHeaders)
            {
                httpRequest.Headers.Add(item.Key, item.Value);
            }

            if (!String.IsNullOrEmpty(testScenario))
            {
                httpRequest.Headers.Add("Gov-Test-Scenario", testScenario);
            }

            liabilityResponse liabilityResponse = null;

            using (var httpClient = new HttpClient())
            {
                HttpResponseMessage response = httpClient.SendAsync(httpRequest).Result;
                checkApiResponse(response, VATApiType.RetrieveVATliabilities);

                var content = response.Content.ReadAsStringAsync();
                liabilityResponse = JsonConvert.DeserializeObject <liabilityResponse>(content.Result);
            }

            return(liabilityResponse);
        }
Esempio n. 2
0
        public static void GetVATLiabilitiesProc(VATMaint vatMaint, DateTime from, DateTime to, string testScenario = null)
        {
            liabilityRequest req = new liabilityRequest()
            {
                from = from, to = to
            };
            liabilityResponse liabilityResponse = null;

            try
            {
                liabilityResponse = vatMaint.VATProvider.Liabilities(req, testScenario);
            }
            catch (Exceptions.VATAPIInvalidToken eToken)
            {
                Trace.WriteError(eToken);
                //         vatMaint.signInHMRC.SetEnabled(true);
                throw new Exception(Messages.PleaseAuthorize);
            }
            catch (Exceptions.VATAPIException eApi)
            {
                Trace.WriteError(eApi);
                if (eApi.Data.Contains("json"))
                {
                    Trace.WriteError(eApi.Data["json"].ToString());
                }
                if (eApi.Code != error.MATCHING_RESOURCE_NOT_FOUND)
                {
                    throw eApi;
                }
            }
            catch (Exception e)
            {
                Trace.WriteError(e);
                throw e;
            }
            vatMaint.Liabilities.Clear();
            if (liabilityResponse != null)
            {
                foreach (var o in liabilityResponse.liabilities)
                {
                    vatMaint.Liabilities.Add(new Liability()
                    {
                        due               = DateTime.ParseExact(o.due, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
                        originalAmount    = o.originalAmount,
                        outstandingAmount = o.outstandingAmount,
                        type              = o.type,
                        from              = DateTime.ParseExact(o.taxPeriod.from, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
                        to = DateTime.ParseExact(o.taxPeriod.to, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
                    });
                }
            }
            return;
        }