protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // Used parts from https://www.paypaltech.com/PDTGen/
            // Visit above URL to auto-generate PDT script

            authToken = WebConfigurationManager.AppSettings["PDTToken"];

            //read in txn token from querystring
            txToken = Request.QueryString.Get("tx");

            query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken);

            // Create the request back
            string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"];
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            // Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;

            // Write the request back IPN strings
            StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(query);
            stOut.Close();

            // Do the request to PayPal and get the response
            StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
            strResponse = stIn.ReadToEnd();
            stIn.Close();
            string CustomerID = GetCustomerID();

             PDTHolder pdt = PDTHolder.Parse(strResponse);

                CustomerPDTDataSetTableAdapters.CustomerStartingPaymentTableAdapter CustomerPDTAdapter = new CustomerPDTDataSetTableAdapters.CustomerStartingPaymentTableAdapter();
                CustomerPDTDataSet.CustomerStartingPaymentDataTable CustomerPDTTable = new CustomerPDTDataSet.CustomerStartingPaymentDataTable();
                CustomerPDTAdapter.FillVerifyTransaction(CustomerPDTTable, Convert.ToInt32(pdt.Custom));

            // If response was SUCCESS, parse response string and output details
            //The payment is succesful
            if (strResponse.StartsWith("SUCCESS"))
            {
                           //If there is no match
                //The customer close the windows.

                //If There is a match
                //The customer return back to the confirmation page.

                foreach (DataRow row in CustomerPDTTable)
                {
                    CustomerPDTDataSetTableAdapters.QueriesTableAdapter CustomerPDT = new CustomerPDTDataSetTableAdapters.QueriesTableAdapter();

                    if (pdt.Custom.ToString() == row["ProjectID"].ToString() && pdt.Currency.ToString() == row["CurrencyCode"].ToString() && (row["Amount"].ToString() == pdt.GrossTotal.ToString()))
                    {
                        //Insert it only 1 time
                        ////Sucessful PDT////
                        CustomerPDTDataSetTableAdapters.CustomerSuccessfulPDTTableAdapter CustomerSuccessfulPDTAdapter = new CustomerPDTDataSetTableAdapters.CustomerSuccessfulPDTTableAdapter();
                        CustomerPDTDataSet.CustomerSuccessfulPDTDataTable CustomerSuccessfulPDTTable = new CustomerPDTDataSet.CustomerSuccessfulPDTDataTable();
                        CustomerSuccessfulPDTAdapter.FillCustomerSuccededPDT(CustomerSuccessfulPDTTable, Convert.ToInt32(CustomerID), Convert.ToInt32(pdt.Custom.ToString()));

                        if (CustomerSuccessfulPDTTable.Rows.Count == 0)
                        {
                            CustomerPDT.SuccessPDT(pdt.GrossTotal, pdt.InvoiceNumber, pdt.PaymentStatus, pdt.PayerFirstName, pdt.PayerLastName, pdt.PaymentFee, pdt.BusinessEmail, txToken
                     , pdt.ReceiverEmail, pdt.ItemName, pdt.Currency, pdt.TransactionId, pdt.Custom, "no subscriber", Convert.ToInt32(CustomerID), Convert.ToInt32(pdt.Custom));

                            CustomerPDT.AddCustomerPendingTransaction(Convert.ToInt32(CustomerID),
                                                                      Convert.ToInt32(pdt.Custom));

                            string sucessmessage = pdt.PayerFirstName + " " +
                                pdt.PayerFirstName + "<br/>";
                            sucessmessage += Resources.Resource.PaymentOf + " ";
                            sucessmessage += pdt.Currency + " " + pdt.GrossTotal +
                                Resources.Resource.PaymentProcessed + "<br/>";
                            sucessmessage += Resources.Resource.Sincerely + "<br/>";
                            sucessmessage += Resources.Resource.YourSideJobTeam + "<br/>";
                        }
                        else
                        {
                            HiddenLabel.Text = Resources.Resource.AlreadyPaid;
                        }
                    }
                    else
                    {
                        //Potential Hack
                        CustomerPDT.HackedPDT(pdt.GrossTotal, pdt.InvoiceNumber, pdt.PaymentStatus, pdt.PayerFirstName, pdt.PayerLastName, pdt.PaymentFee, pdt.BusinessEmail, txToken
                          , pdt.ReceiverEmail, pdt.ItemName, pdt.Currency, pdt.TransactionId, pdt.Custom, "no subscriber", Convert.ToInt32(CustomerID), Convert.ToInt32(pdt.Custom));

                        //Email The Hacker and Admin
                        string failuremessage = pdt.PayerFirstName + " " +
                                pdt.PayerFirstName + "<br/>";
                        failuremessage += Resources.Resource.FailedTransaction + "<br/>";
                        failuremessage += Resources.Resource.FailurePDT;
                        HiddenLabel.Text = failuremessage;

                    }

                }
            }
            else
            {
                string failuremessage = pdt.PayerFirstName + " " +
                                 pdt.PayerFirstName + "<br/>";
                failuremessage += Resources.Resource.FailedTransaction + "<br/>";
                failuremessage += Resources.Resource.FailurePDT;
                HiddenLabel.Text = failuremessage;
            }
        }
    }
Example #2
0
    protected void PayPalImageButton_Click(object sender, ImageClickEventArgs e)
    {
        const string Server_URL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        const string return_URL = "http://www.haithem-araissia.com/WIP2/RightCleanSideJOB2008FromInetpub/CleanSIDEJOB2008/Authenticated/Customer/Paypal/PDTSuccess.aspx";
        const string cancelreturn_URL = "http://www.haithem-araissia.com/WIP2/RightCleanSideJOB2008FromInetpub/CleanSIDEJOB2008/Authenticated/Customer/Paypal/CancelPayment.aspx";
        const string notify_url = "http://www.haithem-araissia.com/WIP2/RightCleanSideJOB2008FromInetpub/CleanSIDEJOB2008/Authenticated/Customer/Paypal/Handler.aspx";
        const string cmd = "_xclick";

        CustomerPDTDataSet.CustomerPaymentDueDataTable CustomerPaymentDueTable;
        GetValue(out CustomerPaymentDueTable);
        const string business = "*****@*****.**";
        string item_name = CustomerPaymentDueTable.Rows[0]["ProjectTitle"].ToString();
        string project_id = Request.QueryString["ID"].ToString();
        string customer_id = GetCustomerID();

        if (PaymentMade(customer_id, project_id) == false)
        {
            string redirect = "";
            redirect += Server_URL;
            redirect += "?cmd=" + cmd;
            redirect += "&business=" + business;
            redirect += "&item_name=" + item_name;
            redirect += "&amount=" + Amount.Text.ToString();
            redirect += "&currency_code=" + CurrencyDropDownList.SelectedValue.ToString();
            redirect += "&payer_id=" + customer_id.ToString();
            redirect += "&receiver_email=" + "*****@*****.**";
            redirect += "&custom=" + project_id;
            redirect += "&notify_url" + notify_url;
            redirect += "&return=" + return_URL;
            redirect += "&cancel_return" + cancelreturn_URL;

            CustomerPDTDataSetTableAdapters.QueriesTableAdapter CustomerPDT = new CustomerPDTDataSetTableAdapters.QueriesTableAdapter();
            CustomerPDT.CustomerStartPayment(Convert.ToInt32(project_id), Convert.ToDouble(Amount.Text.ToString()), CurrencyDropDownList.SelectedValue.ToString(), Convert.ToInt32(customer_id));

            //Redirect to the payment page
            Response.Redirect(redirect);
        }
    }