title: Get response from paypal sandbox
body: <p>I am trying to integrate the paypal sandbox with my asp.net code. The requirement is that i have to take the user to the paypal site , the user will login with his credential and pay a designated amount. </p>
  
  <p>Now i am able to take the user to the paypal site and get the transaction done sucessfully as per my code below. My next step is to get the response from the paypal. In the response i require the status and also i will send an uniqueid while redirecting to the paypal site which i want in the response too so that my application can identify from which user the response has arrived.</p>
  
  <pre><code>private void PayJNP()
      {
          try
          {
              string redirectUrl = "";
              redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();
              redirectUrl += "&amp;first_name=ATPTrader";
              redirectUrl += "&amp;item_name=JNP";
              redirectUrl += "&amp;amount=100";
              redirectUrl += "&amp;return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
              redirectUrl += "&amp;cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
              Response.Redirect(redirectUrl);
          }
          catch (Exception Ex)
          {
  
          }
      }
  </code></pre>
  
  <p>Please help me to capture the response.</p>
  
  <p>TIA</p>
  
  <hr>
  
  <p>I have started implementing the IPN but i am getting some issues</p>
  
  <p>I have configured IPN in the paypal site </p>
  
  <p>From one from thru some hidden controls i am sending data to the paypal sandbox</p>
  
  <pre><code>&lt;form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="form1"
          name="form1"&gt;
          &lt;input type="hidden" name="cmd" value="_xclick"/&gt;
          &lt;input type="hidden" name="business" value="shantanusenin@gmail.com"/&gt;&lt;!--Paypal or sandbox Merchant account --&gt;
          &lt;input type="hidden" name="item_name" value="JNP"/&gt;
          &lt;input type="hidden" name="item_number" value="1"/&gt;
          &lt;input type="hidden" name="amount" value="100"/&gt;
          &lt;input type="hidden" name="return" value="http://alltradepartners.com/test/paypal.aspx"/&gt;&lt;!--this page will be your redirection page --&gt;
          &lt;input type="hidden" name="cancel_return" value="http://alltradepartners.com/test/partnerregistration.aspx"/&gt;
          &lt;input type="hidden" name="currency_code" value="USD"/&gt;
          &lt;input type="hidden" name="notify_url" value="http://alltradepartners.com/test/paypal.aspx"/&gt;&lt;!--this should be your domain web page where you going to receive all your transaction variables --&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>now i have a page which collects the response</p>
  
  <pre><code>//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 += "&amp;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
          StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
          streamOut.Write(strRequest);
          streamOut.Close();
          StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
          string strResponse = streamIn.ReadToEnd();
  
          streamIn.Close();
  
          if (strResponse == "VERIFIED")
          {
  
              Response.Write("VERIFIED");
              //UPDATE YOUR DATABASE
  
              //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
              //txWriter.WriteLine(strResponse);
              //txWriter.Close();
  
              //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
  
  
  
  
  
              NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse);
              string user_email = these_argies["payer_email"];
              string pay_stat = these_argies["payment_status"];
              //.
              //.  more args as needed look at the list from paypal IPN doc
              //.
  
  
              if (pay_stat.Equals("Completed"))
              {
                  Response.Write("Completed");
                  //Send_download_link("yours_truly@mycompany.com", user_email, "Your order", "Thanks for your order this the downnload link ... blah blah blah");
              }       
  
          }
          else if (strResponse == "INVALID")
          {
              Response.Write("INVALID");
              //UPDATE YOUR DATABASE
  
              //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
              //txWriter.WriteLine(strResponse);
              ////log for manual investigation
              //txWriter.Close();
          }
          else
          {
              Response.Write("SUCCESS");
              //UPDATE YOUR DATABASE
  
              //TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
              //txWriter.WriteLine("Invalid");
              ////log response/ipn data for manual investigation
              //txWriter.Close();
          }
  </code></pre>
  
  <p>Now i am able to send the request and getting the response as VERIFIED, but i am not getting the tranactionID. Please suggest where i am missing</p>
  
  <p>TIA</p>