public async Task <IActionResult> OnPostPay() { Couple = await GetAuthorizedCouple(); if (Couple == null) { return(NotFound()); } if (!Couple.Dinner.HasPrice) { return(BadRequest()); } PaymentStatus = await MollieAPI.GetPaymentStatus(Couple.PaymentId); switch (PaymentStatus) { case "paid": case "pending": ViewData["error"] = "Deze bestelling is al betaald."; return(Page()); } var response = await MollieAPI.PaymentRequest( new Payment() { Amount = new Amount(Currency.EUR, Couple.Dinner.Price), Description = "Betaling voor het dinner", RedirectUrl = ModelPath.GetAbsolutePathWithAuthorization <RedirectPaymentModel>(Request.Host, Couple.ID, Couple.AdminCode), } ); string link = response?.GetLink("checkout"); if (string.IsNullOrEmpty(link)) { ViewData["error"] = "De betaling kan nu niet worden gedaan. Probeer het later opnieuw."; return(Page()); } // Save the paymentId Couple.PaymentId = response.Id; await Database.SaveChangesAsync(); // Go to mollie return(Redirect(link)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // Strip seconds Dinner.Date = Dinner.Date.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0); Dinner.SubscriptionStop = Dinner.SubscriptionStop.SetTime(Dinner.Date.Hour, Dinner.Date.Minute, 0, 0); // Dont allow negative prices Dinner.Price = Math.Max(Dinner.Price, 0.0); if (Dinner.Date < DateTime.Now.AddDays(Dinner.MIN_DAYS_IN_ADVANCE).SetTime(0, 0)) { ModelState.AddModelError("Dinner.Date", $"Kies een datum minimaal { Dinner.MIN_DAYS_IN_ADVANCE } dagen in de toekomst."); return(Page()); } if ((Dinner.Date - Dinner.SubscriptionStop).TotalHours < 24) { ModelState.AddModelError("Dinner.SubscriptionStop", "Kies een tijd minimaal 24 uur vσσr het diner."); return(Page()); } if (Dinner.HasPrice && (string.IsNullOrWhiteSpace(Couple.IBAN))) { ModelState.AddModelError("Couple.IBAN", "Een bankrekening is verplicht als het evenement geld kost."); return(Page()); } if (await Database.CreateDinnerAsync(Dinner, Couple) == null) { ModelState.AddModelError(nameof(Dinner), "Kan dinner nu niet aanmaken."); return(Page()); } EmailServer.SendEmail(Couple.EmailAddress, "Nieuw dinner", $"Nieuw diner aangemaakt, code: <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Management.EditDinnerModel>( Request.Host, Couple.ID, Couple.AdminCode )}\">Beheer</a>"); return(Redirect(ModelPath.Get <AwaitEmailModel>())); }
public async Task <IActionResult> OnPostInvite() { Couple = await GetAuthorizedCouple(); if (Couple == null) { return(NotFound()); } if (!ModelState.IsValid(nameof(Invite))) { return(Page()); } Invite.EmailAddress = Invite.EmailAddress.ToLower(); // Load the dinner itself, including other couples await Database.GetDinnerAsync(Couple.Dinner.ID); foreach (Couple storedCouple in Couple.Dinner.Couples) { if (storedCouple.EmailAddress == Invite.EmailAddress) { ModelState.AddModelError(nameof(Invite), $"{ Invite.Person } met emailadres { Invite.EmailAddress } is al uitgenodigd."); return(Page()); } } // Invite Couple invitedCouple = await Database.CreateCoupleAsync(Couple.Dinner.ID, Invite.EmailAddress, Invite.Person); if (invitedCouple == null) { ModelState.AddModelError(nameof(Invite), $"Kan { Invite.Person } nu niet uitnodigen."); return(Page()); } EmailServer.SendEmail(invitedCouple.EmailAddress, "Uitnodiging", $"U ben uitgenodigd door { Couple.PersonMain } om deel te namen aan een WalkingDinner. Bekijk uit uitnodiging <a href=\"{ ModelPath.GetAbsolutePathWithAuthorization<Couples.SeeInvitationModel>( Request.Host, invitedCouple.ID, invitedCouple.AdminCode ) }\">Hier</a>"); ViewData["InviteResult"] = $"{ Invite.Person } is uitgenodigd."; // Clear input data ModelState.Clear(nameof(Invite)); Invite = null; return(Page()); }