コード例 #1
0
ファイル: HomeController.cs プロジェクト: Queercon/dcbadge
        public IActionResult Pay(int BadgeNumber)
        {
            ViewData["TotalPrice"]  = "0";
            ViewData["BadgeNumber"] = "0";

            Helpers.Sql sql = new Helpers.Sql();

            ViewData["Message"]     = "";
            ViewData["Back"]        = 1;
            ViewData["ShowPay"]     = 0;
            ViewData["ShowRecover"] = 0;

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

            if (!string.IsNullOrEmpty(RequestCode) && (BadgeNumber > 0) && (BadgeNumber <= sql.maxBadges(RequestCode)))
            {
                if (sql.verifyCode(RequestCode) == true)
                {
                    sql.updatePrice(RequestCode, BadgeNumber, (BadgeNumber * Startup.price));
                    ViewData["TotalPrice"]  = sql.getPrice(RequestCode);
                    ViewData["BadgeNumber"] = BadgeNumber;
                    ViewData["ShowPay"]     = 1;
                    ViewData["Back"]        = 0;
                }
            }


            return(View());
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Queercon/dcbadge
        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());
        }