Beispiel #1
0
        public ActionResult AddMoney(WalletModel.AddMoney AddMoney)
        {
            int        Amount = AddMoney.EnterMoney;
            PaypalItem p      = new PaypalItem();

            p.currency = "NZD";
            p.sku      = Session[KeyList.SessionKeys.UserID].ToString();
            p.price    = Convert.ToDouble(Amount);

            List <PaypalItem> ListPay = new List <PaypalItem>();

            ListPay.Add(p);
            PaymentHandler ph = new PaymentHandler(ListPay, Convert.ToInt32(Session[KeyList.SessionKeys.UserID]));

            return(View());
        }
        private static JObject ToDto(PaypalItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var jObj = new JObject();

            jObj.Add("description", item.Description);
            jObj.Add("name", item.Name);
            jObj.Add("price", item.Price);
            jObj.Add("quantity", item.Quantity);
            jObj.Add("sku", item.Sku);
            jObj.Add("tax", item.Tax);
            jObj.Add("currency", item.Currency);
            return(jObj);
        }
        private static PaymentTransaction ToPaymentTransaction(JObject jObj)
        {
            if (jObj == null)
            {
                throw new ArgumentNullException(nameof(jObj));
            }

            var amount        = jObj.GetValue("amount") as JObject;
            var amountDetails = amount.GetValue("details") as JObject;
            var itemList      = jObj.GetValue("item_list") as JObject;
            var items         = itemList.GetValue("items") as JArray;
            var paypalItems   = new List <PaypalItem>();
            var result        = new PaymentTransaction
            {
                Total            = amount.Value <double>("total"),
                SubTotal         = amountDetails.Value <double>("subtotal"),
                Tax              = amountDetails.Value <double>("tax"),
                Shipping         = amountDetails.Value <double>("shipping"),
                HandlingFee      = amountDetails.Value <double>("handling_fee"),
                ShippingDiscount = amountDetails.Value <double>("shipping_discount"),
                Description      = jObj.Value <string>("description")
            };

            if (items != null)
            {
                foreach (var item in items)
                {
                    var paypalItem = new PaypalItem
                    {
                        Name        = item.Value <string>("name"),
                        Description = item.Value <string>("description"),
                        Price       = item.Value <double>("price"),
                        Quantity    = item.Value <int>("quantity")
                    };
                    paypalItems.Add(paypalItem);
                }
            }

            result.Items = paypalItems;
            return(result);
        }
        public ActionResult PostToPaypal(int orderId, string amount)
        {
            Models.Paypal paypal = new Models.Paypal();
            paypal.cmd      = "_xclick";
            paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"];
            //if (useSandbox == "1")
            //    ViewBag.actionURl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            //else
            //    ViewBag.actionURl = "https://www.paypal.com/cgi-bin/webscr";

            bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);

            if (useSandbox)
            {
                //sandbox url
                ViewBag.actionURl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            }
            else
            {
                ViewBag.actionURl = "https://www.paypal.com/cgi-bin/webscr";
            }
            paypal.cancel_return = ConfigurationManager.AppSettings["CancelURL"] + "?orderId=" + orderId + "&";
            paypal.@return       = ConfigurationManager.AppSettings["ReturnURL"] + "?orderId=" + orderId + "&";
            paypal.notify_url    = ConfigurationManager.AppSettings["NotifyURL"] + "?orderId=" + orderId + "&";
            paypal.currency_code = ConfigurationManager.AppSettings["CurrencyCode"];

            paypal.PaypalItems = new List <PaypalItem>();
            foreach (FunOrderDetail od in dbmeals.FunOrderDetails.Where(x => x.OrderID == orderId))
            {
                PaypalItem oPaypalItem = new PaypalItem();
                oPaypalItem.item_name = od.Description;
                oPaypalItem.Quantity  = (od.Quantity).ToString();
                oPaypalItem.amount    = od.Price.ToString();
                paypal.PaypalItems.Add(oPaypalItem);
            }
            return(View(paypal));
        }
Beispiel #5
0
        protected void Checkoutt_Click(object sender, EventArgs e)
        {
            if (cartitems == null)
            {
                db = new BetaDB();
                var email = Session["email"].ToString();
                userId    = db.Logins.Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault();
                cartitems = db.Carts.Where(x => x.UserId == userId).ToList <Cart>();
            }
            List <PaypalItem> approvedItems = new List <PaypalItem>();

            foreach (Cart ci in cartitems)
            {
                var product = db.Products.Where(x => x.ProductID == ci.ProductID).SingleOrDefault();
                var stock   = db.Stocks.Where(x => x.ProductID == ci.ProductID && x.ProductSizeName == ci.Size).FirstOrDefault();
                if (stock.StockCount < ci.Quantity)
                {
                    outofstocklbl.Text = "Some Products are Out of Stock";
                }
                else
                {
                    PaypalItem pi = new PaypalItem
                    {
                        ProductId = product.ProductID,
                        name      = product.ProductName,
                        currency  = "NZD",
                        price     = Convert.ToDouble(product.ProductPrice),
                        quantity  = (int)ci.Quantity,
                        size      = ci.Size,
                        sku       = product.ProductID.ToString()
                    };
                    approvedItems.Add(pi);
                }
            }

            PaymentHandler ph = new PaymentHandler(approvedItems, userId);
        }