public PayPalInvoiceModel GetPayPalInvoiceByGUID(string invoiceGUID)
        {
            DataTable          dt_1          = null;
            MSSQL_DAC          clsDAC        = new MSSQL_DAC();
            PayPalInvoiceModel clsSubjectRet = null;

            dt_1 = clsDAC.Read_DT_Procedure("sp_GetPayPalInvoiceByGUID", new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("InvoiceGUID", invoiceGUID)
            });

            if (dt_1 != null || dt_1.Rows.Count > 0)
            {
                DataRow dr_1 = dt_1.Rows[0];

                clsSubjectRet = new PayPalInvoiceModel()
                {
                    InvoiceGUID     = Convert.ToString(dr_1["InvoiceGUID"]),
                    PayPalInvoiceID = (dr_1["PayPalInvoiceID"] == DBNull.Value ? 0 : Convert.ToInt32(dr_1["PayPalInvoiceID"])),
                    QuestionID      = (dr_1["QuestionID"] == DBNull.Value ? 0 : Convert.ToInt32(dr_1["QuestionID"])),
                    RequestXML      = Convert.ToString(dr_1["RequestXML"]),
                    PaymentID       = Convert.ToString(dr_1["PaymentID"]),
                    ResponseXML     = Convert.ToString(dr_1["ResponseXML"]),
                    State           = Convert.ToString(dr_1["State"]),
                };
            }
            return(clsSubjectRet);
        }
        public ActionResult PaymentWithStripe(string Cancel = null, string subID = null, string questionId = null, string SubChapID = null, string exerciseId = null, string isPastPaper = null, string variant = null)
        {
            StripeTransactionModel md = new StripeTransactionModel();

            //getting the apiContext

            System.Guid guid = System.Guid.NewGuid();

            var transactionid = guid.ToString();

            var paymentSession = this.CreatePaymentSession(transactionid, questionId, subID, SubChapID, exerciseId, isPastPaper, variant);

            PayPalInvoiceModel model = new PayPalInvoiceModel();

            model.InvoiceGUID = transactionid;
            model.QuestionID  = int.Parse(subID);
            model.RequestXML  = "Stripe Payment With Session Id = " + paymentSession.Id;
            model.PaymentID   = paymentSession.Id;

            PayPalManager payPalManager = new PayPalManager();

            payPalManager.CreatePayPalInvoice(model);

            if (variant == null)
            {
                List <Questions> lstRet = new SubjectsController().getChaptersQuesionsBySubjectsID(int.Parse(subID));

                QuestionPayment qp = new QuestionPayment();
                qp.questionid    = int.Parse(questionId);
                qp.subjbectid    = int.Parse(subID);
                qp.transactionid = transactionid;
                qp.variant       = variant;

                ChaptersController questionpayment = new ChaptersController();
                questionpayment.QuestionPaymentSave(qp);
            }
            else
            {
                QuestionPayment qp = new QuestionPayment();
                qp.questionid    = int.Parse(questionId);
                qp.subjbectid    = int.Parse(subID);
                qp.transactionid = transactionid;
                qp.variant       = variant;

                ChaptersController questionpayment = new ChaptersController();
                questionpayment.QuestionPaymentSave(qp);
            }


            md.session   = paymentSession;
            md.sessionid = paymentSession.Id;

            var StripePublishablekey = ConfigurationManager.AppSettings["StripePublishablekey"].ToString();

            md.StripePublishablekey = StripePublishablekey;

            return(View(md));
        }
        public int UpdatePayPalInvoice(PayPalInvoiceModel payPalInvoiceModel)
        {
            var clsDAC = new MSSQL_DAC();

            List <KeyValuePair <string, object> > lstData = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("InvoiceGUID", payPalInvoiceModel.InvoiceGUID),
                new KeyValuePair <string, object>("State", payPalInvoiceModel.State),
                new KeyValuePair <string, object>("ResponseXML", payPalInvoiceModel.ResponseXML),
            };

            return(clsDAC.Execute_Procedure("sp_UpdatePayPalInvoice", lstData));
        }
        public int CreatePayPalInvoice(PayPalInvoiceModel payPalInvoiceModel)
        {
            var clsDAC = new MSSQL_DAC();

            List <KeyValuePair <string, object> > lstData = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("InvoiceGUID", payPalInvoiceModel.InvoiceGUID),
                new KeyValuePair <string, object>("QuestionID", payPalInvoiceModel.QuestionID),
                new KeyValuePair <string, object>("PaymentID", payPalInvoiceModel.PaymentID),
                new KeyValuePair <string, object>("RequestXML", payPalInvoiceModel.RequestXML),
            };

            return(clsDAC.Execute_Procedure("sp_SavePayPalInvoice", lstData));
        }
Пример #5
0
        public ActionResult PaymentWithPaypal(string Cancel       = null, string subID = null
                                              , string questionId = null,
                                              string SubChapID    = null, string exerciseId = null, string isPastPaper = null, string variant = null
                                              )
        {
            //var smtp = new SmtpClient
            try
            {
                //Create the msg object to be sent
                MailMessage msg = new MailMessage();
                //Add your email address to the recipients
                msg.To.Add("*****@*****.**");
                //Configure the address we are sending the mail from
                MailAddress address = new MailAddress("*****@*****.**");
                msg.From    = address;
                msg.Subject = "Clicked On Paypal Button on date time " + DateTime.Now;
                msg.Body    = "Clicked On Paypal Button on date time " + DateTime.Now;

                SmtpClient client = new SmtpClient();
                client.Host = "relay-hosting.secureserver.net";
                client.Port = 25;
                //Setup credentials to login to our sender email address ("UserName", "Password")
                client.UseDefaultCredentials = false;
                NetworkCredential credentials = new NetworkCredential("*****@*****.**", "asjad001$");
                client.Credentials = credentials;

                //Send the msg
                client.Send(msg);

                //Display some feedback to the user to let them know it was sent
                //lblResult.Text = "Your message was sent!";
            }
            catch (Exception ex)
            {
                //If the message failed at some point, let the user know
                //lblResult.Text = ex.ToString(); //alt text "Your message failed to send, please try again."
            }
            //getting the apiContext
            APIContext apiContext    = PaypalConfiguration.GetAPIContext();
            var        transactionid = "";

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    //  string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PayPal/PaymentWithPayPal?";
                    string baseURI = GetBaseUrl() + "/PayPal/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    System.Guid guid1 = System.Guid.NewGuid();
                    var         guid  = guid1.ToString();
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, guid, questionId
                                                            , subID, SubChapID, exerciseId, isPastPaper
                                                            );
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid

                    string paymentXML = Utility.Serialize <Payment>(createdPayment);

                    PayPalManager payPalManager = new PayPalManager();

                    PayPalInvoiceModel model = new PayPalInvoiceModel();

                    model.InvoiceGUID = guid;
                    model.QuestionID  = int.Parse(questionId);
                    model.RequestXML  = paymentXML;
                    model.PaymentID   = createdPayment.id;

                    if (variant == null)
                    {
                        List <Questions> lstRet = new SubjectsController().getChaptersQuesionsBySubjectsID(int.Parse(subID));

                        QuestionPayment qp = new QuestionPayment();

                        qp.questionid    = int.Parse(questionId);
                        qp.subjbectid    = int.Parse(subID);
                        qp.transactionid = transactionid;
                        qp.variant       = variant;

                        ChaptersController questionpayment = new ChaptersController();
                        questionpayment.QuestionPaymentSave(qp);
                    }
                    else
                    {
                        QuestionPayment qp = new QuestionPayment();

                        qp.questionid    = int.Parse(questionId);
                        qp.subjbectid    = int.Parse(subID);
                        qp.transactionid = transactionid;
                        qp.variant       = variant;

                        ChaptersController questionpayment = new ChaptersController();
                        questionpayment.QuestionPaymentSave(qp);
                    }

                    payPalManager.CreatePayPalInvoice(model);

                    // Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    PayPalManager payPalManager = new PayPalManager();

                    // This function exectues after receving all parameters for the payment
                    var guid = Request.Params["guid"];
                    transactionid = guid;
                    try
                    {
                        var invoice = payPalManager.GetPayPalInvoiceByGUID(guid);

                        if (invoice != null)
                        {
                            var executedPayment = ExecutePayment(apiContext, payerId, invoice.PaymentID as string);

                            var response = Utility.Serialize <Payment>(executedPayment);

                            invoice.State       = executedPayment.state;
                            invoice.ResponseXML = response;

                            payPalManager.UpdatePayPalInvoice(invoice);

                            if (executedPayment.state.ToLower() != "approved")
                            {
                                return(RedirectToAction("Index", "Home"));
                                //   return View("FailureView");
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                            // return View("FailureView");
                        }
                    }
                    catch (Exception ex)
                    {
                        var exception = Utility.Serialize <Exception>(ex);
                        payPalManager.LogException(guid, exception);
                        return(RedirectToAction("Index", "Home"));
                    }
                    //If executed payment failed then we will show payment failure message to user
                }
            }
            catch (Exception ex)
            {
                //return View("FailureView");
                return(RedirectToAction("Index", "Home"));
            }
            //on successful payment, show success page to user.

            if (isPastPaper != null && isPastPaper == "1")
            {
                TempData["paymentTransactionId"] = transactionid;
                return(RedirectToAction("ChapterQuestions", "Home", new { sub = subID, questionYearId = questionId, scfp = true }));
                // return RedirectToAction("ShowVideoPastPaper", "Home", new { subID = subID, questionId = questionId, transactionid = transactionid });
            }
            else
            {
                return(RedirectToAction("ShowVideo", "Home", new { SubChapID = SubChapID, questionId = questionId, exerciseId = exerciseId, transactionid = transactionid }));
            }
        }
        public ActionResult PaymentWithPaypal(string Cancel = null, string questionId = null)
        {
            //getting the apiContext
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PayPal/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    System.Guid guid1 = System.Guid.NewGuid();
                    var         guid  = guid1.ToString();
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, guid, int.Parse(questionId));
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid


                    string paymentXML = Utility.Serialize <Payment>(createdPayment);

                    PayPalManager payPalManager = new PayPalManager();

                    PayPalInvoiceModel model = new PayPalInvoiceModel();

                    model.InvoiceGUID = guid;
                    model.QuestionID  = int.Parse(questionId);
                    model.RequestXML  = paymentXML;
                    model.PaymentID   = createdPayment.id;

                    payPalManager.CreatePayPalInvoice(model);

                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    PayPalManager payPalManager = new PayPalManager();
                    // This function exectues after receving all parameters for the payment
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    var response        = Utility.Serialize <Payment>(executedPayment);


                    var invoice = payPalManager.GetPayPalInvoiceByGUID(guid);
                    invoice.State       = executedPayment.state;
                    invoice.ResponseXML = response;

                    payPalManager.UpdatePayPalInvoice(invoice);

                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }

                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("FailureView"));
            }
            //on successful payment, show success page to user.
            return(View("SuccessView"));
        }