Exemplo n.º 1
0
        public ActionResult Index()
        {
            using (var context = new PSTHContext())
            {
                var total = context.Payments.Select(x => x.Price).DefaultIfEmpty(0f).Sum();

                return(View(new IndexViewModel()
                {
                    Total = total
                }));
            }
        }
Exemplo n.º 2
0
        public ActionResult CallbackOk()
        {
            try
            {
                var token   = Request.QueryString["token"];
                var payerId = Request.QueryString["PayerID"];

                if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(payerId))
                {
                    if (!string.IsNullOrEmpty(Request.Cookies["_c3P-Pt5"]?.Value))
                    {
                        var paymentResponse = _paymentCore.Payment(token, payerId);
                        if (paymentResponse != null)
                        {
                            var paymentInfoType = _paymentCore.GetTransactionStatus(paymentResponse.TransactionId, out string error);
                            if (paymentInfoType.PaymentStatus.ToString() == "COMPLETED")
                            {
                                try
                                {
                                    using (var context = new PSTHContext())
                                    {
                                        var price = float.Parse(paymentInfoType.GrossAmount.value);
                                        context.Payments.Add(new Payment
                                        {
                                            Price = price
                                        });
                                        context.SaveChanges();
                                    }
                                }
                                catch (Exception e)
                                {
                                    /**/
                                }

                                TempData["type"]    = "success";
                                TempData["message"] = Messages.PaymentSuccess;
                                return(RedirectToHome());
                            }
                        }
                    }
                }
            }
            catch
            {
                /**/
            }
            TempData["type"]    = "warning";
            TempData["message"] = Messages.PaymentWrong;
            return(RedirectToHome());
        }