Example #1
0
        public async Task <IActionResult> OnPost(
            [FromServices] GetOrderCart getOrder,
            [FromServices] CreateOrder createOrder,
            [FromServices] ISessionManager sessionManager)
        {
            var CartOrder = getOrder.Do();

            //creat order  //move it to CutomerInfo when u want to pay in 2stlsam

            var sessionId = HttpContext.Session.Id;


            await createOrder.Do(new CreateOrder.Request
            {
                SessionId   = sessionId,
                FirstName   = CartOrder.CustomerInfo.FirstName,
                LastName    = CartOrder.CustomerInfo.LastName,
                Email       = CartOrder.CustomerInfo.Email,
                PhoneNumber = CartOrder.CustomerInfo.PhoneNumber,
                City        = CartOrder.CustomerInfo.City,
                Address1    = CartOrder.CustomerInfo.Address1,
                Address2    = CartOrder.CustomerInfo.Address2,

                Stocks = CartOrder.Products.Select(s => new CreateOrder.Stock
                {
                    StockId = s.StockId,
                    Qty     = s.Qty
                }).ToList()
            });

            // HttpContext.Session.Remove();//clear the cart after sucses payment
            sessionManager.CleanCart();
            //TODO Send sucsess msg
            return(RedirectToPage("/index"));
        }
        public async Task <IActionResult> OnPost(string stripeEmail, string stripeToken,
                                                 [FromServices] GetOrderCart getOrder,
                                                 [FromServices] CreateOrder createOrder,
                                                 [FromServices] ISessionManager sessionManager)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var CartOrder = getOrder.Do();

            var customer = customers.Create(new CustomerCreateOptions
            {
                Email  = stripeEmail,
                Source = stripeToken,
            });

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = CartOrder.GetCharge(),
                Description = "Purchases",
                Currency    = "usd",
                Customer    = customer.Id
            });
            //creat order  //move it to CutomerInfo when u want to pay in 2stlsam

            var sessionId = HttpContext.Session.Id;


            await createOrder.Do(new CreateOrder.Request
            {
                StripeRef = charge.Id,

                SessionId = sessionId,

                FirstName   = CartOrder.CustomerInfo.FirstName,
                LastName    = CartOrder.CustomerInfo.LastName,
                Email       = CartOrder.CustomerInfo.Email,
                PhoneNumber = CartOrder.CustomerInfo.PhoneNumber,
                City        = CartOrder.CustomerInfo.City,
                Address1    = CartOrder.CustomerInfo.Address1,
                Address2    = CartOrder.CustomerInfo.Address2,

                Stocks = CartOrder.Products.Select(s => new CreateOrder.Stock
                {
                    StockId = s.StockId,
                    Qty     = s.Qty
                }).ToList()
            });

            // HttpContext.Session.Remove();//clear the cart after sucses payment
            sessionManager.CleanCart();
            //TODO Send sucsess msg
            return(RedirectToPage("/index"));
        }
        public async Task <IActionResult> OnPost(
            string stripeEmail,
            string stripeToken,
            [FromServices] GetOrderCart getOrder,
            [FromServices] CreateOrder createOrder,
            [FromServices] ISessionManager sessionManager)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var cartOrder = getOrder.Do();

            var customer = customers.Create(new CustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = cartOrder.GetTotalCharger(),
                Description = "Shop Purchase",
                Currency    = "gbp",
                CustomerId  = customer.Id
            });

            var sessionId = HttpContext.Session.Id;

            await createOrder.Do(new CreateOrder.Request
            {
                StripeReference = charge.Id,

                FirstName   = cartOrder.CustomerInformation.FirstName,
                LastName    = cartOrder.CustomerInformation.LastName,
                Email       = cartOrder.CustomerInformation.Email,
                PhoneNumber = cartOrder.CustomerInformation.PhoneNumber,
                Address1    = cartOrder.CustomerInformation.Address1,
                Address2    = cartOrder.CustomerInformation.Address2,
                City        = cartOrder.CustomerInformation.City,
                PostCode    = cartOrder.CustomerInformation.PostCode,

                Stocks = cartOrder.Products.Select(x => new CreateOrder.Stock
                {
                    StockId = x.StockId,
                    Qty     = x.Qty
                }).ToList()
            });


            sessionManager.CleanCart();

            return(RedirectToPage("/Index"));
        }