public DisplayInvoice()
 {
     Refunds = new List<InvoiceRefund>();
     Merchant = new OverviewMerchant();
     InvoiceItems = new List<InvoiceItem>();
     InvoiceShipping = new InvoiceContactInfo();
     InvoiceBilling = new InvoiceContactInfo();
     SellersAddress = new InvoiceContactInfo();
 }
        public ActionResult CheckOut(RDN.Store.Models.CheckOut model)
        {
            try
            {
                var shoppingCartId = StoreGateway.GetShoppingCartId(HttpContext);
                if (!shoppingCartId.HasValue)
                {

                    return Redirect(Url.Action("StoreCart"));
                }

                var sg = new StoreGateway();
                var checkout = sg.GetCheckoutData(shoppingCartId.Value, model.MerchantId);
                if (checkout == null || checkout.ShoppingCart.ItemsCount == 0)
                {
                    return Redirect(Url.Action("StoreCart"));

                }

                PaymentProvider paymentProvider;
                if (!Enum.TryParse(model.PaymentProviderId, out paymentProvider))
                {
                    return Redirect(Url.Action("StoreCart"));

                }

                var pg = new PaymentGateway();

                ShippingType shipType = ShippingType.Postal;
                if (checkout.WillPickUpAtStore)
                    shipType = ShippingType.PickUp;

                var invoice = pg.StartInvoiceWizard()
                    .Initalize(checkout.MerchantId, checkout.Currency, paymentProvider, PaymentMode.Live, ChargeTypeEnum.InStorePurchase)
                    .SetShipping(checkout.TotalShipping, shipType)
                    .SetInvoiceId(Guid.NewGuid())
                    .SetNotes(model.Notes)
                    .SetUserId(RDN.Library.Classes.Account.User.GetUserId())
                    .SetShoppingCartId(shoppingCartId.Value);


                if (paymentProvider == PaymentProvider.Stripe)
                {
                    string token = Request.Form["stripeToken"].ToString();
                    invoice.SetStripeTokenId(token);
                }
                var sellersAddress = new InvoiceContactInfo();
                if (shipType == ShippingType.PickUp)
                {
                    if (checkout.SellersAddress != null)
                    {
                        sellersAddress.City = checkout.SellersAddress.City;
                        sellersAddress.Country = checkout.SellersAddress.Country;
                        sellersAddress.CompanyName = checkout.SellersAddress.CompanyName;
                        sellersAddress.State = checkout.SellersAddress.State;
                        sellersAddress.Street = checkout.SellersAddress.Street;
                        sellersAddress.Street2 = checkout.SellersAddress.Street2;
                        sellersAddress.Zip = checkout.SellersAddress.Zip;
                        invoice.SetSellersAddress(sellersAddress);
                    }
                }

                var billingInfo = new InvoiceContactInfo();
                billingInfo.City = model.BillingAddress_City;
                billingInfo.Country = model.BillingAddress_Country;
                billingInfo.Email = model.BillingAddress_Email;
                billingInfo.FirstName = model.BillingAddress_FirstName;
                billingInfo.LastName = model.BillingAddress_LastName;
                billingInfo.Phone = model.BillingAddress_Phone;
                billingInfo.State = model.BillingAddress_State;
                billingInfo.Street = model.BillingAddress_Street;
                billingInfo.Street2 = model.BillingAddress_Street2;
                billingInfo.Zip = model.BillingAddress_Zip;
                if (User.Identity.IsAuthenticated)
                    RDN.Library.Classes.Account.User.AddContactToMember(RDN.Library.Classes.Account.User.GetMemberId(), billingInfo, AddressTypeEnum.Billing);
                if (model.IsBillingDifferentFromShipping)
                {
                    var shippingInfo = new InvoiceContactInfo();
                    shippingInfo.City = model.ShippingAddress_City;
                    shippingInfo.Country = model.ShippingAddress_Country;
                    shippingInfo.Email = model.ShippingAddress_Email;
                    shippingInfo.FirstName = model.ShippingAddress_FirstName;
                    shippingInfo.LastName = model.ShippingAddress_LastName;
                    shippingInfo.Phone = model.ShippingAddress_Phone;
                    shippingInfo.State = model.ShippingAddress_State;
                    shippingInfo.Street = model.ShippingAddress_Street;
                    shippingInfo.Street2 = model.ShippingAddress_Street2;
                    shippingInfo.Zip = model.ShippingAddress_Zip;
                    invoice.SetInvoiceContactData(billingInfo, shippingInfo);

                    if (User.Identity.IsAuthenticated)
                        RDN.Library.Classes.Account.User.AddContactToMember(RDN.Library.Classes.Account.User.GetMemberId(), shippingInfo, AddressTypeEnum.Shipping);

                }
                else
                    invoice.SetInvoiceContactData(billingInfo, billingInfo);


                foreach (var cartitem in checkout.ShoppingCart.Stores.FirstOrDefault().StoreItems)
                {
                    var item = new InvoiceItem();
                    item.ArticleNumber = cartitem.ArticleNumber;
                    item.Article2Number = cartitem.Article2Number;
                    item.Description = "Tax Included in Price: " + cartitem.Description;
                    item.Name = cartitem.Name;
                    item.BasePrice = cartitem.BasePrice + cartitem.BaseTaxOnItem;
                    item.Price = cartitem.Price;
                    item.TotalShipping = cartitem.Shipping;
                    item.Quantity = cartitem.QuantityOrdered;
                    item.Weight = cartitem.Weight;
                    item.SizeOfItem = cartitem.ItemSizeEnum;
                    item.ColorOfItem = cartitem.ColorAGB;
                    item.StoreItemId = cartitem.StoreItemId;
                    invoice.AddItemTaxIncluded(item);
                }

                var requestResponse = invoice.FinalizeInvoice();
                if (requestResponse.Error != null)
                    throw new Exception(requestResponse.Error);

                this.ClearCart(HttpContext.Session);

                if (requestResponse.Status == InvoiceStatus.Payment_Successful)
                    return Redirect(Url.Content("~/receipt/" + requestResponse.InvoiceId.ToString().Replace("-", "")));
                else if (requestResponse.Status == InvoiceStatus.Pending_Payment_From_Paypal)
                    return Redirect(requestResponse.RedirectLink);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
Beispiel #3
0
        /// <summary>
        /// adds billing information to the member contact information.
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        public static bool AddContactToMember(Guid memberId, InvoiceContactInfo contact, AddressTypeEnum type)
        {
            try
            {
                var dc = new ManagementContext();
                int country = Convert.ToInt32(contact.Country);
                var mem = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
                if (mem.ContactCard != null && mem.ContactCard.Addresses.Count > 0)
                {
                    bool addAddress = true;
                    foreach (var address in mem.ContactCard.Addresses)
                    {
                        //checking if address exists.
                        if (address.Address1 == contact.Street && address.Address2 == contact.Street2 && address.Zip == contact.Zip)
                            addAddress = false;
                    }
                    if (addAddress)
                    {
                        ContactCard.ContactCardFactory.AddAddressToContact(contact.Street, contact.Street2, contact.City, contact.State, contact.Zip, type, mem.ContactCard, dc.Countries.Where(x => x.CountryId == country).FirstOrDefault());
                    }
                }
                else if (mem.ContactCard != null && mem.ContactCard.Addresses.Count == 0)
                {

                    ContactCard.ContactCardFactory.AddAddressToContact(contact.Street, contact.Street2, contact.City, contact.State, contact.Zip, type, mem.ContactCard, dc.Countries.Where(x => x.CountryId == country).FirstOrDefault());
                }
                else if (mem.ContactCard == null)
                {

                    mem.ContactCard = new DataModels.ContactCard.ContactCard();
                    ContactCard.ContactCardFactory.AddAddressToContact(contact.Street, contact.Street2, contact.City, contact.State, contact.Zip, type, mem.ContactCard, dc.Countries.Where(x => x.CountryId == country).FirstOrDefault());

                }
                int c = dc.SaveChanges();
                return c > 0;
            }
            catch (Exception e)
            {
                ErrorDatabaseManager.AddException(e, e.GetType(), errorGroup: ErrorGroupEnum.Database);
            }
            return false;
        }
 public InvoiceFactory SetSellersAddress(InvoiceContactInfo sellersAddress)
 {
     invoice.SellersAddress = sellersAddress;
     return this;
 }
 public InvoiceFactory SetInvoiceContactData(InvoiceContactInfo invoiceBillingContactInfo = null, InvoiceContactInfo invoiceShippingContactInfo = null)
 {
     invoice.InvoiceShipping = invoiceShippingContactInfo;
     invoice.InvoiceBilling = invoiceBillingContactInfo;
     return this;
 }
 private DataModels.PaymentGateway.Invoices.InvoiceContactInfo ConvertInvoiceContactToDbInvoiceContact(InvoiceContactInfo invoiceContact)
 {
     // If not null then turn a class contact info to a db contact info
     if (invoiceContact == null) return null;
     var output = new DataModels.PaymentGateway.Invoices.InvoiceContactInfo();
     try
     {
         output.CompanyName = invoiceContact.CompanyName;
         output.Country = invoiceContact.Country;
         output.FirstName = invoiceContact.FirstName;
         output.LastName = invoiceContact.LastName;
         output.State = invoiceContact.State;
         output.StateCode = invoiceContact.StateCode;
         output.Street = invoiceContact.Street;
         output.Street2 = invoiceContact.Street2;
         output.City = invoiceContact.City;
         output.Zip = invoiceContact.Zip;
         output.Email = invoiceContact.Email;
         output.Phone = invoiceContact.Phone;
         output.Fax = invoiceContact.Fax;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return output;
 }
        public void CheckOut(CheckOut model)
        {
            var shoppingCartId = GetShoppingCartId();
            if (!shoppingCartId.HasValue)
            {
                Response.Redirect(Url.Action("ViewRDNStore"));
                return;
            }

            var sg = new StoreGateway();
            var checkout = sg.GetCheckoutData(shoppingCartId.Value, new Guid());
            if (checkout == null || checkout.ShoppingCart.ItemsCount == 0)
            {
                Response.Redirect(Url.Action("ViewRDNStore"));
                return;
            }

            PaymentProvider paymentProvider;
            if (!Enum.TryParse(model.PaymentProviderId, out paymentProvider))
            {
                Response.Redirect(Url.Action("ViewRDNStore"));
                return;
            }
            int shippingId;
            if (!Int32.TryParse(model.ShippingOptionSelectedId, out shippingId))
            {
                Response.Redirect(Url.Action("ViewRDNStore"));
                return;
            }

            var pg = new PaymentGateway();

            var invoice = pg.StartInvoiceWizard()
                .Initalize(checkout.MerchantId, checkout.Currency, paymentProvider, PaymentMode.Live, ChargeTypeEnum.InvoiceItem)
                .SetShipping(checkout.TotalShipping, ShippingType.Postal)
                .SetInvoiceId(checkout.ShoppingCart.ShoppingCartId);

            var billingInfo = new InvoiceContactInfo();
            billingInfo.City = model.BillingAddress.City;
            billingInfo.CompanyName = model.BillingAddress.CompanyName;
            billingInfo.Country = model.BillingAddress.Country;
            billingInfo.Email = model.BillingAddress.Email;
            billingInfo.Fax = model.BillingAddress.Fax;
            billingInfo.FirstName = model.BillingAddress.FirstName;
            billingInfo.LastName = model.BillingAddress.LastName;
            billingInfo.Phone = model.BillingAddress.Phone;
            billingInfo.State = model.BillingAddress.State;
            billingInfo.Street = model.BillingAddress.Street;
            billingInfo.Street2 = model.BillingAddress.Street2;
            billingInfo.Zip = model.BillingAddress.Zip;

            var shippingInfo = new InvoiceContactInfo();
            shippingInfo.City = model.ShippingAddress.City;
            shippingInfo.CompanyName = model.ShippingAddress.CompanyName;
            shippingInfo.Country = model.ShippingAddress.Country;
            shippingInfo.Email = model.ShippingAddress.Email;
            shippingInfo.Fax = model.ShippingAddress.Fax;
            shippingInfo.FirstName = model.ShippingAddress.FirstName;
            shippingInfo.LastName = model.ShippingAddress.LastName;
            shippingInfo.Phone = model.ShippingAddress.Phone;
            shippingInfo.State = model.ShippingAddress.State;
            shippingInfo.Street = model.ShippingAddress.Street;
            shippingInfo.Street2 = model.ShippingAddress.Street2;
            shippingInfo.Zip = model.ShippingAddress.Zip;
            invoice.SetInvoiceContactData(billingInfo, shippingInfo);

            //foreach (var cartitem in checkout.ShoppingCart.Items)
            //{
            //    var item = new InvoiceItem();
            //    item.ArticleNumber = cartitem.ArticleNumber;
            //    item.Article2Number = cartitem.Article2Number;
            //    item.Description = cartitem.Description;
            //    item.Name = cartitem.Name;
            //    item.BasePrice = cartitem.BasePrice;
            //    item.Price = cartitem.Price;
            //    item.Quantity = cartitem.QuantityOrdered;
            //    item.Weight = cartitem.Weight;
            //    invoice.AddItem(item);
            //}

            invoice.SetTax(checkout.TaxRate);

            var requestResponse = invoice.FinalizeInvoice();
            if (requestResponse.Error != null)
                throw new Exception(requestResponse.Error);

            Response.Redirect(requestResponse.RedirectLink);
        }