Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public VATMaint()
        {
            _oAuthApplication = PXSelectReadonly <HMRCOAuthApplication,
                                                  Where <HMRCOAuthApplication.applicationName, Equal <Required <HMRCOAuthApplication.applicationName> > > >
                                .SelectSingleBound(this, null, _applicationName);

            if (_oAuthApplication != null)
            {
                if (!String.IsNullOrEmpty(_oAuthApplication.UsrServerUrl))
                {
                    urlSite = _oAuthApplication.UsrServerUrl;
                }

                _oAuthToken = PXSelectReadonly <OAuthToken, Where <OAuthToken.applicationID, Equal <Required <OAuthToken.applicationID> > > >
                              .SelectSingleBound(this, null, _oAuthApplication.ApplicationID);
            }
            VATProvider = new VATApi(urlSite, _oAuthApplication, _oAuthToken, vrn, UpdateOAuthToken);
            SetVRN(Period_Header.Current);

            signInHMRC.SetEnabled(_oAuthToken == null);
            sendVATreturn.SetEnabled(false);
            checkVATReturn.SetEnabled(false);
            PXUIFieldAttribute.SetEnabled <VATPeriodFilter.periodKey>(Period_Header.Cache, null, _oAuthToken != null);
            PXUIFieldAttribute.SetVisibility <TaxReportLine.lineNbr>(Period_Details.Cache, null, PXUIVisibility.Invisible);
            PXUIFieldAttribute.SetVisibility <TaxReportLine.lineNbr>(Period_Details.Cache, null, PXUIVisibility.Invisible);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public VATMaint(OAuthSettings hMRCOAuthApplication, Dictionary <string, string> FraudHeaders = null)
        {
            if (FraudHeaders == null)
            {
                FraudHeaders = new Dictionary <string, string>();
            }

            OAuthToken _oAuthToken;

            TokenKey = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value.Replace("-", "");
            TokenKey = TokenKey.Substring(TokenKey.Length - 24);

            if (System.IO.File.Exists(@"Token.dat"))
            {
                TokenFile = @"Token.dat";
            }
            else
            {
                string fldr = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "HMRC", "VAT");
                System.IO.Directory.CreateDirectory(fldr);
#if DEBUG
                TokenFile = System.IO.Path.Combine(fldr, @"Token_Debug.dat");
#else
                TokenFile = System.IO.Path.Combine(fldr, @"Token.dat");
#endif
            }


            vrn = hMRCOAuthApplication.VRN;
            _oAuthApplication = hMRCOAuthApplication;

            if (System.IO.File.Exists(TokenFile))
            {
                try
                {
                    System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(OAuthToken));
                    using (System.IO.StreamReader file = new System.IO.StreamReader(TokenFile))
                    {
                        _oAuthToken = (OAuthToken)reader.Deserialize(file);
                        file.Close();
                        _oAuthToken.RefreshToken = Decrypt(_oAuthToken.RefreshToken, TokenKey);
                        _oAuthToken.AccessToken  = Decrypt(_oAuthToken.AccessToken, TokenKey);
                        _oAuthToken.Bearer       = Decrypt(_oAuthToken.Bearer, TokenKey);
                    }
                }
                catch (Exception)
                {
                    _oAuthToken = new OAuthToken();
                }
            }
            else
            {
                _oAuthToken = new OAuthToken();
            }

            VATProvider = new VATApi(_oAuthApplication, _oAuthToken, vrn, FraudHeaders, SaveOAuthToken);
        }