Esempio n. 1
0
        public ActionResult Checkout()
        {
            PayPalExpressCheckout pp = new PayPalExpressCheckout(API_UserName, API_Password, API_Signature, isTestingMode);

            List <PayPalExpressCheckout.PayPalItem> items = new List <PayPalExpressCheckout.PayPalItem>();

            PayPalExpressCheckout.PayPalItem item = new PayPalExpressCheckout.PayPalItem();
            item.name = "My Digital Product 1";
            item.amt  = "0.99";
            item.qty  = "1";
            items.Add(item);

            //add more for shopping cart
            item      = new PayPalExpressCheckout.PayPalItem();
            item.name = "Product 2";
            item.amt  = "1.99";
            item.qty  = "1";
            items.Add(item);

            float totalAmount = 0;

            foreach (PayPalExpressCheckout.PayPalItem i in items)
            {
                totalAmount += float.Parse(i.amt);
            }

            string paymentAmount = totalAmount.ToString();
            string customField   = "trackcode=1&id=2"; //for your self tracking

            NameValueCollection nvpResArray = pp.SetExpressCheckoutDG(paymentAmount, currencyCodeType, paymentType, returnURL, cancelURL, items, customField, true, itemCategory);
            string ack = nvpResArray.GetValues("ACK").First().ToUpper();

            if (ack == "SUCCESS" || ack == "SUCCESSWITHWARNING")
            {
                string token = nvpResArray.GetValues("TOKEN").First();
                //redirect to paypal
                if (itemCategory == "Digital")
                {
                    Response.Redirect(pp.PAYPAL_DG_URL + token);
                }
                else
                {
                    Response.Redirect(pp.PAYPAL_URL + token);
                }
            }
            else
            {
                //failed
                ViewBag.result = nvpResArray;
                ViewBag.status = "paypal failed";
            }

            return(View());
        }