示例#1
0
        public async Task <IActionResult> OnPost(string stripeEmail, string stripeToken)
        {
            var CartOrder       = new Application.Cart.GetOrder(HttpContext.Session, _ctx).Do();
            var customerOptions = new CustomerCreateOptions
            {
                Email  = stripeEmail,
                Source = stripeToken
            };
            var      customerService = new CustomerService();
            Customer customer        = customerService.Create(customerOptions);

            var chargeOptions = new ChargeCreateOptions
            {
                Customer    = customer.Id,
                Description = "Shop Purchase",
                Amount      = CartOrder.GetTotalCharge(),
                Currency    = "zar",
            };
            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeOptions);

            var sessionId = HttpContext.Session.Id;

            // Create order
            await new CreateOrder(_ctx).Do(new CreateOrder.Request
            {
                StripeReference = charge.OrderId,
                SessionId       = sessionId,

                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,
                    Quantity = x.Quantity
                }).ToList()
            });

            return(RedirectToPage("/Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPost(string stripeEmail, string stripeToken)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var CartOrder = new Application.Cart.GetOrder(HttpContext.Session, _ctx).Do();

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

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = CartOrder.GetTotalCharge(),
                Description = "Shop Purchase",
                Currency    = "brl",
                Customer    = customer.Id
            });

            var sessionId = HttpContext.Session.Id;

            await new CreateOrder(_ctx).Do(new CreateOrder.Request
            {
                StripeReference = charge.Id,
                SessionId       = sessionId,

                Name         = CartOrder.CustomerInformation.Name,
                Email        = CartOrder.CustomerInformation.Email,
                PhoneNumber  = CartOrder.CustomerInformation.PhoneNumber,
                Address      = CartOrder.CustomerInformation.Address,
                City         = CartOrder.CustomerInformation.City,
                Neighborhood = CartOrder.CustomerInformation.Neighborhood,
                State        = CartOrder.CustomerInformation.State,
                ZipCode      = CartOrder.CustomerInformation.ZipCode,

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

            return(RedirectToPage("/Index"));
        }
示例#3
0
        public async Task <IActionResult> OnPost(string stripeEmail, string stripeToken)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var CardOrder = new Application.Cart.GetOrder(HttpContext.Session, _context).Do();

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

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = CardOrder.GetTotalCharge(),
                Description = "Shop Purchase",
                Currency    = "gbp",
                Customer    = customer.Id
            });

            //create order
            await new CreateOrder(_context).Do(new CreateOrder.Request
            {
                StripeReference = charge.Id,
                FirstName       = CardOrder.CustomerInformation.FirstName,
                LastName        = CardOrder.CustomerInformation.LastName,
                PostCode        = CardOrder.CustomerInformation.PostCode,
                City            = CardOrder.CustomerInformation.City,
                Address1        = CardOrder.CustomerInformation.Address1,
                Address2        = CardOrder.CustomerInformation.Address2,
                Email           = CardOrder.CustomerInformation.Email,
                PhoneNumber     = CardOrder.CustomerInformation.PhoneNumber,

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

            return(RedirectToPage("/Index"));
        }
示例#4
0
        public async Task <IActionResult> OnPost(string stripeEmail, string stripeToken)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();

            var CartOrder = new Application.Cart.GetOrder(HttpContext.Session, _ctx).Do();

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

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

            var sessionId = HttpContext.Session.Id;

            await new CreateOrder(_ctx).Do(new CreateOrder.Request
            {
                StripeReference = charge.Id,
                SessionId       = sessionId,

                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()
            });

            HttpContext.Session.SetString("cart", string.Empty);

            new SendOrderInfo().Do(new SendOrderInfo.Request
            {
                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 SendOrderInfo.Stock
                {
                    Id          = x.StockId,
                    Description = _ctx.Stock.Where(y => y.Id == x.StockId).Select(y => y.Description).FirstOrDefault(),
                    Qty         = x.Qty,
                    ProductId   = x.ProductId,
                    Product     = _ctx.Products.Where(y => y.Id == x.ProductId).FirstOrDefault()
                })
                         .ToList()
            });

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