Results 1 to 9 of 9

Thread: [RESOLVED] Return Variable from Paypal (Sandbox) ASP.NET

  1. #1

    Thread Starter
    Member dionisis's Avatar
    Join Date
    Feb 2011
    Posts
    52

    Resolved [RESOLVED] Return Variable from Paypal (Sandbox) ASP.NET

    Hi all,

    I would like paypal (after customers subscription) to return some values. Here is my scenario…
    • The user visits my subscription web page and fills email (i will use email as username) and password textboxes.
    • He clicks on paypal button and he is redirected to paypal page.
    • When the transaction is completed he is returning back to my succes registration page.
    • When my registration page loads I create the user in my membership database.

    This actually means that from the registration page till succes registration page I must carry with me the email and password. In paypal I can define some hiden advanced variables but I cant find any examples of how I can return these values to my site.
    • First of all I want to know if my subscription procedure is correct or do I have to do this in some other way..?
    • Can paypal return values to my site and how. I am looking for some code example.


    Thank you..

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Hi.I geia xara kalitera.
    Too busy these days to answer but i have written some instructions in an older post.
    http://www.vbforums.com/showthread.php?t=641087
    Also you can visit www.x.com that is the official paypal help site and ask questions.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3

    Thread Starter
    Member dionisis's Avatar
    Join Date
    Feb 2011
    Posts
    52

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    gia sou patrida...
    thanks for your post.. i 'll take a look...

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Hello,

    Were you able to get an answer to your problem?

    If so, you might like to think about posting it so that others can learn as well.

    Thanks

    Gary

  5. #5

    Thread Starter
    Member dionisis's Avatar
    Join Date
    Feb 2011
    Posts
    52

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Actually yes, i have found an answer.. As i am in test mode, i'l come back later and describe what i've done..

    Nothing would came out without your help..!!

    Thank you guys..!

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Sounds good, let us know how you get on.

    Gary

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Great!Just don't forget to do the "trick" to charge extra on paypal
    Ok i'm joking don't rep bad.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    Quote Originally Posted by sapator View Post
    Great!Just don't forget to do the "trick" to charge extra on paypal
    Ok i'm joking don't rep bad.
    It was close, I almost did

  9. #9

    Thread Starter
    Member dionisis's Avatar
    Join Date
    Feb 2011
    Posts
    52

    Re: Return Variable from Paypal (Sandbox) ASP.NET

    All I want to do is to return the email of the user that completes pay transaction… I found this demo over the web but I cant find the link…

    don't forget to create paypall sandbox account

    So I will need three pages

    1. Default.aspx for filling the user email adress and the amount to be send to paypal.
    2. Sendpayment.aspx .Sends the data to paypall
    3. Paypal .aspx. It is a listener that “listens” paypall transaction status.

    • Default.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            Amount<br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />email<br />
            <asp:TextBox ID="email" runat="server"></asp:TextBox>
            <hr />
            <asp:Button ID="Button1" runat="server" Text="PayNow" OnClick="Button1_Click" /></div>
        </form>
    </body>
    </html>
    Code:
    using System.IO;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["totalShoppingAmt"] = TextBox1.Text;
            Session["regemail"] = email.Text;
            Session["orderID"] = string.Format("{0:d7}", (DateTime.Now.Ticks / 10) % 10000000);
            Response.Redirect("sendpayment.aspx");
        }
    }

    • SendPayment


    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="sendpayment.aspx.cs" Inherits="sendpayment" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
    <!--form action for live transaction https://www.paypal.com/cgi-bin/webscr-->
        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="form1"
            name="form1">
            <input type="hidden" name="cmd" value="_xclick"/>
            <input type="hidden" name="business" value="[email protected] "/><!--Paypal or sandbox Merchant account -->
            <input type="hidden" name="item_name" value="<%=Session["orderID"]%>_Books"/>
            <input type="hidden" name="custom" value="<%=Session["regemail"]%>"/><!--Custom Field for payer email -->
            <input type="hidden" name="item_number" value="1"/>
            <input type="hidden" name="amount" value="<%=Session["totalShoppingAmt"]%>"/>
            <input type="hidden" name="return" value="http://sitename.com/thanks.aspx"/><!--this page will be your redirection page -->
            <input type="hidden" name="cancel_return" value="http://sitename.com/cancel.aspx"/>
            <input type="hidden" name="currency_code" value="EUR"/>
            <input type="hidden" name="notify_url" value="http://sitename.com/paypal.aspx"/><!--this should be your domain web page where you going to receive all your transaction variables -->
        </form>
    
        <script type="text/jscript">
       document.form1.submit();   
        </script>
    
    </body>
    </html>
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class sendpayment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    }
    • paypal

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="paypal.aspx.cs" Inherits="paypal" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
        </div>
        </form>
    </body>
    </html>
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Net;
    
    
    public partial class paypal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            // string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
    
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
    
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
    
            //Send the request to PayPal and get the response
            
            string txnid = Server.HtmlEncode(Request.Form["txn_id"]);
            string receiv_email =Server.HtmlEncode(Request.Form["receiver_email"]);
            string business = Server.HtmlEncode(Request.Form["business"]);
            string payer_email=Server.HtmlEncode(Request.Form["payer_email"]);
            string tnx_type =Server.HtmlEncode(Request.Form["txn_Type"]);
            string payment_type = Server.HtmlEncode(Request.Form["payment_type"]);
            string payment_stat=Server.HtmlEncode(Request.Form["payment_status"]);
            string regemail=Server.HtmlEncode(Request.Form["custom"]); // this is where i get my member's email adress
    
            string constr = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
            string insertsql = "INSERT INTO databasename.dbo.tnx_paypal (txn_id, receiver_email, business, payer_email, tnx_type, payment_status,LocalDate,payment_type,regemail) values('" + txnid + "','" + receiv_email + "','" + business + "','" + payer_email + "','" + tnx_type + "','" + payment_stat + "','" + DateTime.Now.ToString() + "','" + payment_type + "','" + regemail +"')";
            using (SqlConnection myConnection = new SqlConnection(constr))
            {
                myConnection.Open();
                SqlCommand mycommand = new SqlCommand(insertsql, myConnection);
    
                mycommand.ExecuteNonQuery();
                myConnection.Close();
            }
    
            // for testing purposes i did not create any ipn status actions as i wanted to record every paypal status.
            if (strResponse == "VERIFIED")
    
            {
                //UPDATE YOUR DATABASE
    
    
    
                //check the payment_status is Completed
                //check that txn_id has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment
    
            }
            else if (strResponse == "INVALID")
            {
                //UPDATE YOUR DATABASE
    
    
            }
            else
            {  //UPDATE YOUR DATABASE
    
            }
        }
    }
    I wish it will be helpfull...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width