示例#1
0
 public static void GetRegistrationDropDownLists(ref OrderViewModel viewModel)
 {
     viewModel.ProvModel = RegisterLists.ProvList();
     viewModel.CountryModel = RegisterLists.CountryList();
     viewModel.CreditCardType = RegisterLists.CreditCardTypeList();
     viewModel.ExpiryYearList = RegisterLists.ExpiryYearList();
     viewModel.ExpiryMonthList = RegisterLists.ExpiryMonthList();
 }
示例#2
0
        public NvpCodec DirectPayment(OrderViewModel orderViewModel, ref NvpCodec decoder, ref string retMsg)
        {
            if (_env == "pilot")
            {
                _pendpointurl = "https://pilot-payflowpro.paypal.com";
            }

            var encoder = new NvpCodec();
            encoder["TENDER"] = "C";
            encoder["TRXTYPE"] = "S";
            encoder["ACCT"] = orderViewModel.CreditCardNumber;
            //encoder["CVV2"] = createOrderViewModel.Cvv2;
            encoder["EXPDATE"] = orderViewModel.ExpDate;
            encoder["ACCTTYPE"] = orderViewModel.PaymentOption;
            encoder["AMT"] = orderViewModel.Amt.ToString("c");
            encoder["CURRENCY"] = _currencyCode;
            encoder["FIRSTNAME"] = orderViewModel.FirstNameCreditCard;
            encoder["LASTNAME"] = orderViewModel.LastNameCreditCard;
            encoder["STREET"] = orderViewModel.CcAddress1;
            encoder["CITY"] = orderViewModel.CcCity;
            //encoder["STATE"] = createOrderViewModel.CcAddress2.ToUpper();
            encoder["ZIP"] = orderViewModel.CcPostalCode;
            encoder["COUNTRY"] = orderViewModel.CountryCode;

            // unique request ID
            Guid uid = Guid.NewGuid();
            encoder["INVNUM"] = uid.ToString();
            //encoder["ORDERDESC"] = createOrderViewModel.CourseName;
            encoder["VERBOSITY"] = "MEDIUM";
            encoder["Email"] = orderViewModel.Email;

            //encoder["COMMENT1"] = createOrderViewModel.TransactionDateTimeUtc.ToString("yyyy-MM-dd HH:mm:ss") + "-" + createOrderViewModel.CourseName;
            //encoder["COMMENT2"] = "elearning-" + createOrderViewModel.Organization;

            //Roger Code - Do I need to generate a token each time?
            //var token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            //encoder["SECURETOKENID"] = token;
            //encoder["CREATESECURETOKEN"] = "Y";

            var pStrrequestforNvp = encoder.Encode();
            var pStresponsenvp = HttpCall(pStrrequestforNvp, uid.ToString());

            if (String.IsNullOrEmpty(pStresponsenvp))
                return null;

            decoder = new NvpCodec();
            decoder.Decode(pStresponsenvp);

            

            return decoder;

        }
示例#3
0
        public static OperationResult<bool> ProcessPaymentOrPromo(ref OrderViewModel viewModel)
        {
            var operationResult = new OperationResult<bool>();
            if (viewModel.Amt == 0)
            {
                viewModel.ConfirmationCode = "PROMO";
                viewModel.Ppref = "PROMO";
                viewModel.CorrelationId = "PROMO";
                viewModel.Tax1Amount = 0;
                operationResult.Result = true;
                operationResult.Message = "Promo Accepted";

            }
            else
            {
                //process Paypal Payment
                var amtBeforeTaxes = viewModel.Cart.CalculateOrderTotal();
                viewModel.Tax1Amount = amtBeforeTaxes*viewModel.Tax1Rate/100;

                var nvpapiCaller = new NvpApiCaller();

                viewModel.CurrencyCode = "CAD";
                viewModel.PaymentType = "Sale";

                viewModel.ExpDate = viewModel.ExpiryMonthCreditCard + viewModel.ExpiryYearCreditCard.Substring(2, 2);

                string retMsg = "";

                var decoder = new NvpCodec();

                //Submit Payment to PayPal
                nvpapiCaller.DirectPayment(viewModel, ref decoder, ref retMsg);

                var processorReturnCode = decoder["RESULT"].ToLower();
                if (processorReturnCode == "0")
                {
                    //Get confirmation code from PayPal
                    viewModel.ConfirmationCode = decoder["PNREF"];
                    viewModel.Ppref = decoder["PPREF"];
                    viewModel.CorrelationId = decoder["CORRELATIONID"];
                    retMsg = "ErrorCode=" + processorReturnCode + "&" + "Desc=" + decoder["RESPMSG"];
                    operationResult.Result = true;
                    operationResult.Message = "Payment Accepted by PayPal";

                }


            }
            return operationResult;
        }
示例#4
0
 public static ApplicationUser AddRegistrantAsUser(OrderViewModel viewModel, ApplicationDbContext context)
 {
     var user = new ApplicationUser
     {
         FirstName = viewModel.FirstName,
         LastName = viewModel.LastName,
         Address1 = viewModel.Address1,
         //Address2 = viewModel.Address2,
         City = viewModel.City,
         CountryCode = viewModel.CountryCode,
         PostalCode = viewModel.PostalCode,
         Email = viewModel.Email,
         UserName = viewModel.Email,
         Phone = viewModel.Phone,
         //Gender = viewModel.Gender
     };
     return user;
 }
        public async Task<ActionResult> CompleteOrder(OrderViewModel viewModel)
        {
            // Check that unauthenticated registrant not in system
            if (!Request.IsAuthenticated && _userManager.FindByEmail(viewModel.Email) != null)
            {
                CheckOutServices.GetRegistrationDropDownLists(ref viewModel);
                ModelState.AddModelError("userInSystem", "A person with this email address is already in system.  Please log in to order.");
                return View(viewModel);
            }

            //Get Purchaser Object
            var purchaser = Request.IsAuthenticated ? _userManager.FindById(User.Identity.GetUserId()) : CheckOutServices.AddRegistrantAsUser(viewModel, _context);

            //Submit payment or Validate Promo Code
            var operationResult = CheckOutServices.ProcessPaymentOrPromo(ref viewModel);

            if (operationResult.Result)
            {
                //Save User data to Db if new or changed;
                if (!Request.IsAuthenticated)
                {
                    var result = await _userManager.CreateAsync(purchaser, viewModel.Password);
                    if (result.Succeeded)
                    {
                        if (ModelState.IsValid)
                        {
                            await SignInManager.SignInAsync(purchaser, isPersistent: false, rememberBrowser: false);
                            
                            UserComputer.UpdateUserComputerInfo(purchaser, _userManager);

                            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                            // Send an email with this link
                            // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                            // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                            // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                            //return View("~/Views/Courses/Board.cshtml/" + purchaser.Id);
                        }
                        else
                        {
                            AddErrors(result);
                            return View("~/Views/Checkout/CompleteOrder.cshtml", viewModel);
                        }
                    }
                    else
                    {
                        AddErrors(result);
                        return View("~/Views/Checkout/CompleteOrder.cshtml", viewModel);
                    }
                    
                }

                //We have an authenticated Purchaser at this point
                viewModel.UserName = purchaser.UserName;

                var order = CheckOutServices.AddOrder(viewModel, _context);
                ShoppingCart.GetCart(HttpContext).ProcessOrderDetails(order);

                return RedirectToAction("ConfirmPurchase", "CheckOut", new { id = order.OrderId });
            }

            return View(viewModel);
        }
        private OrderViewModel CreateOrderViewModel(decimal amtBeforeTaxes, ShoppingCart cart)
        {
            var viewModel = new OrderViewModel();
            {
                viewModel.ProvModel = RegisterLists.ProvList();
                viewModel.CountryModel = RegisterLists.CountryList();
                viewModel.CreditCardType = RegisterLists.CreditCardTypeList();
                viewModel.ExpiryYearList = RegisterLists.ExpiryYearList();
                viewModel.ExpiryMonthList = RegisterLists.ExpiryMonthList();


                if (User.Identity.IsAuthenticated)
                {
                    var currentUserId = User.Identity.GetUserId();
                    var currentUser = _context.Users.FirstOrDefault(x => x.Id == currentUserId);
                    CheckOutServices.PopulateViewModelWithRegisteredUserData(ref viewModel, currentUser);
                }


                if (amtBeforeTaxes == 0)
                    viewModel.IsPromo = true;

                if (viewModel.IsPromo)
                {
                    viewModel.CreditCardNumber = "4024007108173500";
                    viewModel.ExpiryMonthCreditCard = "04";
                    viewModel.ExpiryYearCreditCard = "2020";
                    viewModel.FirstNameCreditCard = "xxxxxx";
                    viewModel.LastNameCreditCard = "xxxxxx";
                }

                viewModel.CurrencyCode = _currencyCode;
                viewModel.PaymentType = "Sale";
                viewModel.Tax1Rate = _tax1Rate;
                viewModel.Tax1Name = _tax1Name;

                viewModel.Cart = cart;
            }
            return viewModel;
        }
示例#7
0
        public static void PopulateViewModelWithRegisteredUserData(ref OrderViewModel viewModel, ApplicationUser currentUser)
        {
            // ReSharper disable once PossibleNullReferenceException
            viewModel.FirstName = currentUser.FirstName;
            viewModel.LastName = currentUser.LastName;
            //viewModel.Gender = currentUser.Gender;

            viewModel.Address1 = currentUser.Address1;
            viewModel.City = currentUser.City;
            viewModel.ProvCode = currentUser.ProvCode;
            viewModel.CountryCode = currentUser.CountryCode;
            viewModel.PostalCode = currentUser.PostalCode;
            //viewModel.Phone = currentUser.Phone;

            viewModel.ProvModel = RegisterLists.ProvList();
            viewModel.CountryModel = RegisterLists.CountryList();
            viewModel.Email = currentUser.Email;
            viewModel.UserName = currentUser.UserName;

            viewModel.CcAddress1 = currentUser.Address1;
            //viewModel.CcAddress2 = currentUser.Address2;
            viewModel.CcCity = currentUser.City;
            viewModel.CcPostalCode = currentUser.PostalCode;

            viewModel.FirstNameCreditCard = currentUser.FirstName;
            viewModel.LastNameCreditCard = currentUser.LastName;

            viewModel.Password = "******";
            viewModel.ConfirmPassword = "******";
        }
示例#8
0
        public static  Order AddOrder(OrderViewModel vm, ApplicationDbContext context)
        {
            var order = new Order
            {
                ConfirmationCode = vm.ConfirmationCode,
                Ppref = vm.Ppref,
                Correlationid = vm.CorrelationId,
                PaymentType = vm.PaymentOption,
                UserName = vm.UserName,
                FirstName = vm.FirstName,
                LastName = vm.LastName,
                City = vm.City,
                Country = vm.CountryCode,
                PostalCode = vm.PostalCode,
                OrderDate = DateTime.UtcNow,
                Total = vm.Amt,
                Phone = vm.Phone,
                Email = vm.Email,
                Tax1Amount = vm.Tax1Amount,
                Tax1Name = vm.Tax1Name,

            };

            context.Orders.Add(order);
            try
            {
                context.SaveChanges(); //This gets the orderId that we use to for Order details table
            }
            catch (DbEntityValidationException e)
            {
                foreach (var error in e.EntityValidationErrors)
                {
                    Console.WriteLine(@"Entity of Type ""{0}"" in state ""{1}"" has the following errors:",
                        error.Entry.Entity.GetType().Name,
                        error.Entry.State);
                    foreach (var ve in error.ValidationErrors)
                    {
                        Console.WriteLine(@"-Property: '{0}', Error: '{1}", ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }

            return order;
        }