public static FakePayment CreatePayment(decimal amount,
                                         PaymentType paymentType,
                                         Guid paymentMethodId,
                                         string authorizationCode     = "",
                                         string customerName          = "",
                                         string implementationClass   = "",
                                         string paymentMethodName     = "",
                                         string providerTransactionID = "",
                                         string status                = "",
                                         string transactionID         = "",
                                         string transactionType       = "",
                                         string validationCode        = "",
                                         IOrderAddress billingAddress = null,
                                         Hashtable properties         = null)
 {
     return(new FakePayment
     {
         Amount = amount,
         AuthorizationCode = authorizationCode,
         BillingAddress = billingAddress ?? FakeOrderAddress.CreateOrderAddress(),
         CustomerName = customerName,
         ImplementationClass = implementationClass,
         PaymentMethodId = paymentMethodId,
         PaymentMethodName = paymentMethodName,
         PaymentType = paymentType,
         ProviderTransactionID = providerTransactionID,
         Status = status,
         TransactionID = transactionID,
         TransactionType = transactionType,
         ValidationCode = validationCode,
         Properties = properties ?? new Hashtable()
     });
 }
Example #2
0
        /// <summary>
        /// Gets the alpha2 country code.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns></returns>
        public CountryCodeType GetAlpha2CountryCode(IOrderAddress address)
        {
            if (CountryCodeTable == null)
            {
                return(CountryCodeType.CUSTOMCODE);
            }

            string code = string.Empty;

            foreach (DataRow row in CountryCodeTable.Rows)
            {
                if (row[0].ToString().Equals(address.CountryCode, StringComparison.OrdinalIgnoreCase))
                {
                    code = row[1].ToString().ToUpperInvariant();
                    break;
                }
            }

            foreach (CountryCodeType value in Enum.GetValues(typeof(CountryCodeType)))
            {
                if (value.ToString().ToUpperInvariant() == code)
                {
                    return(value);
                }
            }

            return(CountryCodeType.CUSTOMCODE);
        }
        public virtual OmniumOrderLine MapOrderLine(
            ILineItem lineItem, IMarket market, Currency currency, IOrderAddress address)
        {
            var marketId = market.MarketId;

            var taxTotal = _lineItemCalculator.GetSalesTax(lineItem, market, currency, address);
            var taxRate  = _taxUtility.GetTaxValue(marketId, address, TaxType.SalesTax, lineItem.TaxCategoryId);

            var placedPrice      = _taxUtility.GetPriceTax(lineItem, market, currency, address, lineItem.PlacedPrice);
            var discountedAmount = _taxUtility.GetPriceTax(lineItem, market, currency, address, lineItem.GetDiscountTotal(currency)); //all discounts (line item + coupon code)
            var extendedPrice    = _taxUtility.GetPriceTax(lineItem, market, currency, address, _lineItemCalculator.GetExtendedPrice(lineItem, currency));
            var discountedPrice  = _taxUtility.GetPriceTax(lineItem, market, currency, address, _lineItemCalculator.GetDiscountedPrice(lineItem, currency));

            var omniumOrderLine2 = new OmniumOrderLine
            {
                Code                   = lineItem.Code,
                ProductId              = GetProductCode(lineItem.Code),
                DisplayName            = lineItem.DisplayName,
                PlacedPrice            = placedPrice.PriceInclTax,
                PlacedPriceExclTax     = placedPrice.PriceExclTax,
                ExtendedPrice          = extendedPrice.PriceInclTax,
                ExtendedPriceExclTax   = extendedPrice.PriceExclTax,
                DiscountedPrice        = discountedPrice.PriceInclTax,
                DiscountedPriceExclTax = discountedPrice.PriceExclTax,
                Discounted             = discountedAmount.PriceInclTax,
                DiscountedExclTax      = discountedAmount.PriceExclTax,
                TaxTotal               = taxTotal,
                TaxRate                = (decimal)taxRate,
                LineItemId             = lineItem.LineItemId.ToString(),
                Quantity               = lineItem.Quantity,
                Properties             = lineItem.ToPropertyList()
            };

            return(omniumOrderLine2);
        }
Example #4
0
        private PaymentProcessingResult ProcessPaymentCapture(IOrderGroup orderGroup,
                                                              ICreditCardPayment creditCardPayment,
                                                              IOrderAddress billingAddress)
        {
            if (string.IsNullOrEmpty(creditCardPayment.ProviderPaymentId))
            {
                return(Charge(orderGroup, creditCardPayment, billingAddress));
            }
            try
            {
                var capture = _stripeChargeService.Capture(creditCardPayment.ProviderPaymentId, new StripeChargeCaptureOptions());
                if (!string.IsNullOrEmpty(capture.FailureCode))
                {
                    return(PaymentProcessingResult.CreateUnsuccessfulResult(Translate(capture.Outcome.Reason)));
                }
                creditCardPayment.ProviderPaymentId     = capture.Id;
                creditCardPayment.ProviderTransactionID = capture.BalanceTransactionId;
                return(PaymentProcessingResult.CreateSuccessfulResult(""));
            }
            catch (StripeException e)
            {
                switch (e.StripeError.ErrorType)
                {
                case "card_error":
                    return(PaymentProcessingResult.CreateUnsuccessfulResult(Translate(e.StripeError.Code)));

                default:
                    return(PaymentProcessingResult.CreateUnsuccessfulResult(e.StripeError.Message));
                }
            }
        }
        /// <summary>
        /// Initialize a payment request from an <see cref="OrderGroup"/> instance. Adds order number, amount, timestamp, buyer information etc.
        /// </summary>
        /// <param name="payment">The <see cref="VerifonePaymentRequest"/> instance to initialize</param>
        /// <param name="orderGroup"><see cref="OrderGroup"/></param>
        public virtual void InitializePaymentRequest(VerifonePaymentRequest payment, IOrderGroup orderGroup)
        {
            IOrderAddress billingAddress  = FindBillingAddress(payment, orderGroup);
            IOrderAddress shipmentAddress = FindShippingAddress(payment, orderGroup);

            payment.OrderTimestamp        = orderGroup.Created.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            payment.MerchantAgreementCode = GetMerchantAgreementCode(payment);
            payment.PaymentLocale         = GetPaymentLocale(ContentLanguage.PreferredCulture);
            payment.OrderNumber           = orderGroup.OrderLink.OrderGroupId.ToString(CultureInfo.InvariantCulture.NumberFormat);

            payment.OrderCurrencyCode = IsProduction(payment)
                ? Iso4217Lookup.LookupByCode(CurrentMarket.DefaultCurrency.CurrencyCode).Number.ToString()
                : "978";

            var totals = OrderGroupCalculator.GetOrderGroupTotals(orderGroup);

            payment.OrderGrossAmount = totals.Total.ToVerifoneAmountString();

            var netAmount = orderGroup.PricesIncludeTax ? totals.Total : totals.Total - totals.TaxTotal;

            payment.OrderNetAmount = netAmount.ToVerifoneAmountString();
            payment.OrderVatAmount = totals.TaxTotal.ToVerifoneAmountString();

            payment.BuyerFirstName       = billingAddress?.FirstName;
            payment.BuyerLastName        = billingAddress?.LastName;
            payment.OrderVatPercentage   = "0";
            payment.PaymentMethodCode    = "";
            payment.SavedPaymentMethodId = "";
            payment.RecurringPayment     = "0";
            payment.DeferredPayment      = "0";
            payment.SavePaymentMethod    = "0";
            payment.SkipConfirmationPage = "0";

            string phoneNumber = billingAddress?.DaytimePhoneNumber ?? billingAddress?.EveningPhoneNumber;

            if (string.IsNullOrWhiteSpace(phoneNumber) == false)
            {
                payment.BuyerPhoneNumber = phoneNumber;
            }

            payment.BuyerEmailAddress = billingAddress?.Email ?? orderGroup.Name ?? string.Empty;

            if (payment.BuyerEmailAddress.IndexOf('@') < 0)
            {
                payment.BuyerEmailAddress = null;
            }

            payment.DeliveryAddressLineOne = shipmentAddress?.Line1;

            if (shipmentAddress != null && string.IsNullOrWhiteSpace(shipmentAddress.Line2) == false)
            {
                payment.DeliveryAddressLineTwo = shipmentAddress.Line2;
            }

            payment.DeliveryAddressPostalCode  = shipmentAddress?.PostalCode;
            payment.DeliveryAddressCity        = shipmentAddress?.City;
            payment.DeliveryAddressCountryCode = "246";

            ApplyPaymentMethodConfiguration(payment);
        }
        public virtual OmniumOrderAddress MapOrderAddress(IOrderAddress orderAddress)
        {
            if (orderAddress == null)
            {
                return(new OmniumOrderAddress());
            }

            return(new OmniumOrderAddress
            {
                Name = $"{orderAddress.FirstName} {orderAddress.LastName}",
                FirstName = orderAddress.FirstName,
                LastName = orderAddress.LastName,
                DaytimePhoneNumber = orderAddress.DaytimePhoneNumber,
                EveningPhoneNumber = orderAddress.EveningPhoneNumber,
                Email = orderAddress.Email,
                Line1 = orderAddress.Line1,
                Line2 = orderAddress.Line2,
                PostalCode = orderAddress.PostalCode,
                City = orderAddress.City,
                CountryCode = GetFormattedCountryCode(orderAddress.CountryCode),
                CountryName = orderAddress.CountryName,
                Organization = orderAddress.Organization,
                RegionCode = orderAddress.RegionCode,
                RegionName = orderAddress.RegionName
            });
        }
Example #7
0
        private static void UpdateShipment(ICart cart, IOrderAddress orderAddress, ShippingDetails shippingDetails)
        {
            var shipment = cart.GetFirstShipment();

            shipment.ShippingMethodId = new Guid(shippingDetails.ShippingMethodId);
            shipment.ShippingAddress  = orderAddress;
        }
        public void MapToModel(IOrderAddress orderAddress, AddressModel addressModel)
        {
            if (orderAddress == null)
            {
                return;
            }

            addressModel.AddressId     = orderAddress.Id;
            addressModel.Name          = orderAddress.Id;
            addressModel.Line1         = orderAddress.Line1;
            addressModel.Line2         = orderAddress.Line2;
            addressModel.City          = orderAddress.City;
            addressModel.CountryName   = orderAddress.CountryName;
            addressModel.CountryCode   = orderAddress.CountryCode;
            addressModel.Email         = orderAddress.Email;
            addressModel.FirstName     = orderAddress.FirstName;
            addressModel.LastName      = orderAddress.LastName;
            addressModel.PostalCode    = orderAddress.PostalCode;
            addressModel.Organization  = orderAddress.Organization;
            addressModel.CountryRegion = new CountryRegionViewModel
            {
                Region = orderAddress.RegionName ?? orderAddress.RegionCode
            };
            addressModel.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
        }
Example #9
0
        /// <summary>
        /// Gets the PayPal address type model from a specific IOrderAddress.
        /// </summary>
        /// <value>The PayPal address type model.</value>
        public static AddressType ToAddressType(IOrderAddress orderAddress)
        {
            var addressType = new AddressType
            {
                CityName    = orderAddress.City,
                Country     = CountriesAndStates.GetAlpha2CountryCode(orderAddress.CountryCode),
                CountryName = orderAddress.CountryName,
                Street1     = orderAddress.Line1,
                Street2     = orderAddress.Line2,
                PostalCode  = orderAddress.PostalCode,
                Phone       = string.IsNullOrEmpty(orderAddress.DaytimePhoneNumber)
                    ? orderAddress.EveningPhoneNumber
                    : orderAddress.DaytimePhoneNumber,
                Name = orderAddress.FirstName + " " + orderAddress.LastName
            };

            var stateName = orderAddress.RegionName;
            var address   = orderAddress as OrderAddress;

            if (!string.IsNullOrEmpty(address?.State))
            {
                stateName = address.State;
            }

            addressType.StateOrProvince = CountriesAndStates.GetStateCode(stateName);
            return(addressType);
        }
Example #10
0
        private void AdjustFirstShipmentInOrder(ICart cart, IOrderAddress orderAddress, Guid selectedShip)
        {
            // Need to set the guid (name is good to have too) of some "real shipmentment in the DB"
            // RoCe - this step is not needed, actually - code and lab-steps can be updated
            // We'll do it to show how it works
            var shippingMethod = ShippingManager.GetShippingMethod(selectedShip).ShippingMethod.First();

            IShipment theShip = cart.GetFirstShipment(); // ...as we get one "for free"

            // Need the choice of shipment from DropDowns
            theShip.ShippingMethodId = shippingMethod.ShippingMethodId;
            //theShip.ShippingMethodName = "TucTuc";

            theShip.ShippingAddress = orderAddress;

            #region Hard coded and cheating just to show

            // RoCe: - fix the MarketService
            var   mSrv          = ServiceLocator.Current.GetInstance <IMarketService>();
            var   defaultMarket = mSrv.GetMarket(MarketId.Default); // cheating some
            Money cost00        = theShip.GetShippingCost(_currentMarket.GetCurrentMarket(), new Currency("USD"));
            Money cost000       = theShip.GetShippingCost(_currentMarket.GetCurrentMarket(), cart.Currency);
            #endregion

            Money cost0 = theShip.GetShippingCost(
                _currentMarket.GetCurrentMarket()
                , _currentMarket.GetCurrentMarket().DefaultCurrency); // to make it easy

            // done by the "default calculator"
            Money cost1 = theShip.GetShippingItemsTotal(_currentMarket.GetCurrentMarket().DefaultCurrency);

            theShip.ShipmentTrackingNumber = "ABC123";
        }
Example #11
0
        /// <summary>
        /// Updates order address information from PayPal address type model.
        /// </summary>
        /// <param name="orderAddress">The order address.</param>
        /// <param name="customerAddressType">The customer address type.</param>
        /// <param name="addressType">The PayPal address type.</param>
        /// <param name="payerEmail">The PayPal payer email.</param>
        public static void UpdateOrderAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType, AddressType addressType, string payerEmail)
        {
            var name = Utilities.StripPreviewText(addressType.Name.Trim(), 46);

            orderAddress.City               = addressType.CityName;
            orderAddress.CountryCode        = CountriesAndStates.GetAlpha3CountryCode(addressType.Country.ToString().ToUpperInvariant());
            orderAddress.DaytimePhoneNumber = addressType.Phone;
            orderAddress.EveningPhoneNumber = addressType.Phone;
            orderAddress.Line1              = addressType.Street1;
            orderAddress.Line2              = addressType.Street2;
            orderAddress.PostalCode         = addressType.PostalCode;
            orderAddress.Email              = payerEmail;
            var index = name.IndexOf(' ');

            orderAddress.FirstName  = index >= 0 ? name.Substring(0, index) : name;
            orderAddress.LastName   = index >= 0 ? name.Substring(index + 1) : string.Empty;
            orderAddress.RegionCode = addressType.StateOrProvince;
            orderAddress.RegionName = CountriesAndStates.GetStateName(addressType.StateOrProvince);
            if (orderAddress is OrderAddress address)
            {
                address.State = orderAddress.RegionName;
            }

            TrySaveCustomerAddress(orderAddress, customerAddressType);
        }
        private string GetTaxNewSchool(ShirtVariation currentContent)
        {
            IMarket market    = _currentMarket.GetCurrentMarket();
            Guid    currCust  = CustomerContext.Current.CurrentContactId;
            string  bogusCart = "BogusCart";

            ICart cart = _orderRepository.LoadOrCreateCart <ICart>(
                currCust, bogusCart);

            ILineItem lineItem = _orderGroupFactory.CreateLineItem(currentContent.Code, cart);

            lineItem.Quantity      = 1;
            lineItem.PlacedPrice   = GetCustomerPricingPrice(currentContent).UnitPrice.Amount;
            lineItem.TaxCategoryId = currentContent.TaxCategoryId;
            cart.AddLineItem(lineItem);

            IOrderAddress bogusAddress = _orderGroupFactory.CreateOrderAddress(cart);

            bogusAddress.CountryCode = "sv";
            bogusAddress.City        = "Stockholm";
            bogusAddress.CountryName = "Sweden";

            string str = String.Empty;
            //str += _taxCalc.Service.GetTaxTotal(cart, market, market.DefaultCurrency).Amount.ToString();

            var taxValues = Enumerable.Empty <ITaxValue>();

            taxValues = OrderContext.Current.GetTaxes(Guid.Empty, currentContent.theTaxCategory, "sv", bogusAddress);

            str = _taxCalc.Service.GetSalesTax(lineItem, market, bogusAddress, new Money(0m, "SEK")).ToString();


            return(str);
        }
Example #13
0
        private static void AdjustPriceAndTaxes(Currency currency, ILineItem lineItem,
            DinteroOrderLine dinteroItem, IOrderAddress orderAddress)
        {
            var amount = lineItem.GetExtendedPrice(currency).Amount;
            double vat = 0;

            var entryDto = CatalogContext.Current.GetCatalogEntryDto(lineItem.Code,
                new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            if (entryDto.CatalogEntry.Count > 0)
            {
                CatalogEntryDto.VariationRow[] variationRows = entryDto.CatalogEntry[0].GetVariationRows();
                if (variationRows.Length > 0)
                {
                    var taxCategory = CatalogTaxManager.GetTaxCategoryNameById(variationRows[0].TaxCategoryId);
                    var taxes = OrderContext.Current.GetTaxes(Guid.Empty, taxCategory,
                        Thread.CurrentThread.CurrentCulture.Name, orderAddress).ToList();

                    foreach (var tax in taxes)
                    {
                        if (tax.TaxType == TaxType.SalesTax)
                        {
                            vat = tax.Percentage;
                        }
                    }
                }
            }

            dinteroItem.Amount = CurrencyHelper.CurrencyToInt(amount, currency.CurrencyCode);
            dinteroItem.Vat = Convert.ToInt32(vat);
            dinteroItem.VatAmount = GetVatAmount(amount, vat, currency.CurrencyCode);
        }
Example #14
0
        public static OrderManagementAddressInfo ToAddress(this IOrderAddress orderAddress)
        {
            var address = new OrderManagementAddressInfo();

            address.GivenName      = orderAddress.FirstName;
            address.FamilyName     = orderAddress.LastName;
            address.StreetAddress  = orderAddress.Line1;
            address.StreetAddress2 = orderAddress.Line2;
            address.PostalCode     = orderAddress.PostalCode;
            address.City           = orderAddress.City;
            address.Country        = CountryCodeHelper.GetTwoLetterCountryCode(orderAddress.CountryCode);
            if (orderAddress.CountryCode != null && address.Country.Equals("us", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(orderAddress.RegionName))
            {
                address.Region =
                    CountryCodeHelper.GetStateCode(CountryCodeHelper.GetTwoLetterCountryCode(orderAddress.CountryCode),
                                                   orderAddress.RegionName);
            }
            else
            {
                address.Region = orderAddress.RegionName;
            }

            address.Email = orderAddress.Email;
            address.Phone = orderAddress.DaytimePhoneNumber ?? orderAddress.EveningPhoneNumber;

            return(address);
        }
Example #15
0
 /// <summary>
 /// Determines whether the address is changed.
 /// </summary>
 /// <param name="orderAddress">The order address.</param>
 /// <param name="addressType">The PayPal address type.</param>
 /// <returns>
 ///     <c>true</c> if [is address changed] [the specified order address]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsAddressChanged(IOrderAddress orderAddress, AddressType addressType)
 {
     return(!string.Equals(orderAddress.City, addressType.CityName, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.CountryCode, CountriesAndStates.GetAlpha3CountryCode(addressType.Country.ToString().ToUpperInvariant()), StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.Line1, addressType.Street1, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.Line2 ?? string.Empty, addressType.Street2 ?? string.Empty, StringComparison.OrdinalIgnoreCase) ||
            !string.Equals(orderAddress.PostalCode, addressType.PostalCode, StringComparison.OrdinalIgnoreCase));
 }
        private void CreatePayment(IPaymentMethodViewModel <PaymentMethodBase> paymentViewModel, AddressModel billingAddress)
        {
            IOrderAddress address = _addressBookService.ConvertToAddress(billingAddress);
            var           total   = Cart.GetTotal(_orderGroupCalculator);
            var           payment = paymentViewModel.PaymentMethod.CreatePayment(total.Amount);

            Cart.AddPayment(payment, _orderFactory);
            payment.BillingAddress = address;
        }
Example #17
0
 public virtual double GetTaxValue(MarketId marketId, IOrderAddress address, TaxType taxType, int?taxCategoryId)
 {
     // Only return 0 when address is null or when tax category is null and we want to get the tax rate for line items. For Shipping tax, we want to use the default tax category
     if (address == null || (taxType == TaxType.SalesTax && !taxCategoryId.HasValue))
     {
         return(0.0);
     }
     return(GetTaxValue(marketId, address.CountryCode, address.RegionCode, address.PostalCode, address.City, taxType, taxCategoryId));
 }
Example #18
0
        private IOrderAddress AddAddressToOrder(ICart cart)
        {
            IOrderAddress shippingAddress = null;

            if (CustomerContext.Current.CurrentContact == null)
            {
                IShipment shipment = cart.GetFirstShipment();
                if (shipment.ShippingAddress != null)
                {
                    //using the cart.GetFirstShipment() seems only useful if we are checking for an existing address, otherwise
                    //the solution code's recommended 'new school' approach doesn't use it.
                }
                IOrderAddress myOrderAddress = _orderGroupFactory.CreateOrderAddress(cart);
                myOrderAddress.CountryName = "United States";
                myOrderAddress.Id          = "HomersShippingAddress";
                myOrderAddress.Email       = "*****@*****.**";

                shippingAddress = myOrderAddress;
            }
            else
            {
                //User is logged in
                if (CustomerContext.Current.CurrentContact.PreferredShippingAddress == null)
                {
                    CustomerAddress newCustAddress = CustomerAddress.CreateInstance();
                    newCustAddress.AddressType        = CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Public; //mandatory
                    newCustAddress.ContactId          = CustomerContext.Current.CurrentContact.PrimaryKeyId;
                    newCustAddress.CountryCode        = "USA";
                    newCustAddress.CountryName        = "United States";
                    newCustAddress.Name               = "Wilbur's customer address"; // mandatory
                    newCustAddress.DaytimePhoneNumber = "9008675309";
                    newCustAddress.FirstName          = CustomerContext.Current.CurrentContact.FirstName;
                    newCustAddress.LastName           = CustomerContext.Current.CurrentContact.LastName;
                    newCustAddress.Email              = "*****@*****.**";

                    // note: Line1 & City is what is shown in CM at a few places... not the Name
                    CustomerContext.Current.CurrentContact.AddContactAddress(newCustAddress);
                    CustomerContext.Current.CurrentContact.SaveChanges();

                    // ... needs to be in this order
                    CustomerContext.Current.CurrentContact.PreferredShippingAddress = newCustAddress;
                    CustomerContext.Current.CurrentContact.SaveChanges(); // need this ...again

                    // then, for the cart
                    //.Cart.OrderAddresses.Add(new OrderAddress(newCustAddress)); - OLD
                    shippingAddress = new OrderAddress(newCustAddress); // - NEW
                }
                else
                {
                    shippingAddress = new OrderAddress(CustomerContext.Current.CurrentContact.PreferredShippingAddress);
                }
            }

            return(shippingAddress);
        }
Example #19
0
        private void UpdatePayment(ICart cart, IPayment payment, IOrderAddress orderAddress, TransactionInfo transactionInfo, string orderId)
        {
            cart.GetFirstForm().Payments.Clear();
            var total      = cart.GetTotal(_orderGroupCalculator);
            var newPayment = PaymentHelper.CreateVippsPayment(cart, total, payment.PaymentMethodId);

            newPayment.Status = PaymentStatus.Processed.ToString();
            cart.AddPayment(newPayment, _orderGroupFactory);
            newPayment.BillingAddress = orderAddress;
            newPayment.TransactionID  = orderId;
        }
        public AddressModel ConvertToModel(IOrderAddress orderAddress)
        {
            var address = new AddressModel();

            if (orderAddress != null)
            {
                MapToModel(orderAddress, address);
            }

            return(address);
        }
Example #21
0
 public static void CopyTo(this IOrderAddress srcAddress, IOrderAddress destAddress)
 {
     destAddress.Company   = srcAddress.Company;
     destAddress.FirstName = srcAddress.FirstName;
     destAddress.LastName  = srcAddress.LastName;
     destAddress.Address1  = srcAddress.Address1;
     destAddress.Address2  = srcAddress.Address2;
     destAddress.Zipcode   = srcAddress.Zipcode;
     destAddress.City      = srcAddress.City;
     destAddress.Country   = srcAddress.Country;
     destAddress.State     = srcAddress.State;
 }
Example #22
0
 public static void CopyTo(this IOrderAddress srcAddress, IOrderAddress destAddress)
 {
     destAddress.Company = srcAddress.Company;
     destAddress.FirstName = srcAddress.FirstName;
     destAddress.LastName = srcAddress.LastName;
     destAddress.Address1 = srcAddress.Address1;
     destAddress.Address2 = srcAddress.Address2;
     destAddress.Zipcode = srcAddress.Zipcode;
     destAddress.City = srcAddress.City;
     destAddress.Country = srcAddress.Country;
     destAddress.State = srcAddress.State;
 }
Example #23
0
        private IOrderAddress AddAddressToOrder(ICart cart)
        {
            IOrderAddress shippingAddress = null;

            if (CustomerContext.Current.CurrentContact == null)
            {
            }
            else
            {
            }

            return(shippingAddress);
        }
Example #24
0
 public string FormatAddress(IOrderAddress address)
 {
     if (address.Country == null || String.IsNullOrWhiteSpace(address.Country.AddressFormat)) {
         // TODO : Provide default format
         return "";
     }
     else {
         return _tokenizer.Replace(
             address.Country.AddressFormat,
             new Dictionary<string, object> { { "OrderAddress", address } }
         ).Trim(new char[]{' ', '-', '\r', '\n'});
     }
 }
Example #25
0
        public AddressModel ConvertToModel(IOrderAddress orderAddress)
        {
            var address = new AddressModel {
                AddressId = Guid.NewGuid().ToString()
            };

            if (orderAddress != null)
            {
                MapToModel(orderAddress, address);
            }

            return(address);
        }
Example #26
0
 public static FakeShipment CreatShipment(int id, Guid shippingMethodId, IOrderAddress shippingAddress, IList <ILineItem> items = null, Hashtable properties = null)
 {
     return(new FakeShipment
     {
         ShipmentId = id,
         ShippingAddress = shippingAddress,
         ShippingMethodId = shippingMethodId,
         ShipmentDiscount = 0,
         WarehouseCode = "default",
         LineItems = items ?? new List <ILineItem>(),
         Properties = properties ?? new Hashtable()
     });
 }
Example #27
0
        public decimal GetTaxPercentage(IMarket market, IOrderAddress shippingAddress, TaxType taxType)
        {
            var taxValues = base.GetTaxValues("General Sales", market.DefaultLanguage.Name, shippingAddress).ToList();

            if (!taxValues.Any())
            {
                return(0);
            }

            var taxValue = taxValues.FirstOrDefault(x => x.TaxType == taxType);

            return(taxValue != null ? (decimal)taxValue.Percentage : 0);
        }
Example #28
0
 public static FakeShipment CreatShipment(int id, IOrderAddress orderAddress, decimal discount, IList <ILineItem> items, string shippingMethodIdString = null, Hashtable properties = null)
 {
     return(new FakeShipment
     {
         ShipmentId = id,
         ShippingAddress = orderAddress,
         ShippingMethodId = new Guid(shippingMethodIdString ?? "7eedee57-c8f4-4d19-a58c-284e72094527"),
         ShipmentDiscount = discount,
         WarehouseCode = "default",
         LineItems = items,
         Properties = properties ?? new Hashtable()
     });
 }
Example #29
0
        public decimal GetTaxPercentage(ILineItem lineItem, IMarket market, IOrderAddress shippingAddress, TaxType taxType)
        {
            var taxValues = GetTaxValues(lineItem, market, shippingAddress).ToList();

            if (!taxValues.Any())
            {
                return(0);
            }

            var taxValue = taxValues.FirstOrDefault(x => x.TaxType == taxType);

            return(taxValue != null ? (decimal)taxValue.Percentage : 0);
        }
        private void CreatePayment(IPaymentMethodViewModel <PaymentMethodBase> paymentViewModel, AddressModel billingAddress)
        {
            IOrderAddress address = _addressBookService.ConvertToAddress(Cart, billingAddress);
            var           total   = Cart.GetTotal(_orderGroupCalculator);
            var           payment = paymentViewModel.PaymentMethod.CreatePayment(Cart, total.Amount);

            Cart.AddPayment(payment, _orderGroupFactory);
            payment.BillingAddress = address;

            if (Cart.IsQuoteCart())
            {
                payment.TransactionType = TransactionType.Capture.ToString();
            }
        }
        protected virtual IOrderAddress FindBillingAddress(VerifonePaymentRequest payment, IOrderGroup orderGroup)
        {
            IOrderForm    orderForm      = FindCorrectOrderForm(payment.PaymentMethodId, orderGroup.Forms);
            IPayment      orderPayment   = orderForm.Payments.FirstOrDefault(x => x.PaymentMethodId == payment.PaymentMethodId);
            IOrderAddress billingAddress = orderPayment?.BillingAddress;

            if (billingAddress == null)
            {
                billingAddress = orderGroup.Forms.SelectMany(x => x.Payments)
                                 .FirstOrDefault(x => x.BillingAddress != null)?.BillingAddress;
            }

            return(billingAddress);
        }
        /// <summary>
        /// If current user is registered user, try to save the OrderAddress to its Contact.
        /// </summary>
        /// <param name="orderAddress">The modified order address.</param>
        /// <param name="customerAddressType">The customer address type.</param>
        private static void TrySaveCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            var httpProfile = HttpContext.Current.Profile;
            var profile     = httpProfile == null ? null : new CustomerProfileWrapper(httpProfile);

            if (profile == null || profile.IsAnonymous)
            {
                return;
            }

            // Add to contact address
            var customerContact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();

            if (customerContact != null)
            {
                var customerAddress = CustomerAddress.CreateForApplication();
                customerAddress.Name               = orderAddress.Id;
                customerAddress.AddressType        = customerAddressType;
                customerAddress.City               = orderAddress.City;
                customerAddress.CountryCode        = orderAddress.CountryCode;
                customerAddress.CountryName        = orderAddress.CountryName;
                customerAddress.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
                customerAddress.Email              = orderAddress.Email;
                customerAddress.EveningPhoneNumber = orderAddress.EveningPhoneNumber;
                customerAddress.FirstName          = orderAddress.FirstName;
                customerAddress.LastName           = orderAddress.LastName;
                customerAddress.Line1              = orderAddress.Line1;
                customerAddress.Line2              = orderAddress.Line2;
                customerAddress.PostalCode         = orderAddress.PostalCode;
                customerAddress.RegionName         = orderAddress.RegionName;
                customerAddress.RegionCode         = orderAddress.RegionCode;

#pragma warning disable 618
                if (customerContact.ContactAddresses == null || !IsAddressInCollection(customerContact.ContactAddresses, customerAddress))
#pragma warning restore 618
                {
                    // If there is an address has the same name with new address,
                    // rename new address by appending the index to the name.
                    var addressCount = customerContact.ContactAddresses.Count(a => a.Name == customerAddress.Name);
                    customerAddress.Name = $"{customerAddress.Name}{(addressCount == 0 ? string.Empty : "-" + addressCount.ToString())}";

                    customerContact.AddContactAddress(customerAddress);
                    customerContact.SaveChanges();
                }
            }
        }
 public void MapToAddress(AddressModel addressModel, IOrderAddress orderAddress)
 {
     orderAddress.Id = addressModel.Name;
     orderAddress.City = addressModel.City;
     orderAddress.CountryCode = addressModel.CountryCode;
     orderAddress.CountryName = _countryManager.GetCountries().Country.Where(x => x.Code == addressModel.CountryCode).Select(x => x.Name).FirstOrDefault();
     orderAddress.FirstName = addressModel.FirstName;
     orderAddress.LastName = addressModel.LastName;
     orderAddress.Line1 = addressModel.Line1;
     orderAddress.Line2 = addressModel.Line2;
     orderAddress.DaytimePhoneNumber = addressModel.DaytimePhoneNumber;
     orderAddress.PostalCode = addressModel.PostalCode;
     orderAddress.RegionName = addressModel.CountryRegion.Region;
     orderAddress.RegionCode = addressModel.CountryRegion.Region;
     orderAddress.Email = addressModel.Email;
     orderAddress.Organization = addressModel.Organization;
 }
 public void MapToModel(IOrderAddress orderAddress, AddressModel addressModel)
 {
     addressModel.Name = orderAddress.Id;
     addressModel.Line1 = orderAddress.Line1;
     addressModel.Line2 = orderAddress.Line2;
     addressModel.City = orderAddress.City;
     addressModel.CountryName = orderAddress.CountryName;
     addressModel.CountryCode = orderAddress.CountryCode;
     addressModel.Email = orderAddress.Email;
     addressModel.FirstName = orderAddress.FirstName;
     addressModel.LastName = orderAddress.LastName;
     addressModel.PostalCode = orderAddress.PostalCode;
     addressModel.CountryRegion = new CountryRegionViewModel
     {
         Region = orderAddress.RegionName ?? orderAddress.RegionCode
     };
     addressModel.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
 }
        public AddressModel ConvertToModel(IOrderAddress orderAddress)
        {
            var address = new AddressModel { AddressId = Guid.NewGuid().ToString() };

            if (orderAddress != null)
            {
                MapToModel(orderAddress, address);
            }

            return address;
        }
Example #36
0
 private CustomerAddress CreateCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum addressType)
 {
     var address = CustomerAddress.CreateInstance();
     address.Name = orderAddress.Id;
     address.AddressType = addressType;
     address.PostalCode = orderAddress.PostalCode;
     address.City = orderAddress.City;
     address.CountryCode = orderAddress.CountryCode;
     address.CountryName = orderAddress.CountryName;
     address.State = orderAddress.RegionName;
     address.Email = orderAddress.Email;
     address.FirstName = orderAddress.FirstName;
     address.LastName = orderAddress.LastName;
     address.Line1 = orderAddress.Line1;
     address.Line2 = orderAddress.Line2;
     address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
     address.EveningPhoneNumber = orderAddress.EveningPhoneNumber;
     address.RegionCode = orderAddress.RegionCode;
     address.RegionName = orderAddress.RegionName;
     return address;
 }