Example #1
0
        public async Task <ActionResult> Feedback(string guid = "")
        {
            var             payRes  = new PaymentResponseViewModel();
            var             userId  = Functions.User.GetUserId();
            var             user    = _db.AspNetUsers.FirstOrDefault(w => w.Id == userId);
            PaymentResponse payment = await _paymentClient.GetPaymentAsync(user.UniquePaymentReference);

            if (user.PassThrougReference == guid && user.UniquePaymentReference == payment.Id)
            {
                switch (payment.Status)
                {
                case Mollie.Api.Models.Payment.PaymentStatus.Paid:
                    //This is our happy path, everything went well, show a successmessage to the user.
                    Subscription subscription = new Subscription()
                    {
                        UserId           = Functions.User.GetUserId(),
                        Number           = 10,
                        DatePurchased    = DateTime.Now,
                        PaymentReference = payment.Id,
                        PaymentMethod    = payment.Method.ToString()
                    };
                    Subscriptions.AddSubscription(_db, subscription, Server.MapPath("~\\MailTemplates\\BetalingOntvangen.html"));
                    await _db.SaveChangesAsync();

                    //update user to avoid double subscriptions!
                    var userToUpdate = _db.AspNetUsers.FirstOrDefault(w => w.Id == userId);
                    userToUpdate.UniquePaymentReference = "";
                    userToUpdate.PassThrougReference    = "";
                    await _db.SaveChangesAsync();

                    payRes.PassThroughId    = guid;
                    payRes.PaymentSucceeded = true;
                    payRes.PaymentReference = user.UniquePaymentReference;
                    payRes.SuccessMessage   = "Proficiat, uw betaling is geslaagd! U hebt nu 10 lessen beschikbaar!";
                    break;

                case Mollie.Api.Models.Payment.PaymentStatus.Open:
                    payRes.ErrorMessage = "Payment is still open, we have to reconnect to mollie";
                    //The payment hasn't started yet, try to relaunch the link to mollie here;
                    break;

                case Mollie.Api.Models.Payment.PaymentStatus.Pending:
                    payRes.ErrorMessage = "Payment is started, just wait a little...";
                    //The payment has started, wait for it.
                    break;

                default:
                    //The payment isn't paid, pending or open, we assume it's aborted: propose some actions here
                    payRes.ErrorMessage = "Er is helaas iets misgelopen, klik op onderstaande knop om opnieuw te proberen.";
                    break;
                }
            }
            else
            {
                //the guid we passed to Mollie is not mapped correctly, show an error
                payRes.ErrorMessage = "Er is reeds een nieuwe betaling gestart, u kan dit scherm sluiten.";
            }
            return(View(payRes));
        }
Example #2
0
        public async Task <IActionResult> Webhook(string id)
        {
            //Search for the Order Posted by the Webhook
            var dbOrder = _context.Orders.Where(x => x.PaymentId == id).Select(x => x).SingleOrDefault();

            //Get the current Payment Status
            PaymentResponse result = await paymentClient.GetPaymentAsync(id);

            //Update dbOrder
            dbOrder.PaymentStatus = result.Status.ToString();
            _context.Update(dbOrder);



            await _context.SaveChangesAsync();

            if (dbOrder.PaymentStatus.ToLower() == "paid")
            {
                await _emailSender.SendEmailAsync(
                    dbOrder.Email,
                    "Order Confirmation",
                    $"Your order has been placed successfully, your order number is {dbOrder.Guid}");
            }


            return(Ok());
        }
 private async Task <PaymentResponse> GetPaymentDetails(string paymentId)
 {
     return(await _paymentClient.GetPaymentAsync(paymentId));
 }
Example #4
0
 public async Task <PaymentResponse> FetchMolliePayment(string paymentId)
 {
     return(await _client.GetPaymentAsync(paymentId));
 }