Example #1
0
 public PaymentModel(
     ApplicationDbContext ctx,
     CreateOrder createOrder,
     GetOrder getOrder,
     OneOffPayment payment)
 {
     _ctx         = ctx;
     _payment     = payment;
     _createOrder = createOrder;
     _getOrder    = getOrder;
 }
Example #2
0
 public CustomerDetailsModel(
     ApplicationDbContext ctx,
     OneOffPayment payment,
     SetCartAddress setCartAddress,
     CreateOrder createOrder,
     EmailSender emailSender)
 {
     _ctx            = ctx;
     _payment        = payment;
     _setCartAddress = setCartAddress;
     _createOrder    = createOrder;
     _emailSender    = emailSender;
 }
        public async Task <IActionResult> OnPostRequestPayment(
            [FromServices] OneOffPayment payment,
            [FromServices] CreateOrder createOrder)
        {
            var PaymentReference = Guid.NewGuid().ToString();

            var order = await createOrder.Do(new CreateOrder.Request
            {
                UserMark          = GetCartUserMark(),
                PayementReference = PaymentReference,
            });

            var totalValue = order.OrderProducts.Sum(x => x.Product.Price * x.Qty);

            var redirectUrl = payment.GetRedirectLink(new OneOffPayment.Request
            {
                BuyerEmail       = GetUserEmail(),
                PaymentReference = PaymentReference,
                TotalValue       = totalValue ?? 0m
            });

            var client = new SmtpClient(_config["Email:SMTP"], Convert.ToInt32(_config["Email:PORT"]))
            {
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(_config["Email:Username"], _config["Email:Password"])
            };

            var mailMessage = new MailMessage
            {
                To         = { Input.PayerEmail },
                Subject    = "Order Subject",
                Body       = $@"
<h1>Order Approval</h1>


<a href=""{redirectUrl}"">Approve Order Here</a>
",
                From       = new MailAddress(_config["Email:Username"]),
                IsBodyHtml = true
            };

            await client.SendMailAsync(mailMessage);

            return(RedirectToPage("/Checkout/Confirmation"));
        }
        public async Task <IActionResult> OnPostAsync(
            [FromServices] ApplicationDbContext ctx,
            [FromServices] UserManager <ApplicationUser> userManager,
            [FromServices] SignInManager <ApplicationUser> signInManager,
            [FromServices] OneOffPayment payment,
            [FromServices] SetCartAddress setCartAddress,
            [FromServices] CreateOrder createOrder)
        {
            if (!Input.RequestPayment)
            {
                ModelState.ClearValidationState("Input.PayerName");
                ModelState.ClearValidationState("Input.PayerEmail");
                ModelState.MarkFieldValid("Input.PayerName");
                ModelState.MarkFieldValid("Input.PayerEmail");
            }

            var user = new ApplicationUser
            {
                FirstName = Input.FirstName,
                LastName  = Input.LastName,
                UserName  = Input.Email,
                Email     = Input.Email
            };

            foreach (var item in userManager.PasswordValidators)
            {
                var password = await item.ValidateAsync(userManager, user, Input.Password);

                if (!password.Succeeded)
                {
                    foreach (var error in password.Errors)
                    {
                        ModelState.AddModelError("Input.Password", string.Format("[{0}] - {1}", error.Code, error.Description));
                    }
                }
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var address = new Address
            {
                Address1 = Input.Address1,
                Address2 = Input.Address2,
                City     = Input.City,
                PostCode = Input.PostCode,
            };

            user.Addresses.Add(address);

            var result = await userManager.CreateAsync(user, Input.Password);

            if (result.Succeeded)
            {
                await userManager.AddClaimAsync(user, new Claim("type", "superuser"));

                await signInManager.SignInAsync(user, false);

                await new CreateAccount(ctx, _emailSender)
                .Do(new CreateAccount.Request
                {
                    UserId = user.Id,
                    Input  = new CreateAccount.BusinessRegisterViewModel
                    {
                        CompanyName        = Input.CompanyName,
                        RegistrationNumber = "",
                        CompanyVAT         = "",
                        TermAccount        = false,
                        Address1           = Input.Address1,
                        Address2           = Input.Address2,
                        City     = Input.City,
                        PostCode = Input.PostCode,
                    }
                });

                await setCartAddress.Do(new SetCartAddress.Request
                {
                    UserMark  = GetCartUserMark(),
                    AddressId = address.Id
                });

                if (Input.RequestPayment)
                {
                    var PaymentReference = Guid.NewGuid().ToString();

                    var order = await createOrder.Do(new CreateOrder.Request
                    {
                        UserMark          = (user.Id, GetSessionId()),
                        PayementReference = PaymentReference,
                    });