コード例 #1
0
        public async Task CancelTaxTest()
        {
            // Header Level Elements
            // Required Header Level Elements
            var configSection = ConfigurationHelper.GetConfiguration();
            string accountNumber = configSection["accountNumber"];
            string licenseKey = configSection["licenseKey"];
            string serviceUrl = configSection["serviceUrl"];

            ITaxService taxSvc = new TaxService(accountNumber, licenseKey, serviceUrl);

            CancelTaxRequest cancelTaxRequest = new CancelTaxRequest
            {
                CompanyCode = "APITrialCompany",
                DocType = DocType.SalesInvoice,
                DocCode = "INV001",
                CancelCode = CancelCode.DocVoided
            };

            // Required Request Parameters

            CancelTaxResult cancelTaxResult = await taxSvc.CancelTax(cancelTaxRequest);

            // Print results
            Console.WriteLine("CancelTaxTest Result: {0}", cancelTaxResult.ResultCode);
            if (!cancelTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in cancelTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
コード例 #2
0
        // This calls CancelTax to void a transaction specified in taxreq
        public async Task<CancelTaxResult> CancelTax(CancelTaxRequest cancelTaxRequest)
        {
            // Convert the request to XML
            XmlSerializerNamespaces namesp = new XmlSerializerNamespaces();
            namesp.Add(string.Empty, string.Empty);
            XmlWriterSettings settings = new XmlWriterSettings {OmitXmlDeclaration = true};
            XmlSerializer x = new XmlSerializer(cancelTaxRequest.GetType());
            StringBuilder sb = new StringBuilder();
            x.Serialize(XmlWriter.Create(sb, settings), cancelTaxRequest, namesp);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(sb.ToString());

            // Call the service
            Uri address = new Uri(_svcUrl + "tax/cancel");
            var request = HttpHelper.CreateRequest(address, _accountNumber, _license);
            request.Method = "POST";
            request.ContentType = "text/xml";
            //request.ContentLength = sb.Length;
            Stream newStream = await request.GetRequestStreamAsync();
            newStream.Write(Encoding.ASCII.GetBytes(sb.ToString()), 0, sb.Length);
            CancelTaxResponse cancelResponse = new CancelTaxResponse();
            try
            {
                WebResponse response = await request.GetResponseAsync();
                XmlSerializer r = new XmlSerializer(cancelResponse.GetType());
                cancelResponse = (CancelTaxResponse) r.Deserialize(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                XmlSerializer r = new XmlSerializer(cancelResponse.GetType());
                cancelResponse = (CancelTaxResponse) r.Deserialize(((HttpWebResponse) ex.Response).GetResponseStream());

                // If the error is returned at the cancelResponse level, translate it to the cancelResult.
                if (cancelResponse.ResultCode.Equals(SeverityLevel.Error))
                {
                    cancelResponse.CancelTaxResult = new CancelTaxResult
                    {
                        ResultCode = cancelResponse.ResultCode,
                        Messages = cancelResponse.Messages
                    };
                }
            }

            return cancelResponse.CancelTaxResult;
        }