Exemple #1
0
        public IActionResult Validate(string RequestCode)
        {
            Helpers.Sql sql = new Helpers.Sql();
            ViewData["Message"]     = "";
            ViewData["Back"]        = 1;
            ViewData["ShowPay"]     = 0;
            ViewData["ShowRecover"] = 0;
            ViewData["RequestCode"] = RequestCode;

            if (!string.IsNullOrEmpty(RequestCode))
            {
                Response.Cookies.Append("RequestCode", RequestCode);

                if (sql.verifyCode(RequestCode) == true)
                {
                    if (sql.codeUsed(RequestCode) == false)
                    {
                        ViewData["Message"]   = "Your code has been validated";
                        ViewData["Back"]      = 0;
                        ViewData["ShowPay"]   = 1;
                        ViewData["MaxBadges"] = sql.maxBadges(RequestCode);
                    }
                    else
                    {
                        ViewData["Message"]     = "";
                        ViewData["Back"]        = 0;
                        ViewData["ShowRecover"] = 1;
                    }
                }
                else
                {
                    ViewData["Message"] = "Invalid Code";
                    ViewData["Back"]    = 1;
                }
            }

            return(View());
        }
Exemple #2
0
        public IActionResult Complete(string stripeEmail, string stripeToken)
        {
            ViewData["Message"]    = "If your seeing this, either you shouldnt be here, or something went wrong. Email us, or try again.";
            ViewData["Back"]       = 1;
            ViewData["qrcode"]     = "";
            ViewData["ShowEnd"]    = 0;
            ViewData["TransError"] = "";
            ViewData["Image"]      = "";
            ViewData["badgenum"]   = "";
            ViewData["Email"]      = "";
            ViewData["uri"]        = Startup.uri;

            string qrcode = "";


            ViewBag.RequestCode = Request.Cookies["RequestCode"];
            string RequestCode = ViewBag.RequestCode;

            Helpers.Sql    sql  = new Helpers.Sql();
            Helpers.QRGen  qr   = new Helpers.QRGen();
            Helpers.Mailer mail = new Helpers.Mailer();

            int price = sql.getPrice(RequestCode);

            var customers = new StripeCustomerService();
            var charges   = new StripeChargeService();

            if (!sql.codeUsed(RequestCode))
            {
                if (!String.IsNullOrEmpty(stripeEmail) && !String.IsNullOrEmpty(stripeToken))
                {
                    try
                    {
                        var customer = customers.Create(new StripeCustomerCreateOptions
                        {
                            Email       = stripeEmail,
                            SourceToken = stripeToken
                        });

                        var charge = charges.Create(new StripeChargeCreateOptions
                        {
                            Amount      = price,
                            Description = "QC-DCBadgeOrder",
                            Currency    = "usd",
                            CustomerId  = customer.Id
                        });


                        if (String.Compare(charge.Status, "succeeded", true) == 0)
                        {
                            ViewData["Back"] = 0;
                            String guid = Guid.NewGuid().ToString();
                            qrcode = sql.getID(RequestCode) + ";" + guid;
                            sql.updateSale(RequestCode, stripeEmail, customer.Id, charge.Id, qrcode);
                            int badgenum = charge.Amount / Startup.price;
                            ViewData["badgenum"] = badgenum;
                            ViewData["qrcode"]   = qrcode;
                            ViewData["ShowEnd"]  = 1;
                            ViewData["Message"]  = "";
                            ViewData["Image"]    = qr.genQRCode64(qrcode);
                            ViewData["Email"]    = stripeEmail;
                            mail.SendEmailAsync(stripeEmail, qrcode, badgenum.ToString());
                        }
                    }
                    catch (StripeException e)
                    {
                        ViewData["TransError"] = e.Message;
                        ViewData["Message"]    = "Something went wrong... look at the error message, email us or try again.";
                    }
                }
            }



            return(View());
        }