public async Task <IActionResult> OnGet( [FromServices] IOptionsMonitor <StripeSettings> optionsMonitor, [FromServices] GetCart getCart, [FromServices] PaymentIntentService paymentIntentService) { var userId = User.GetUserId(); StripeConfiguration.ApiKey = optionsMonitor.CurrentValue.SecretKey; var cart = await getCart.ByUserId(userId); if (cart == null || cart.Products.Count <= 0) { return(RedirectToPage("/Index")); } var paymentIntent = await paymentIntentService.CreateAsync(new PaymentIntentCreateOptions { CaptureMethod = "manual", Amount = cart.Total(), Currency = "gbp", ReceiptEmail = cart.Email, Shipping = new ChargeShippingOptions { Name = cart.Name, Phone = cart.Phone, Address = new AddressOptions { Line1 = cart.Address1, Line2 = cart.Address2, City = cart.City, Country = cart.Country, PostalCode = cart.PostCode, State = cart.State, }, }, }); ClientSecret = paymentIntent.ClientSecret; return(Page()); }
public async Task <IActionResult> OnGet( [FromServices] GetCart getCart, [FromServices] IWebHostEnvironment env) { var userId = User.GetUserId(); var cart = await getCart.ByUserId(userId); if (cart.Products.Count <= 0) { return(RedirectToPage("/Index")); } Form = new CheckoutForm(); if (env.IsDevelopment()) { Form.Name = "test"; Form.Email = "*****@*****.**"; Form.Phone = "7845556789"; Form.Address1 = "Test"; Form.Address2 = ""; Form.City = "City"; Form.Country = "Country"; Form.PostCode = "QQ1 2RR"; Form.State = ""; } else if (cart.DeliveryInformationComplete) { Form.Name = cart.Name; Form.Email = cart.Email; Form.Phone = cart.Phone; Form.Address1 = cart.Address1; Form.Address2 = cart.Address2; Form.City = cart.City; Form.Country = cart.Country; Form.PostCode = cart.PostCode; Form.State = cart.State; } return(Page()); }