Exemplo n.º 1
0
        public ActionResult PaymentSave(MembershipContactInfoModel model)
        {
            //if (model.GatewayName != "PayPal") {
            //    //ModelState.AddModelError(string.Empty, "Wrong gateway channel, please contact your Administrator.");
            //    return View("Error");
            //}

            ViewBag.ErrorMessage = "";
            if (!model.isContactValid())
            {
                return(RedirectToAction("Index", "Membership"));
            }

            //check if model email exists
            AuthDbContext context    = new AuthDbContext();
            var           usrManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (usrManager.FindByEmail(model.Email) != null)
            {
                //already a member
                ViewBag.ErrorMessage = "Invalid information, this account already exists, please return and correct the information.";
            }

            if (!model.isContactValid())
            {
                ViewBag.ErrorMessage = "Invalid information, please return and fill out all the required information.";
                return(View(model));
            }

            DBHelper.DBMembership.BufferRegisterContact(ref model);

            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// get form submit from ContactInfo
        /// Save information to Buffer
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult PaymentSave(MembershipContactInfoModel model)
        {
            if (model.GatewayName != "Stripe")
            {
                ModelState.AddModelError("CustomError", "Error: Wrong gateway channel");
                return(View("Error"));
            }

            try
            {
                ViewBag.ErrorMessage = "";
                if (!model.isContactValid())
                {
                    return(RedirectToAction("Index", "Membership"));
                }

                //check if model email exists
                AuthDbContext context    = new AuthDbContext();
                var           usrManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
                if (usrManager.FindByEmail(model.Email) != null)
                {
                    //already a member
                    ModelState.AddModelError("CustomError", "Error: Invalid information, this account already exists, please return and correct the information.");
                    return(View("Error"));
                }

                //save contact information into Buffer
                DBHelper.DBMembership.BufferRegisterContact(ref model);

                return(View(model));
            }
            catch (Exception ex) {
                ModelState.AddModelError("CustomError", "Error: " + ex.Message);
                return(View("Error"));
            }
        }
Exemplo n.º 3
0
        public ActionResult PaymentReceive(string token, string payerID)
        {
            ViewBag.ErrorMessage = "";
            // First thing's first. We'll need to get the token and payer ID returned from the previous call:
            if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(payerID))
            {
                ViewBag.ErrorMessage = "Something went wrong, payment didn't go through the gateway.";
                return(View());
            }

            string Your_Test_Merchant_Account_User = "******";
            string Your_Test_Account_Password      = "******";
            string Your_Test_Account_Signature     = "AFcWxV21C7fd0v3bYYYRCpSSRl31Am.wVsyYEVgjySzw5m3Tj9q9KCk5";

            MembershipContactInfoModel model = new MembershipContactInfoModel();

            MembershipContactInfoModel dbModel = DBHelper.DBMembership.GetModelByTransactionToken(token);
            string nameProduct = HttpUtility.UrlEncode(dbModel.MembershipTitle);
            string descProduct = HttpUtility.UrlEncode(dbModel.MembershipDescription);
            double tax         = 13 / 100;

            try
            {
                // Than we add the tokens to string type variables as we'll need to rebuild the NVP string

                // Rebuilding the NVP string for the request; I've hardcoded the payment values again as this sample app does not have a database behind it.
                string NVP = string.Empty;

                NVP += "METHOD=DoExpressCheckoutPayment";
                NVP += "&VERSION=123";

                NVP += "&USER="******"&PWD=" + Your_Test_Account_Password;
                NVP += "&SIGNATURE=" + Your_Test_Account_Signature;

                NVP += "&TOKEN=" + token;
                NVP += "&PAYERID=" + payerID;

                NVP += "&PAYMENTREQUEST_0_PAYMENTACTION=Sale";
                NVP += "&PAYMENTREQUEST_0_AMT=" + DBHelper.DBMembership.PriceFormat(dbModel.Price * (1 + tax));
                NVP += "&PAYMENTREQUEST_0_ITEMAMT=" + DBHelper.DBMembership.PriceFormat(dbModel.Price);
                NVP += "&PAYMENTREQUEST_0_SHIPPINGAMT=0";
                NVP += "&PAYMENTREQUEST_0_HANDLINGAMT=0";
                NVP += "&PAYMENTREQUEST_0_TAXAMT=" + DBHelper.DBMembership.PriceFormat(tax);

                // Making the API call
                string response = APICall(NVP);

                // Interpreting the response from PayPal; As a simple UI for checking the transaction, I'm displaying the transaction ID in the page on success so to make things easier when I'm checking the transaction log in PayPal's web UI.
                if (response.Contains("Success"))
                {
                    string transactionId  = response.Substring(response.IndexOf("PAYMENTINFO_0_TRANSACTIONID"), response.IndexOf("&", response.IndexOf("PAYMENTINFO_0_TRANSACTIONID")) - response.IndexOf("PAYMENTINFO_0_TRANSACTIONID"));
                    string TransactNumber = transactionId.Split('=')[1];
                    ViewBag.PaymentStatus += transactionId;
                    model = DBHelper.DBMembership.CheckTransactionTokenReturn(token);
                    if (model.isContactValid())
                    {
                        model.PayerID           = payerID;
                        model.TransactionNumber = TransactNumber;
                        //update transaction number and payerid to buffer
                        DBHelper.DBMembership.ValidateTransaction(model);
                        //create username
                        DBHelper.DBMembership.CreateMember(model);
                        //transfer Buffer into Contacts and the rest of tables
                        DBHelper.DBMembership.BufferTransfer(model);
                    }
                }
                else
                {
                    //model = (MembershipContactInfoModel)Session["Payer"];
                    ViewBag.ErrorMessage = "Something went wrong, payment didn't go through the gateway.";
                }
            }
            catch (Exception ex) {
                //model = (MembershipContactInfoModel)Session["Payer"];
                ViewBag.ErrorMessage = ex.Message;
            }


            return(View(model));
        }