public void CommitTax(Order order) { List <int> shipAddresses = Shipping.GetDistinctShippingAddressIDs(order.CartItems); if (shipAddresses.Count == 1) { CapturedRsp response = tc.Captured(ApiLoginID, ApiKey, order.OrderNumber.ToString()); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be captured({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } else { foreach (int _addressID in shipAddresses) { CapturedRsp response = tc.Captured(ApiLoginID, ApiKey, GetMultipleShippingAddressOrderNumber(order.OrderNumber, _addressID)); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be captured({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } } }
public decimal GetTaxRate(Customer customer, CartItemCollection cartItems, IEnumerable <OrderOption> orderOptions) { if (!customer.HasAtLeastOneAddress() || !cartItems.Any()) { return(0m); } // Return the cached value if it's present and still valid string lastCartHash = HttpContext.Current.Items["TaxCloud.CartHash"] as string; decimal?lastTaxAmount = HttpContext.Current.Items["TaxCloud.TaxAmount"] as decimal?; string currentCartHash = GetCartHash(cartItems, customer, orderOptions); if (lastTaxAmount != null && currentCartHash == lastCartHash) { return(lastTaxAmount.Value); } // Create line items for all cart items and shipping selections decimal taxAmount = 0M; List <CouponObject> CouponList = cartItems.CouponList; List <QDObject> QuantityDiscountList = cartItems.QuantityDiscountList; if (Shipping.GetDistinctShippingAddressIDs(cartItems).Count == 1) { IEnumerable <net.taxcloud.api.CartItem> refCartitems = ConvertCartItems(cartItems, customer); net.taxcloud.api.Address destAddress = ConvertAddress(customer.PrimaryShippingAddress); refCartitems = refCartitems.Concat(CreateCartShippingLineItem(customer, cartItems, orderOptions)).Concat(CreateOrderOptionLineItems(orderOptions)); taxAmount = lookupTaxRate(customer.CustomerID.ToString(), refCartitems.ToArray(), refOrigin, destAddress); } else { List <int> shipAddresses = Shipping.GetDistinctShippingAddressIDs(cartItems); foreach (int _addressID in shipAddresses) { net.taxcloud.api.Address destAddress = ConvertAddress(_addressID); IEnumerable <CartItem> tmpcic = cartItems.Where(r => r.ShippingAddressID == _addressID); IEnumerable <net.taxcloud.api.CartItem> refCartitems = ConvertCartItems(tmpcic, customer, CouponList, QuantityDiscountList); refCartitems = refCartitems.Concat(CreateCartShippingLineItem(customer, tmpcic, orderOptions)); if (_addressID == customer.PrimaryShippingAddressID) { refCartitems = refCartitems.Concat(CreateOrderOptionLineItems(orderOptions)); } taxAmount += lookupTaxRate(customer.CustomerID.ToString(), refCartitems.ToArray(), refOrigin, destAddress); } } //Cache the tax amount HttpContext.Current.Items["TaxCloud.CartHash"] = currentCartHash; HttpContext.Current.Items["TaxCloud.TaxAmount"] = taxAmount; return(taxAmount); }
public void VoidTax(Order order) { List <int> shipAddresses = Shipping.GetDistinctShippingAddressIDs(order.CartItems); if (shipAddresses.Count == 1) { IEnumerable <net.taxcloud.api.CartItem> refItems = ConvertCartItems(order.CartItems, new Customer(order.CustomerID)); refItems = refItems.Concat(CreateOrderShippingLineItem(order, shipAddresses.First())); ReturnedRsp response = tc.Returned(ApiLoginID, ApiKey, order.OrderNumber.ToString(), refItems.ToArray(), DateTime.Now); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be Canceled({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } else { Customer customer = new Customer(order.CustomerID); List <CouponObject> CouponList = order.CartItems.CouponList; List <QDObject> QuantityDiscountList = order.CartItems.QuantityDiscountList; IEnumerable <OrderOption> orderOptions = GetOrderOptions(order); foreach (int _addressID in shipAddresses) { IEnumerable <CartItem> tmpcic = order.CartItems.Where(r => r.ShippingAddressID == _addressID); IEnumerable <net.taxcloud.api.CartItem> refCartitems = ConvertCartItems(tmpcic, customer, CouponList, QuantityDiscountList); refCartitems = refCartitems.Concat(CreateOrderShippingLineItem(order, _addressID)); if (_addressID == customer.PrimaryShippingAddressID) { refCartitems = refCartitems.Concat(CreateOrderOptionLineItems(orderOptions)); } ReturnedRsp response = tc.Returned(ApiLoginID, ApiKey, GetMultipleShippingAddressOrderNumber(order.OrderNumber, _addressID), refCartitems.ToArray(), DateTime.Now); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be Canceled({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } } }
public void OrderPlaced(Order order) { //string cartId = GetCartID(order.CustomerID.ToString(), refDest.Zip5, refItems.First().Index); string _cartID = string.Empty; List <int> shipAddresses = Shipping.GetDistinctShippingAddressIDs(order.CartItems); if (shipAddresses.Count == 1) { _cartID = GetCartID(order.CustomerID.ToString(), order.ShippingAddress.m_Zip, order.CartItems.First().ShoppingCartRecordID); AuthorizedRsp response = tc.Authorized(ApiLoginID, ApiKey, order.CustomerID.ToString(), _cartID, order.OrderNumber.ToString(), DateTime.Now); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be Authorized({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } else { Customer customer = new Customer(order.CustomerID); foreach (int _addressID in shipAddresses) { net.taxcloud.api.Address destAddress = ConvertAddress(_addressID); IEnumerable <CartItem> tmpcic = order.CartItems.Where(r => r.ShippingAddressID == _addressID); Address _address = new Address(); _address.LoadFromDB(_addressID); _cartID = GetCartID(order.CustomerID.ToString(), _address.Zip, tmpcic.First().ShoppingCartRecordID); AuthorizedRsp response = tc.Authorized(ApiLoginID, ApiKey, order.CustomerID.ToString(), _cartID, GetMultipleShippingAddressOrderNumber(order.OrderNumber, _addressID), DateTime.Now); if (response.ResponseType != MessageType.OK) { string errormsg = String.Empty; foreach (ResponseMessage message in response.Messages) { errormsg += string.Format("Purchase could not be Authorized({0}-{1})", message.ResponseType.ToString(), message.Message); } throw new Exception(errormsg); } } } }