public ActionResult CheckOut()
        {
            var shoppingCartId = GetShoppingCartId();
            if (!shoppingCartId.HasValue)
            {
                Response.Redirect(Url.Action("ViewRDNStore"));
                return null;
            }

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

            var checkoutObject = new CheckOut();
            checkoutObject.MerchantId = checkout.MerchantId;
            checkoutObject.ShoppingCart = checkout.ShoppingCart;
            checkoutObject.Tax = checkout.Tax;
            checkoutObject.TaxRate = checkout.TaxRate;
            checkoutObject.TotalExclVat = checkout.TotalExclVat;
            checkoutObject.TotalInclVat = checkout.TotalInclVat;
            checkoutObject.Currency = checkout.Currency;
        
                checkoutObject.Currency =checkout.Currency;
                checkoutObject.CurrencyCost =checkout.CurrencyCost;
        
            checkoutObject.ShippingOptions =
                checkout.ShippingOptionsRaw.Select(
                    x => new SelectListItem
                    {
                        Selected = false,
                        Text = string.Format("{0} {1} {2}", x.Value.Name.ToString(), x.Value.Price, checkoutObject.Currency),
                        Value = x.Key.ToString()
                    }).ToList();
            checkoutObject.ShippingOptions[0].Selected = true;

            var paymentProviders = Enum.GetNames(typeof(PaymentProvider));
            checkoutObject.PaymentProviders = paymentProviders.Select(x => new SelectListItem { Selected = false, Text = x, Value = x }).ToList();
            checkoutObject.PaymentProviders[0].Selected = true;
            checkout.ShippingAddress = new StoreShoppingCartContactInfo();
            checkout.BillingAddress = new StoreShoppingCartContactInfo();
            return View(checkoutObject);
        }
        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);
        }