protected void Page_Load(object sender, System.EventArgs e) { Customer thisCustomer = ((AspDotNetStorefrontPrincipal)Context.User).ThisCustomer; AspDotNetStorefrontCore.net.taxcloud.api.TaxCloud _tc = new AspDotNetStorefrontCore.net.taxcloud.api.TaxCloud(); string str = CommonLogic.FormCanBeDangerousContent("certificateID"); AspDotNetStorefrontCore.net.taxcloud.api.ExemptionCertificate _certificate = new ExemptionCertificate(); _certificate.Detail = new ExemptionCertificateDetail(); _certificate.Detail.SinglePurchaseOrderNumber = CommonLogic.FormCanBeDangerousContent("SinglePurchaseOrderNumber"); if (string.IsNullOrEmpty(_certificate.Detail.SinglePurchaseOrderNumber)) { _certificate.Detail.SinglePurchase = false; } else { _certificate.Detail.SinglePurchase = true; } ExemptState[] exemptState = new ExemptState[1]; exemptState[0] = new ExemptState(); exemptState[0].StateAbbr = (AspDotNetStorefrontCore.net.taxcloud.api.State)(Enum.Parse(typeof(AspDotNetStorefrontCore.net.taxcloud.api.State), CommonLogic.Form("ExemptState"), true)); //exemptState[0].ReasonForExemption = CommonLogic.FormCanBeDangerousContent("ReasonForExemption"); //exemptState[0].IdentificationNumber = CommonLogic.FormCanBeDangerousContent("IdentificationNumber"); _certificate.Detail.ExemptStates = exemptState; _certificate.Detail.PurchaserTaxID = new TaxID(); _certificate.Detail.PurchaserTaxID.TaxType = (TaxIDType)(Enum.Parse(typeof(TaxIDType), CommonLogic.Form("TaxType"), true)); _certificate.Detail.PurchaserTaxID.IDNumber = CommonLogic.FormCanBeDangerousContent("IDNumber");;; _certificate.Detail.PurchaserFirstName = CommonLogic.FormCanBeDangerousContent("PurchaserFirstName");;; _certificate.Detail.PurchaserLastName = CommonLogic.FormCanBeDangerousContent("PurchaserLastName");;; _certificate.Detail.PurchaserAddress1 = CommonLogic.FormCanBeDangerousContent("PurchaserAddress1");;; _certificate.Detail.PurchaserCity = CommonLogic.FormCanBeDangerousContent("PurchaserCity");;; _certificate.Detail.PurchaserState = (AspDotNetStorefrontCore.net.taxcloud.api.State)(Enum.Parse(typeof(AspDotNetStorefrontCore.net.taxcloud.api.State), CommonLogic.FormCanBeDangerousContent("PurchaserState"), true)); _certificate.Detail.PurchaserZip = CommonLogic.FormCanBeDangerousContent("PurchaserZip"); _certificate.Detail.PurchaserBusinessType = (BusinessType)(Enum.Parse(typeof(BusinessType), CommonLogic.FormCanBeDangerousContent("PurchaserBusinessType"), true)); _certificate.Detail.PurchaserExemptionReason = (ExemptionReason)(Enum.Parse(typeof(ExemptionReason), CommonLogic.FormCanBeDangerousContent("PurchaserExemptionReason"), true)); _certificate.Detail.PurchaserExemptionReasonValue = CommonLogic.FormCanBeDangerousContent("PurchaserExemptionReasonValue");;; AddCertificateRsp addRs = _tc.AddExemptCertificate(AppLogic.AppConfig("taxcloud.apiloginid"), AppLogic.AppConfig("taxcloud.apikey"), thisCustomer.CustomerID.ToString(), _certificate); if (addRs.ResponseType != MessageType.Error) { DB.ExecuteSQL("update shoppingcart set certificateID=" + DB.SQuote(addRs.CertificateID) + " where CustomerID=" + thisCustomer.CustomerID); } }
private decimal lookupTaxRate(string custID, net.taxcloud.api.CartItem[] refItems, net.taxcloud.api.Address refOrigin, net.taxcloud.api.Address refDest) { double taxRate = 0.0f; ExemptionCertificate exemptCert = null; string _cartID = GetCartID(custID, refDest.Zip5, refItems.First().Index); using (SqlConnection conn = DB.dbConn()) { conn.Open(); using (IDataReader rs = DB.GetRS("select Top 1 certificateID from ShoppingCart where CustomerID=" + custID, conn)) { if (rs.Read() && DB.RSField(rs, "certificateID") != "") { exemptCert = new ExemptionCertificate(); exemptCert.CertificateID = DB.RSField(rs, "certificateID"); } } } LookupRsp response = tc.Lookup(ApiLoginID, ApiKey, custID, _cartID, refItems, refOrigin, refDest, DeliveredBySeller, exemptCert); if (response.ResponseType == MessageType.Error) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("TaxCloudError:{0}-{1}", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } else { foreach (CartItemResponse cir in response.CartItemsResponse) { taxRate += Math.Round(cir.TaxAmount, 2); } } return((decimal)taxRate); }