예제 #1
0
        public static AvaTaxResult GetTax(string URL, DocumentType DocType,
                                            string Account, string License,
                                            string CompanyCode, string UserName, string Password,
                                            string OrderIdentifier, BaseAddress OriginationAddress,
                                            BaseAddress DestinationAddress, List<Line> items,
                                            string CustomerCode)
        {

            BVSoftware.Avalara.AvaTaxResult result = new AvaTaxResult();

            avt.TaxService.GetTaxRequest gtr = new avt.TaxService.GetTaxRequest();
            gtr.OriginAddress = ConvertBaseAddress(OriginationAddress);
            gtr.DestinationAddress = ConvertBaseAddress(DestinationAddress);
            
            
            //' Origin and Destination addresses
            //OriginationAddress.AddressCode = "O"
            //DestinationAddress.AddressCode = "D"
            //gtr.Addresses = New BaseAddress(2) {}
            //gtr.Addresses(0) = OriginationAddress
            //gtr.Addresses(1) = DestinationAddress
            //Document Level Origin and Destination Addresses - see AddressCode field.
            //gtr.OriginCode = gtr.Addresses(0).AddressCode
            //gtr.DestinationCode = gtr.Addresses(1).AddressCode

            gtr.CompanyCode = CompanyCode;
            gtr.CustomerCode = CustomerCode;
            gtr.DetailLevel = avt.TaxService.DetailLevel.Document;
            gtr.DocCode = OrderIdentifier;
            gtr.DocType = ConvertDocType(DocType);
            gtr.DocDate = DateTime.Now;
            
            foreach (Line l in items)
            {
                avt.TaxService.Line nl = ConvertLine(l);
                gtr.Lines.Add(nl);
            }            
            
            avt.TaxService.TaxSvc svc = GetTaxServiceProxy(URL, Account, License, UserName, Password);
            avt.TaxService.GetTaxResult gtres = svc.GetTax(gtr);


            if (gtres.ResultCode != avt.SeverityLevel.Success)
            {
                result.Success = false;
                result.Messages.Add("GetTax Failed");
                ApplyMessagesToResult(result, gtres.Messages);
            }
            else
            {
                result.Success = true;
            }

            result.DocId = gtres.DocId;
            result.TotalAmount = gtres.TotalAmount;
            result.TotalTax = gtres.TotalTax;

            return result;                      
        }
예제 #2
0
        public static BaseAddress ConvertAddressToAvalara(MerchantTribe.Web.Geography.IAddress address)
        {
            var result = new BaseAddress();
            result.Line1 = address.Street;
            result.Line2 = address.Street2;            
            result.City = address.City;
            result.Region = address.RegionData.Name;
            result.PostalCode = address.PostalCode;
            //result.Country = address.CountryName

            return result;
        }
예제 #3
0
 public static void GetAvalaraTaxes(Orders.Order order, 
                                 string identifier, 
                                 BaseAddress origin, 
                                 BaseAddress destination,List<Line> lines, 
                                 string customerCode, MerchantTribeApplication app)
 {
     var result = new AvaTaxResult();            
         result = BVAvaTax.GetTax(app.CurrentStore.Settings.Avalara.ServiceUrl, 
             DocumentType.SalesOrder, 
             app.CurrentStore.Settings.Avalara.Account, 
             app.CurrentStore.Settings.Avalara.LicenseKey, 
             app.CurrentStore.Settings.Avalara.CompanyCode,
             app.CurrentStore.Settings.Avalara.Username, 
             app.CurrentStore.Settings.Avalara.Password,
             identifier, origin, destination, lines, customerCode);
                 
     if (result != null)
     {
         if (result.Success == true)
         {                    
             order.TotalTax = result.TotalTax;
         }
         else
         {
             if (app.CurrentStore.Settings.Avalara.DebugMode)
             {
             string note = "Avalara - Get Tax Request Failed:";
             foreach(var m in result.Messages)
                  {
                      note += "\n" + m;
                  }                
             order.Notes.Add(new Orders.OrderNote() {
                  IsPublic = false,
                  Note = note});                         
             app.OrderServices.Orders.Update(order);
                                         
                EventLog.LogEvent("Avalara -  ApplyTaxes", note, Web.Logging.EventLogSeverity.Error);
             }
         }
     }
 }
예제 #4
0
        public static void CommitAvalaraTaxes(Orders.Order order, string identifier, BaseAddress origin, BaseAddress destination, List<Line> lines, MerchantTribeApplication app)
        {                            
                var docId = "";                
                var customerCode = Utilities.AvalaraUtilities.GetCustomerCode(order);

                //The only difference here is that we are using a SalesInvoice instead of SalesOrder
            
                var result = BVAvaTax.GetTax(app.CurrentStore.Settings.Avalara.ServiceUrl, 
                    DocumentType.SalesInvoice, 
                    app.CurrentStore.Settings.Avalara.Account, 
                    app.CurrentStore.Settings.Avalara.LicenseKey, 
                    app.CurrentStore.Settings.Avalara.CompanyCode,
                    app.CurrentStore.Settings.Avalara.Username, 
                    app.CurrentStore.Settings.Avalara.Password,
                    identifier, origin, destination, lines, customerCode);
                                      
                if (result.Success)
                {                 
                    docId = result.DocId;
                } 
                else
                {
                    if (app.CurrentStore.Settings.Avalara.DebugMode)
                    {
                        string note = "Avalara - Commit Tax Failed:";
                        foreach(var m in result.Messages)
                         {
                             note += "\n" + m;
                         }                
                        order.Notes.Add(new Orders.OrderNote() {
                         IsPublic = false,
                         Note = note});                         
                        app.OrderServices.Orders.Update(order);
                        
                        EventLog.LogEvent("Avalara", note, Web.Logging.EventLogSeverity.Error);
                    }
                    return;
                }

            
                var totalTax = result.TotalTax;

                result = BVAvaTax.PostTax(app.CurrentStore.Settings.Avalara.ServiceUrl,
                    app.CurrentStore.Settings.Avalara.Account,
                    app.CurrentStore.Settings.Avalara.LicenseKey,
                    app.CurrentStore.Settings.Avalara.CompanyCode,
                    app.CurrentStore.Settings.Avalara.Username,
                    app.CurrentStore.Settings.Avalara.Password,
                    identifier, docId, DocumentType.SalesInvoice, result.TotalAmount, result.TotalTax);

                    if (result != null)
                    {
                        if (result.Success)
                        {                                                
                            order.CustomProperties.SetProperty("bvsoftware", BVAvaTax.AvalaraTaxPropertyName, result.DocId);                            
                            app.OrderServices.Orders.Update(order);
                        }
                        else
                        {
                            if (app.CurrentStore.Settings.Avalara.DebugMode)
                            {
                                string note = "Avalara - Commit Tax Failed (POST):";
                                foreach (var m in result.Messages)
                                {
                                    note += "\n" + m;
                                }
                                order.Notes.Add(new Orders.OrderNote()
                                {
                                    IsPublic = false,
                                    Note = note
                                });
                                app.OrderServices.Orders.Update(order);

                                EventLog.LogEvent("Avalara", note, Web.Logging.EventLogSeverity.Error);
                            }
                            return;
                        }
                    }


                    result = BVAvaTax.CommitTax(app.CurrentStore.Settings.Avalara.ServiceUrl,
                        app.CurrentStore.Settings.Avalara.Account,
                        app.CurrentStore.Settings.Avalara.LicenseKey,
                        app.CurrentStore.Settings.Avalara.CompanyCode,
                        app.CurrentStore.Settings.Avalara.Username,
                        app.CurrentStore.Settings.Avalara.Password,
                        identifier, docId, DocumentType.SalesInvoice);

                    if (result.Success)
                    {
                        if (app.CurrentStore.Settings.Avalara.DebugMode)
                        {
                            string note = "Avalara - Committed " + totalTax.ToString("C") + ":";
                            foreach (var m in result.Messages)
                            {
                                note += "\n" + m;
                            }
                            order.Notes.Add(new Orders.OrderNote()
                            {
                                IsPublic = false,
                                Note = note
                            });
                            app.OrderServices.Orders.Update(order);

                            EventLog.LogEvent("Avalara", note, Web.Logging.EventLogSeverity.Error);
                        }                        
                    } 
                    else
                    {
                        if (app.CurrentStore.Settings.Avalara.DebugMode)
                        {
                            string note = "Avalara - Commit Tax Failed (Commit Call):";
                            foreach (var m in result.Messages)
                            {
                                note += "\n" + m;
                            }
                            order.Notes.Add(new Orders.OrderNote()
                            {
                                IsPublic = false,
                                Note = note
                            });
                            app.OrderServices.Orders.Update(order);

                            EventLog.LogEvent("Avalara", note, Web.Logging.EventLogSeverity.Error);
                        }                        
                    }
        }
예제 #5
0
        internal static avt.AddressService.Address ConvertBaseAddress(BaseAddress local)
        {
            avt.AddressService.Address result = new global::Avalara.AvaTax.Adapter.AddressService.Address();

            result.City = local.City;
            result.Country = local.Country;
            result.Line1 = local.Line1;
            result.Line2 = local.Line2;
            result.Line3 = local.Line3;
            result.PostalCode = local.PostalCode;
            result.Region = local.Region;            

            return result;
        }