コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostCancel()
        {
            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":
                break;

            default:
                ViewData["error"] = "Er staat geen betaling open.";
                return(Page());
            }

            var refundResponse = await MollieAPI.CreateRefund(Couple.PaymentId, Couple.Dinner.Price);

            if (refundResponse == null)
            {
                ViewData["error"] = "Kan betaling nu niet annuleren. Probeer het later opnieuw.";
                return(Page());
            }

            Couple.PaymentId     = null;
            Couple.PaymentStatus = null;
            await Database.SaveChangesAsync();

            PaymentStatus      = null;
            ViewData["status"] = "Annulering is aangemaakt.";

            return(Page());
        }