コード例 #1
0
        public ActionResult Payment()
        {
            var model = ShoppingViewModelFactory.Create <PaymentMethodsViewModel>(PropertyBag);

            model.PaymentMethods = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
            {
                CustomerID = Identity.Current.CustomerID,
                ExcludeIncompleteMethods = true,
                ExcludeInvalidMethods    = true
            });
            model.Addresses = Exigo.GetCustomerAddresses(Identity.Current.CustomerID)
                              .Where(c => c.IsComplete)
                              .Select(c => c as ShippingAddress);

            ViewBag.HasAutoOrderItems = ShoppingCart.Items.Count(c => c.Type == ShoppingCartItemType.AutoOrder) > 0;

            return(View("Payment", model));
        }
コード例 #2
0
        public ActionResult ManageAddress(AddressType type)
        {
            var model = Exigo.GetCustomerAddresses(Identity.Current.CustomerID).Where(c => c.AddressType == type).FirstOrDefault();

            return(View("ManageAddress", model));
        }
コード例 #3
0
        public ActionResult AddressList()
        {
            var model = Exigo.GetCustomerAddresses(Identity.Current.CustomerID).Where(c => c.IsComplete).ToList();

            return(View(model));
        }
コード例 #4
0
        public ActionResult RenewSubscription(CreditCard creditcard)
        {
            var shipMethodID = OrderConfiguration.DefaultShipMethodID; // Will call or free option, since this is a virtual order
            var customerID   = CurrentCustomerID;
            var requests     = new List <ApiRequest>();
            var items        = new List <ShoppingCartItem>();
            var paymonthly   = true;
            var card         = new CreditCard();


            if (creditcard.Type != CreditCardType.New)
            {
                card = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
                {
                    CustomerID = Identity.Current.CustomerID,
                    ExcludeIncompleteMethods = true,
                    ExcludeInvalidMethods    = true
                }).Where(c => c is CreditCard && ((CreditCard)c).Type == creditcard.Type).FirstOrDefault().As <CreditCard>();
            }
            else
            {
                card = creditcard;
            }


            try
            {
                // Determine which items we need to add to the order we are creating and assemble our order request
                if (paymonthly)
                {
                    items.Add(new ShoppingCartItem {
                        ItemCode = GlobalSettings.Backoffices.MonthlySubscriptionItemCode, Quantity = 1
                    });
                }


                // We pull the customer's addresses first, if there are none we calculate with the corp address
                var customerAddresses = Exigo.GetCustomerAddresses(CurrentCustomerID);
                var address           = (customerAddresses.Count() > 0 && customerAddresses.Where(c => c.IsComplete).Count() > 0) ? customerAddresses.Where(c => c.IsComplete).FirstOrDefault().As <ShippingAddress>() : new ShippingAddress(GlobalSettings.Company.Address);


                var OrderRequest = new CreateOrderRequest(OrderConfiguration, shipMethodID, items, address)
                {
                    CustomerID = customerID
                };

                requests.Add(OrderRequest);

                // Then next step is adding the credit card payment and account update request
                if (!card.IsTestCreditCard && !Request.IsLocal)
                {
                    if (card.Type == CreditCardType.New)
                    {
                        requests.Add(new ChargeCreditCardTokenRequest(card));
                        requests.Add(new SetAccountCreditCardTokenRequest(card)
                        {
                            CustomerID = customerID, CreditCardAccountType = AccountCreditCardType.Primary
                        });
                    }
                    else
                    {
                        requests.Add(new ChargeCreditCardTokenOnFileRequest(card));
                    }
                }
                else
                {
                    OrderRequest.OrderStatus = OrderStatusType.Shipped;
                }

                // Process the transaction
                var transactionRequest = new TransactionalRequest();
                transactionRequest.TransactionRequests = requests.ToArray();
                var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest);

                if (transactionResponse.Result.Status != ResultStatus.Success)
                {
                    //throw new Exception(transactionResponse.Result.Errors.ToString());
                    throw new Exception("Transaction failed");
                }
                else
                {
                    var httpContext = System.Web.HttpContext.Current;
                    var cookie      = httpContext.Request.Cookies[GlobalSettings.Backoffices.MonthlySubscriptionCookieName];
                    if (cookie != null)
                    {
                        cookie.Expires = DateTime.Now.AddMinutes(30);
                        Response.Cookies.Set(cookie);
                    }
                    else
                    {
                        cookie         = new HttpCookie(GlobalSettings.Backoffices.MonthlySubscriptionCookieName);
                        cookie.Value   = "true";
                        cookie.Expires = DateTime.Now.AddMinutes(30);
                        Response.Cookies.Add(cookie);
                        httpContext.Response.Cookies.Add(cookie);
                        //Invalidate the customer subscription cache
                        HttpRuntime.Cache.Remove(string.Format("exigo.customersubscriptions.{0}-{1}", customerID, Subscriptions.BackofficeFeatures));
                    }
                }


                return(new JsonNetResult(new
                {
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }