Пример #1
0
        //create method
        public ActionResult PaymentWithPaypal()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            var order = (OrderVipDTO)Session["ordervip"];

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Client/Payment/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid, order);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        SetAlert("Mua gói vip không thành công", "error");
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                SetAlert("Mua gói vip không thành công", "error");
                return(RedirectToAction("Index"));
            }

            ApiService.AcceptOrder(order);
            SetAlert("Mua gói vip thành công", "success");
            return(RedirectToAction("Success", "Payment", new { code = apiContext.AccessToken }));
        }
Пример #2
0
        public ActionResult MomoCallBack(string amount, string extraData, string signature)
        {
            string[] words = extraData.Split(',');

            var user = ApiService.GetIdLogin(words[2]);

            if (ApiService.AcceptOrder(new OrderVipDTO()
            {
                PVipID = Int32.Parse(words[0]),
                PaymentID = Int32.Parse(words[1]),
                UserID = user.ID,
                OrdPrice = Int32.Parse(amount)
            }))
            {
                SetAlert("Mua gói vip thành công", "success");
                return(RedirectToAction("Success", "Payment", new { code = signature }));
            }


            SetAlert("Mua gói vip không thành công", "error");
            return(RedirectToAction("Index"));
        }