Пример #1
0
        public ActionResult PayPalPayment(int ordId)
        {
            int        zz         = ordId;
            APIContext apicontext = PayPalConfiguration.GetAPIContextZ();

            try
            {
                string PayerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(PayerID))
                {
                    string baseUri = Request.Url.Scheme + "://"
                                     + Request.Url.Authority + "PaypalPayment/Paypal";
                    var Guid          = Convert.ToString((new Random()).Next(100000000));
                    var createPayment = this.CreatePayPalPayment(apicontext, baseUri
                                                                 + "guid=" + Guid, zz);
                    var    link = createPayment.links.GetEnumerator();
                    string paypalRedirectURL = null;
                    while (link.MoveNext())
                    {
                        Links liz = link.Current;
                        if (liz.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectURL = liz.href;
                        }
                    }
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apicontext, PayerID, Session[guid] as string);
                    if (executePayment.ToString().ToLower() != "approved")
                    {
                        return(View("FailedPayPalPayment"));
                    }
                }
            }
            catch (Exception)
            {
                return(View("FailedPayPalPayment"));
            }
            return(View("SuccessfulPayment"));
        }