locked
Issues with PayPal Sandbox testing again??? RRS feed

  • Question

  • User-631683198 posted

    hi,
    My paypal IPN was working fine a few months ago in text situation using sandbox.Now i tried again and seem to be getting invalid everytime. So after payment my

    SQL database is not updated with transaction details. but if I check test account

    on paypal sandbox it shows completed transactions.

    Has anyone come across similar issues and am i misssing something. - i tried on paypal forum but

    maybe someone knows here.?

    It has previously been errors in creating sandbox test account for business and buyer.

    for example - In my site account -  I have specified 3 currencies .- USD- EUROS and GBP. - GBP is set as primary as i am non US developer.

    Do I setup test buyer account originating in Uk

    Also do I create business test account as well from UK

    I have followed Paypal forum and made sure of following

     //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";

    here is a small code snippet

    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.sandbox.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;
            string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
    
            //Send the request to PayPal and get the response
    
    
    
    
            //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")
            {
    
    
                NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
    
                string pay_stat = these_argies["payment_status"];
    
                //.
                //.  more args as needed look at the list from paypal IPN doc
                //.
    
    
                if (pay_stat.Equals("Completed"))
                {
    
    
    
                    string txnid = Server.HtmlEncode(Request.Form["txn_id"]);
                    string txnid1 = Server.HtmlEncode(Request.Form["item_name"]);
                    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 invoice = Server.HtmlEncode(Request.Form["invoice"]); // this is where i get my member's email adress
    
    
    
    
    
    
                    string user_email1 = these_argies["payer_email"];
                    string receiv_email1 = these_argies["receiver_email"];
                    string cust = these_argies["custom"];
                    string tran = these_argies["item_name"];
                    string tx = these_argies["txn_id"];
                    string st = these_argies["payment_status"];
                    string inv = these_argies["invoice"];
    
                    SqlConnection conn = new SqlConnection("Data Source=esql2k1201.discountasp.net;Initial Cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    
    
    
    
                    string insertsql = "INSERT INTO PAYPAL (payer_email,receiver_email,BuyerId,item_name,txn_id,payment_status) VALUES (@payer_email, @receiver_email, @BuyerId, @item_name,@txn_id,@payment_status)";
    
    
                    conn.Open();
                    SqlCommand mycommand = new SqlCommand(insertsql, conn);
                    mycommand.Parameters.AddWithValue("@payer_email", user_email1);
                    mycommand.Parameters.AddWithValue("@receiver_email", receiv_email1);
                    mycommand.Parameters.AddWithValue("@BuyerId", cust);
                    mycommand.Parameters.AddWithValue("@item_name", tran);
                    mycommand.Parameters.AddWithValue("@txn_id", tx);
                    mycommand.Parameters.AddWithValue("@payment_status", st);
    
                    mycommand.ExecuteNonQuery();
                    conn.Close();
    
    
    
    
    
                    SqlConnection conn3 = new SqlConnection("Data Source=esql2k1201.discountasp.net;Initial Catalog=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    
    
                    SqlCommand command = new SqlCommand("UPDATE PlayMe.Booking SET Confirmed=1 WHERE Validation=@Validation", conn3);
    
                    command.Parameters.AddWithValue("@Validation", inv);
    
                    conn3.Open();
                    command.ExecuteNonQuery();
                    conn3.Close();
    

     
        <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="info-facilitator@mycompany.com"/><!--Paypal or sandbox Merchant account -->
            <input type="hidden" name="item_name" value="Donate"/>
            <input type="hidden" name="custom" value="<%=Session["client"]%>"/><!--Custom Field for payer email -->
            <input type="hidden" name="item_number" value="1"/>
            <input type="hidden" name="amount" value="<%=Session["Fee"]%>"/>
            <input type="hidden" name="return" value="http://www.xxxxxxxxxxxxxxxxxxx"/><!--this page will be your redirection page -->
            <input type="hidden" name="cancel_return" value="xxxxxxxxxxxxxxxxxxxxxxxx"/>
            <input type="hidden" name="currency_code" value="<%=Session["currency"]%>"/>
             <input type="hidden" name="invoice" value="<%=Session["uniqueGuid"].ToString()%>"/>
            <input type="hidden" name="notify_url" value="xxxxxxxxxxxxxxxx/><!--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>
        </div>

    I

    Saturday, April 23, 2016 12:46 PM

Answers

  • User-631683198 posted

    in case this helps anyone out there i had to add the below before calling web request...as paypal was always getting error

    Exception Details: System.Net.WebException: The request was aborted: Could
    not create SSL/TLS secure channel.

     System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


            //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;
            string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;

            //Send the request to PayPal and get the response




            //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")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 25, 2016 5:57 PM