コード例 #1
0
        //
        // GET: /SuccessPaiement/

        public ActionResult Index()
        {
            AWLFacture achat = new AWLFacture(); // this is something I have defined in order to save the order in the database

            // 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", "bUyBnYSISiK2AmXEowNt9s_CJ2EqzTc5ZETJ5bRQWFyQiiG4xJ8Kw2D9T00"); // this has to be adjusted
            formVals.Add("tx", Request["tx"]);

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

            if (response.Contains("SUCCESS"))
            {
                string transactionID = GetPDTValue(response, "txn_id");      // txn_id //d
                string sAmountPaid   = GetPDTValue(response, "mc_gross");    // d
                string deviceID      = GetPDTValue(response, "custom");      // d
                string payerEmail    = GetPDTValue(response, "payer_email"); // d
                string Item          = GetPDTValue(response, "item_name");
                string ItemNumber    = GetPDTValue(response, "item_number");
                string dateNumber    = DateTime.Now.ToString();

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

                AWLFacturesContext contextFactures = new AWLFacturesContext();
                List <AWLFacture>  tableFactures   = contextFactures.FacturesTable.ToList();

                if (tableFactures.Count(d => d.IdPaiement == transactionID) < 1)
                {
                    //if the transactionID is not found in the database, add it
                    //then, add the additional features to the user account
                    UsersContext db        = new UsersContext();
                    UserProfile  userBuyer = db.UserProfiles.FirstOrDefault(u => u.UserName.Equals(System.Web.HttpContext.Current.User.Identity.Name));

                    // Mise à jour des paramètres d'achat
                    achat.IdPaiement = transactionID;
                    achat.Buyer      = userBuyer.UserName;
                    achat.Article    = Item;
                    achat.Montant    = amountPaid;
                    achat.Plateforme = dateNumber + " - with PAYPAL";

                    // On ajoute l'entrée dans la table Factures et on sauve la base de données
                    contextFactures.FacturesTable.Add(achat);
                    contextFactures.SaveChanges();

                    // Génération du PDF et des emails

                    // Ajout des noix dans le compte du nutter
                    if (ItemNumber == "1")
                    {
                        userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                    }
                    else if (ItemNumber == "2")
                    {
                        userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                    }
                    else if (ItemNumber == "3")
                    {
                        userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                    }
                    else if (ItemNumber == "4")
                    {
                        userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                        userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                        userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                    }
                    db.SaveChanges();

                    // Mise à jour dans le panel d'en haut à droite
                    ViewData["noix1"] = userBuyer.UserNuts1;
                    ViewData["noix2"] = userBuyer.UserNuts2;
                    ViewData["noix3"] = userBuyer.UserNuts3;

                    // On envoie un mail de confirmation
                    MailingService4 mailingService = new MailingService4();
                    mailingService.SendTokenByEmail("", userBuyer.Email, userBuyer.UserName, transactionID, Item, amountPaid.ToString(), dateNumber);
                }
                else
                {
                    //if we are here, the user must have already used the transaction ID for an account
                    //you might want to show the details of the order, but do not upgrade it!
                }
                // take the information returned and store this into a subscription table
                // this is where you would update your database with the details of the tran

                return(View());
            }
            else
            {
                //error
                return(View("ErrorBuy"));
            }
        }
コード例 #2
0
        //
        // GET: /SuccessPaiement/

        public ActionResult Index()
        {
            StreamReader reader      = new StreamReader(HttpContext.Request.InputStream, System.Text.Encoding.UTF8);
            String       sXMLRequest = reader.ReadToEnd();
            XmlDocument  xmlRequest  = new XmlDocument();

            xmlRequest.LoadXml(sXMLRequest);

            XmlNode xmlTransactionId = xmlRequest.SelectSingleNode("/mapi/result/transid");
            XmlNode xmlDate          = xmlRequest.SelectSingleNode("/mapi/result/date");
            XmlNode xmlTime          = xmlRequest.SelectSingleNode("/mapi/result/time");
            XmlNode xmlAmount        = xmlRequest.SelectSingleNode("/mapi/result/origAmount");
            XmlNode xmlEmail         = xmlRequest.SelectSingleNode("/mapi/result/emailClient");
            XmlNode xmlProduct       = xmlRequest.SelectSingleNode("/mapi/result/merchantDatas/_aKey_nom1");
            XmlNode xmlIdProduct     = xmlRequest.SelectSingleNode("/mapi/result/refProduct0");

            string sTransactionId = xmlTransactionId.ToString();
            string sDate          = DateTime.Now.ToString();
            String sAmount        = xmlAmount.ToString();
            string sEmail         = xmlEmail.ToString();
            string sProduct       = xmlProduct.ToString();
            string sIdProduct     = xmlIdProduct.ToString();

            AWLFacture achat = new AWLFacture(); // this is something I have defined in order to save the order in the database

            AWLFacturesContext contextFactures = new AWLFacturesContext();
            List <AWLFacture>  tableFactures   = contextFactures.FacturesTable.ToList();

            if (tableFactures.Count(d => d.IdPaiement == sTransactionId) < 1)
            {
                //if the transactionID is not found in the database, add it
                //then, add the additional features to the user account
                UsersContext db        = new UsersContext();
                UserProfile  userBuyer = db.UserProfiles.FirstOrDefault(u => u.UserName.Equals(System.Web.HttpContext.Current.User.Identity.Name));

                // Mise à jour des paramètres d'achat
                achat.IdPaiement = sTransactionId;
                achat.Buyer      = userBuyer.UserName;
                achat.Article    = sProduct;
                achat.Montant    = Convert.ToDecimal(sAmount);
                achat.Plateforme = sDate + " - with HIPAY WALLET";

                // On ajoute l'entrée dans la table Factures et on sauve la base de données
                contextFactures.FacturesTable.Add(achat);
                contextFactures.SaveChanges();

                // Génération du PDF et des emails

                // Ajout des noix dans le compte du nutter
                if (sIdProduct == "1")
                {
                    userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                }
                else if (sIdProduct == "2")
                {
                    userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                }
                else if (sIdProduct == "3")
                {
                    userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                }
                else if (sIdProduct == "4")
                {
                    userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                    userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                    userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                }
                db.SaveChanges();

                // Mise à jour dans le panel d'en haut à droite
                ViewData["noix1"] = userBuyer.UserNuts1;
                ViewData["noix2"] = userBuyer.UserNuts2;
                ViewData["noix3"] = userBuyer.UserNuts3;
            }
            else
            {
                //if we are here, the user must have already used the transaction ID for an account
                //you might want to show the details of the order, but do not upgrade it!
            }
            // take the information returned and store this into a subscription table
            // this is where you would update your database with the details of the tran

            return(View());
        }
コード例 #3
0
        //
        // GET: /SuccessPaiementFbk/

        public ActionResult Index(string identifiant, string montant, string devise, string itemnumber, string idnutter)
        {
            AWLFacture achat = new AWLFacture(); // this is something I have defined in order to save the order in the database

            //validate the order
            string  dateNumber = DateTime.Now.ToString();
            Decimal amountPaid = 0;

            Decimal.TryParse(montant, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out amountPaid);

            AWLFacturesContext contextFactures = new AWLFacturesContext();
            List <AWLFacture>  tableFactures   = contextFactures.FacturesTable.ToList();

            if (tableFactures.Count(d => d.IdPaiement == identifiant) < 1)
            {
                //if the transactionID is not found in the database, add it
                //then, add the additional features to the user account
                AWLFacebookContext db        = new AWLFacebookContext();
                AWLFacebookProfile userBuyer = db.FacebookNuttersTable.FirstOrDefault(u => u.UserId.Equals(idnutter));


                // Mise à jour des paramètres d'achat
                achat.IdPaiement = identifiant;
                achat.Buyer      = userBuyer.UserName + "/" + idnutter;
                string nomitem;
                if (itemnumber == "1")
                {
                    achat.Article = "Simple Nuts";
                }
                else if (itemnumber == "2")
                {
                    achat.Article = "Bronze Nuts";
                }
                else if (itemnumber == "3")
                {
                    achat.Article = "Gold Nuts";
                }
                else if (itemnumber == "4")
                {
                    achat.Article = "Package Nuts";
                }

                nomitem          = achat.Article;
                achat.Montant    = amountPaid;
                achat.Plateforme = dateNumber + " - with FACEBK";

                // On ajoute l'entrée dans la table Factures et on sauve la base de données
                contextFactures.FacturesTable.Add(achat);
                contextFactures.SaveChanges();

                // Génération du PDF et des emails

                // Ajout des noix dans le compte du nutter
                if (itemnumber == "1")
                {
                    userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                }
                else if (itemnumber == "2")
                {
                    userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                }
                else if (itemnumber == "3")
                {
                    userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                }
                else if (itemnumber == "4")
                {
                    userBuyer.UserNuts1 = userBuyer.UserNuts1 + 30;
                    userBuyer.UserNuts2 = userBuyer.UserNuts2 + 30;
                    userBuyer.UserNuts3 = userBuyer.UserNuts3 + 30;
                }
                db.SaveChanges();

                // Mise à jour dans le panel d'en haut à droite
                ViewData["noix1"] = userBuyer.UserNuts1;
                ViewData["noix2"] = userBuyer.UserNuts2;
                ViewData["noix3"] = userBuyer.UserNuts3;

                // Pour la fenetre de confirmation et de succès
                ViewBag.nomitem         = nomitem;
                ViewBag.identifiantcool = identifiant;
                ViewBag.montantcool     = montant;
                ViewBag.devisecool      = devise;

                return(View());
            }
            else
            {
                //error
                return(View("ErrorBuy"));
            }
        }