Exemplo n.º 1
0
        public void CCCCCCC_Is_6()
        {
            _finalProduct = posTerm.ScanProduct("CCCCCCC");
            totalPrice    = pCalc.CalculateTotalPrice(_finalProduct);

            Assert.AreEqual(6, totalPrice);
        }
Exemplo n.º 2
0
        public ActionResult Details(string tx)
        {
            #region Insert Order using IPN CODE
            var order = new CoachOrder();

            // Receive IPN request from PayPal and parse all the variables returned
            var formVals = new Dictionary <string, string>();
            formVals.Add("cmd", "_notify-synch"); //notify-synch_notify-validate
            formVals.Add("at", "wABDeX0w9ivh2l8iWcH1kQOwVmTlOrox0oWCUQeDNqyZHKmBd8GjRy6s6c4");
            formVals.Add("tx", Request["tx"]);

            // if you want to use the PayPal sandbox change this from false to true
            string response = GetPayPalResponse(formVals, useSandbox: false);

            if (response.Contains("SUCCESS"))
            {
                string transactionID = GetPDTValue(response, "txn_id");   // txn_id //d
                string sAmountPaid   = GetPDTValue(response, "mc_gross"); // d
                string sCurrency     = GetPDTValue(response, "mc_currency");

                var    custom_info    = GetPDTValue(response, "custom").Split(','); // d
                string payerEmail     = GetPDTValue(response, "payer_email");       // d
                string Item           = GetPDTValue(response, "item_name");
                string payment_status = GetPDTValue(response, "payment_status");
                string receiver_email = GetPDTValue(response, "receiver_email");

                string sQuantity = custom_info[2];
                int.TryParse(sQuantity, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out int quantity);

                string sPayerId = custom_info[3];
                int.TryParse(sPayerId, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out int payer_account_id);

                //validate the order
                decimal amountPaid = 0;
                decimal.TryParse(sAmountPaid, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out amountPaid);

                order.txn_id      = transactionID;
                order.mc_gross    = amountPaid;
                order.mc_currency = sCurrency;
                order.payer_mail  = payerEmail;
                order.receiver_id = int.Parse(custom_info[0]);
                order.game_id     = int.Parse(custom_info[1]);
                order.service_id  = int.Parse(custom_info[4]);

                order.date             = DateTime.UtcNow;
                order.quantity         = quantity;
                order.payer_account_id = payer_account_id;

                using (var conn = new MySqlConnection(ConnectionString.Get("EscademyDB")))
                {
                    conn.Open();

                    if (amountPaid >= PriceCalculator.CalculateTotalPrice(order.service_id, quantity, conn) - 0.1M &&
                        sCurrency == "USD" &&
                        payment_status == "Completed" &&
                        receiver_email.Equals("*****@*****.**", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var new_order = !check_if_order_exists(transactionID, conn);

                        if (new_order)
                        {
                            order.success = true;
                            int OrderId = insert_new_order(order, conn);
                            create_transaction(OrderId, order, conn);
                        }
                        else
                        {
                            order.success = false;
                        }

                        ViewBag.order = order;
                    }
                    else
                    {
                        order.success = false;
                        int OrderId = insert_new_order(order, conn);//Incorrect amount.. just log incident.
                    }

                    conn.Close();
                }
            }
            else
            {
                //error
            }
            #endregion

            #region Get Order-Item Detail by Transaction-Id
            var     OrderItemDetail = new List <OrderDetailVM>();
            string  BuyerName       = "";
            decimal TotalAmount     = 0;
            string  OrderDate       = "";
            int     OrderNo         = 0;
            int     i = 0;
            using (var conn = new MySqlConnection(ConnectionString.Get("EscademyDB")))
            {
                conn.Open();
                #region Get Order-Item Detail by Transaction-Id
                using (var cmdActiveOrder = conn.CreateCommand())
                {
                    cmdActiveOrder.CommandText = "select concat(a1.FirstName,' ', a1.LastName) as BuyerName,o.Id as OrderNo,o.mc_gross,o.quantity,o.date as OrderedDate,(select pg.Title from esc_profilegames pg where /*pg.accountId=o.receiver_id and*/ pg.gameId=o.game_id limit 1) as ItemName from esc_orders o inner join esc_accounts a1 on o.payer_account_id=a1.Id where o.txn_id=@transactionId";
                    cmdActiveOrder.Parameters.AddWithValue("@transactionId", tx);
                    var reader = cmdActiveOrder.ExecuteReader();
                    while (reader.Read())
                    {
                        if (i == 0)
                        {
                            BuyerName = reader.GetString("BuyerName");
                            OrderDate = String.Format("{0:ddd, MMM d, yyyy}", @reader.GetDateTime("OrderedDate"));
                            OrderNo   = reader.GetInt32("OrderNo");
                            i++;
                        }

                        TotalAmount = TotalAmount + reader.GetDecimal("mc_gross");
                        OrderItemDetail.Add(new OrderDetailVM()
                        {
                            ItemName = reader.GetString("ItemName"),
                            Quantity = reader.GetInt32("quantity"),
                            Price    = reader.GetDecimal("mc_gross"),
                        });
                    }
                    ViewBag.OrderItemList = OrderItemDetail;
                    ViewBag.TotalAmount   = TotalAmount.ToString().Replace(",", ".");
                    ViewBag.OrderNo       = OrderNo;
                    ViewBag.BuyerName     = BuyerName;
                    ViewBag.OrderDate     = OrderDate;
                }
                #endregion
                conn.Close();
            }
            #endregion
            return(View());
        }