/// <summary> /// Validates the current province value /// </summary> /// <returns></returns> private bool ValidateProvince(out string provinceName) { provinceName = (Province.Visible ? StringHelper.StripHtml(Province.Text) : Province2.SelectedValue); string countryCode = Country.SelectedValue; if (ProvinceDataSource.CountForCountry(countryCode) == 0) { return(true); } //CHECK THE VALUE int provinceId = ProvinceDataSource.GetProvinceIdByName(countryCode, provinceName); if (provinceId > 0) { //UPDATE VALUE Province p = ProvinceDataSource.Load(provinceId); if (p.ProvinceCode.Length > 0) { provinceName = p.ProvinceCode; } else { provinceName = p.Name; } } return(provinceId > 0); }
/// <summary> /// Validates the current province value /// </summary> /// <returns></returns> private bool ValidateProvince(DropDownList CountryList, TextBox ProvinceText, DropDownList ProvinceList, out string provinceName) { provinceName = StringHelper.StripHtml(Request.Form[ProvinceText.UniqueID]); if (string.IsNullOrEmpty(provinceName)) { provinceName = Request.Form[ProvinceList.UniqueID]; } string countryCode = CountryList.SelectedValue; if (ProvinceDataSource.CountForCountry(countryCode) == 0) { return(true); } //CHECK THE VALUE int provinceId = ProvinceDataSource.GetProvinceIdByName(countryCode, provinceName); if (provinceId > 0) { //UPDATE VALUE Province p = ProvinceDataSource.Load(provinceId); if (p.ProvinceCode.Length > 0) { provinceName = p.ProvinceCode; } else { provinceName = p.Name; } } return(provinceId > 0); }
/// <summary> /// Gets the shipping addresses for the basket /// </summary> /// <param name="basket">The basket to parse; can be null to return the default shipping address</param> /// <returns>The shipping addresses for the basket</returns> public static List <TaxAddress> GetShippingAddresses(Basket basket) { List <TaxAddress> shippingAddresses = new List <TaxAddress>(); string shippingCountry; int shippingProvinceId; string shippingPostalCode; if (basket != null) { foreach (BasketShipment shipment in basket.Shipments) { Address shippingAddress = shipment.Address; if (shippingAddress != null && shippingAddress.IsValid) { shippingCountry = shippingAddress.CountryCode; shippingProvinceId = shippingAddress.ProvinceId; shippingPostalCode = shippingAddress.PostalCode; TaxAddress tempShippingAddress = new TaxAddress(shippingCountry, shippingProvinceId, shippingPostalCode); if (shippingAddresses.IndexOf(tempShippingAddress) < 0) { shippingAddresses.Add(tempShippingAddress); } } } } if (shippingAddresses.Count == 0) { Warehouse shippingAddress = Token.Instance.Store.DefaultWarehouse; shippingCountry = shippingAddress.CountryCode; shippingProvinceId = ProvinceDataSource.GetProvinceIdByName(shippingCountry, shippingAddress.Province); shippingPostalCode = shippingAddress.PostalCode; shippingAddresses.Add(new TaxAddress(shippingCountry, shippingProvinceId, shippingPostalCode)); } return(shippingAddresses); }
protected void ChangeProvinceListOKButton_Click(object sender, System.EventArgs e) { string controlName = HiddenSelectedProvinces.UniqueID; string postedValue = Request.Form[controlName]; //REMOVE ALL Provinces ASSOCIATED WITH SHIPZONE _ShipZone.Provinces.Clear(); _ShipZone.Provinces.Save(); if (!string.IsNullOrEmpty(postedValue)) { //ADD SELECTED Provinces BACK IN List <string> validCountryCodes = GetValidCountryCodes(); string[] postedProvinceCodes = postedValue.Split(",".ToCharArray()); foreach (string tempCode in postedProvinceCodes) { string[] codeParts = tempCode.Split(":".ToCharArray()); if (codeParts.Length == 2) { string countryCode = codeParts[0].Trim(); if (validCountryCodes.Contains(countryCode)) { string provinceName = codeParts[1].Trim(); int provinceId = ProvinceDataSource.GetProvinceIdByName(countryCode, provinceName); if (provinceId > 0) { Province province = ProvinceDataSource.Load(provinceId); _ShipZone.Provinces.Add(province); } } } } _ShipZone.Save(); } ProvinceList.Text = GetProvinceList(); }
private bool IsAddressValid(Address address) { if (string.IsNullOrEmpty(address.FirstName)) { return(false); } if (string.IsNullOrEmpty(address.LastName)) { return(false); } if (string.IsNullOrEmpty(address.Address1)) { return(false); } if (string.IsNullOrEmpty(address.City)) { return(false); } if (string.IsNullOrEmpty(address.CountryCode)) { return(false); } //SEE WHETHER POSTAL CODE IS REQUIRED string[] countries = AbleContext.Current.Store.Settings.PostalCodeCountries.Split(",".ToCharArray()); bool requirePostalCode = (Array.IndexOf(countries, address.CountryCode) > -1); if (requirePostalCode) { if (string.IsNullOrEmpty(address.PostalCode)) { return(false); } if ((address.CountryCode == "US") && (!Regex.IsMatch(address.PostalCode, "^\\d{5}(-\\d{4})?$"))) { return(false); } if ((address.CountryCode == "CA") && (!Regex.IsMatch(address.PostalCode, "^[A-Za-z][0-9][A-Za-z] ?[0-9][A-Za-z][0-9]$"))) { return(false); } } //SEE WHETHER PROVINCE IS VALID if (ProvinceDataSource.CountForCountry(address.CountryCode) > 0) { int provinceId = ProvinceDataSource.GetProvinceIdByName(address.CountryCode, address.Province); if (provinceId == 0) { return(false); } } return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="payment">The Payment object associated with this request</param> /// <param name="subscriptionPlan">The SubscriptionPlan associated witht this request</param> /// <param name="remoteIP">Remote IP of the user initiating the request</param> public AuthorizeRecurringTransactionRequest(Payment payment, SubscriptionPlan subscriptionPlan, string remoteIP) : base(payment, remoteIP) { this._TransactionOrigin = TransactionOrigin.Internet; if (subscriptionPlan != null) { this.SubscriptionName = subscriptionPlan.Name; this.Amount = payment.Amount; this.RecurringChargeSpecified = subscriptionPlan.RecurringChargeSpecified; // GET THE SUBSCRIPTION CHARGE WITH TAX Order order = payment.Order; int billToProvinceId = ProvinceDataSource.GetProvinceIdByName(order.BillToCountryCode, order.BillToProvince); TaxAddress billingAddress = new TaxAddress(order.BillToCountryCode, billToProvinceId, order.BillToPostalCode); this.RecurringCharge = TaxHelper.GetPriceWithTax(subscriptionPlan.RecurringCharge, subscriptionPlan.TaxCodeId, billingAddress, billingAddress); this.NumberOfPayments = subscriptionPlan.NumberOfPayments; this.PaymentFrequency = subscriptionPlan.PaymentFrequency; this.PaymentFrequencyUnit = subscriptionPlan.PaymentFrequencyUnit; } }
/// <summary> /// Gets the billing address for the basket /// </summary> /// <param name="basket">The basket to parse; if null the billing address of the current user is returned</param> /// <returns>The billing address for the basket, or current user if basket is null</returns> public static TaxAddress GetBillingAddress(Basket basket) { //BY DEFAULT, ASSUME STORE COUNTRY IS BILLING COUNTRY string billingCountry = string.Empty; int billingProvinceId = 0; string billingPostalCode = string.Empty; // OBTAIN THE BILLING ADDRESS User user = null; Address billingAddress = null; if (basket != null) { user = basket.User; } else { user = Token.Instance.User; } if (user != null) { billingAddress = user.PrimaryAddress; } // DETERMINE THE TAXABLE ADDRESS if (billingAddress != null && billingAddress.IsValid) { billingCountry = billingAddress.CountryCode; billingProvinceId = billingAddress.ProvinceId; billingPostalCode = billingAddress.PostalCode; } else { Warehouse storeAddress = Token.Instance.Store.DefaultWarehouse; billingCountry = storeAddress.CountryCode; billingProvinceId = ProvinceDataSource.GetProvinceIdByName(billingCountry, storeAddress.Province); billingPostalCode = storeAddress.PostalCode; } return(new TaxAddress(billingCountry, billingProvinceId, billingPostalCode)); }
/// <summary> /// Generates payment records for an order /// </summary> /// <param name="order">The order being created</param> /// <param name="checkoutRequest">The checkout request</param> /// <param name="giftCertPayments">The collection of gift certificate payments for this order</param> /// <param name="giftCertPaymentMethodId">The ID of the gift certificate payment method</param> /// <param name="orderItemSubscriptions">Order Item subscriptions</param> internal static void GenerateOrderPayments(Order order, CheckoutRequest checkoutRequest, List <BasketPaymentItem> giftCertPayments, int giftCertPaymentMethodId, Dictionary <int, Subscription[]> orderItemSubscriptions) { //THIS VARIABLE SHOULD ONLY CONTAIN DATA IF POST-CHECKOUT GATEWAY PROCESSING IS REQUIRED string saveAccountData = string.Empty; //USE A COMMON DATE FOR ALL PAYMENTS REGISTERED DateTime paymentDate = LocaleHelper.LocalNow; //CONVERT GIFT CERTIFICATE PLACEHOLDERS INTO PAYMENT ITEMS LSDecimal totalGiftCertPayment = 0; foreach (BasketPaymentItem giftCertItem in giftCertPayments) { Payment giftCertPayment = giftCertItem.GetPaymentObject(); totalGiftCertPayment += giftCertPayment.Amount; giftCertPayment.OrderId = order.OrderId; giftCertPayment.PaymentMethodId = giftCertPaymentMethodId; giftCertPayment.PaymentDate = paymentDate; order.Payments.Add(giftCertPayment); giftCertPayment.Save(); } //IF PAYMENT DATA WAS PASSED WITH CHECKOUT REQUEST, ADD TO ORDER RECORD NOW if (checkoutRequest != null && checkoutRequest.Payment != null) { //BUILD A LIST OF PAYMENTS TO ADD TO THE ORDER BASED ON CONTENTS Payment originalPayment = checkoutRequest.Payment; //DETERMINE TOTAL PAYMENT REQUIRED FOR ITEMS LSDecimal remainingPaymentAmount = order.Items.TotalPrice(); //PRESERVE ACCOUNT DATA saveAccountData = originalPayment.AccountData; //DECIDE WHETHER PAYMENTS MUST BE DIVIDED BECAUSE OF ARB SUBSCRIPTIONS if (orderItemSubscriptions.Count > 0) { //LOOP EACH ORDER ITEM WITH A RECURRING SUBSCRIPTION foreach (int orderItemId in orderItemSubscriptions.Keys) { // THIS STORES THE DISCOUNT TO APPLY TO EACH SUBSCRIPTION PAYMENT LSDecimal subscriptionDiscount = 0; // THIS STORES ADDITIONAL DISCOUNT TO APPLY ONLY TO THE FIRST SUBSCRIPTION LSDecimal firstSubscriptionAdjustment = 0; // GET THE TOTAL DISCOUNTS APPLIED TO THIS ORDER ITEM (VALUE SHOULD BE NEGATIVE) LSDecimal totalItemAdjustments = GetOrderItemAdjustments(order, orderItemId); // IF THERE IS A DISCOUNT, DETERMINE PRO-RATED DISCOUNT FOR EACH PAYMENT (ITEM) if (totalItemAdjustments != 0) { // THERE IS A DISCOUNT THAT APPLIES TO THIS ORDER ITEM, WE NEED TO DETERMINE AMOUNT // SUBSCRIPTION DISCOUNT IS TOTAL DISCOUNT BY THE NUMBER OF SUBSCRIPTION ITEMS subscriptionDiscount = (LSDecimal)Math.Floor((decimal)(totalItemAdjustments / orderItemSubscriptions[orderItemId].Length)); // DETERMINE THE TOTAL DISCOUNT AMOUNT USING CALCULATED PER-SUBSCRIPTION VALUE LSDecimal calculatedTotal = subscriptionDiscount * orderItemSubscriptions[orderItemId].Length; // THE TOTAL DISCOUNT MUST MATCH THE LUMP SUM, SO CALCULATE ANY LEFTOVER DISCOUNT FOR THE FIRST PAYMENT firstSubscriptionAdjustment = (totalItemAdjustments - calculatedTotal); } // WE MUST DETERMINE THE PRICE OF THE ITEM (INCLUDING TAX) // GET THE ORDER ITEM FOR THIS RECURRING SUBSCRIPTION OrderItem orderItem = order.Items[order.Items.IndexOf(orderItemId)]; // GET THE PRICE OF THE ITEM (INCLUDING TAX) int billToProvinceId = ProvinceDataSource.GetProvinceIdByName(order.BillToCountryCode, order.BillToProvince); TaxAddress billingAddress = new TaxAddress(order.BillToCountryCode, billToProvinceId, order.BillToPostalCode); LSDecimal subscriptionPrice = TaxHelper.GetPriceWithTax(orderItem.Price + subscriptionDiscount, orderItem.TaxCodeId, billingAddress, billingAddress); // LOOP ALL THE SUBSCRIPTIONS AND CREATE CORRESPONDING PAYMENT ITEMS foreach (Subscription s in orderItemSubscriptions[orderItemId]) { // ADD PAYMENT ITEM ASSOCIATED WITH THE SUBSCRIPTION Payment arbPayment = new Payment(); arbPayment.SubscriptionId = s.SubscriptionId; arbPayment.Amount = subscriptionPrice + firstSubscriptionAdjustment; arbPayment.CurrencyCode = originalPayment.CurrencyCode; arbPayment.OrderId = order.OrderId; arbPayment.PaymentDate = paymentDate; arbPayment.PaymentMethodId = originalPayment.PaymentMethodId; arbPayment.PaymentMethodName = originalPayment.PaymentMethodName; arbPayment.PaymentStatus = PaymentStatus.Unprocessed; arbPayment.ReferenceNumber = originalPayment.ReferenceNumber; arbPayment.AccountData = saveAccountData; order.Payments.Add(arbPayment); arbPayment.Save(); //ACCOUNT DATA IS RESET AFTER SAVE IN CASE THE SAVE METHOD ALTERS IT BASED //ON MERCHANT SECURITY SETTINGS, WE STILL NEED THE VALUE FOR THE CHECKOUT PROCESS arbPayment.AccountData = saveAccountData; arbPayment.IsDirty = false; // SUBTRACT THIS PAYMENT FROM THE REMAINING TOTAL remainingPaymentAmount -= arbPayment.Amount; // RESET ADJUSTMENT THAT SHOULD APPLY TO FIRST SUBSCRIPTION ONLY firstSubscriptionAdjustment = 0; } } //CREATE AN ADDITIONAL PAYMENT IF THERE IS ANY AMOUNT LEFT TO BE COLLECTED if (remainingPaymentAmount > 0) { //NEED ONE PAYMENT FOR EACH SUBSCRIPTION Payment remainingPayment = new Payment(); remainingPayment.SubscriptionId = 0; if (remainingPaymentAmount >= originalPayment.Amount) { remainingPayment.Amount = originalPayment.Amount; } else { remainingPayment.Amount = remainingPaymentAmount; } remainingPayment.CurrencyCode = originalPayment.CurrencyCode; remainingPayment.OrderId = order.OrderId; remainingPayment.PaymentDate = paymentDate; remainingPayment.PaymentMethodId = originalPayment.PaymentMethodId; remainingPayment.PaymentMethodName = originalPayment.PaymentMethodName; remainingPayment.PaymentStatus = PaymentStatus.Unprocessed; remainingPayment.ReferenceNumber = originalPayment.ReferenceNumber; remainingPayment.AccountData = saveAccountData; order.Payments.Add(remainingPayment); remainingPayment.Save(); //ACCOUNT DATA IS RESET AFTER SAVE IN CASE THE SAVE METHOD ALTERS IT BASED //ON MERCHANT SECURITY SETTINGS, WE STILL NEED THE VALUE FOR THE CHECKOUT PROCESS remainingPayment.AccountData = saveAccountData; remainingPayment.IsDirty = false; } } else { originalPayment.PaymentId = 0; originalPayment.SubscriptionId = 0; originalPayment.PaymentStatus = PaymentStatus.Unprocessed; originalPayment.OrderId = order.OrderId; originalPayment.PaymentDate = paymentDate; order.Payments.Add(originalPayment); originalPayment.Save(); //ACCOUNT DATA IS RESET AFTER SAVE IN CASE THE SAVE METHOD ALTERS IT BASED //ON MERCHANT SECURITY SETTINGS, WE STILL NEED THE VALUE FOR THE CHECKOUT PROCESS originalPayment.AccountData = saveAccountData; originalPayment.IsDirty = false; } } }