0

Hi,

I am developing a web-site where user can purchase items and pay through PAYPAL.

Its working fine on test and all the payment processing is working well. But aI want to update my database after succesful payment and for that I have created one THANKS.ASPX page where I fetch the response and if it is verified that update the database and also it working fine.

After redirect to paypal and successful patment I received page from Paypal site for successful payment where transaction ID and other information are displayed.

There is a link in paypal page called "Return to Merchant Test Score" and when user click on the link it redirects to my Thanks.aspx where I fetch the response and if verified the update the database.

For Automatic redirection :-

I am able to redirect user to my web-site from paypal after setting the "AutoReturn" to true and specify the URL.


Now another problem is that when "AutoReturn" is true and url is specified I receive the response as INVALID and If I again set the "AutoReturn" to false and after payment user click on the link "Return to Merchant" then I received the response as VALID.

Please let me know where I am wrong?

Below is my code:-

1) Redirect User from my web-site to Paypal for payment

Response.Redirect("Paypal.aspx?" + "business=" + objDb.paypalemailid + "&quantity=" + Qty + " &item_name=" + prodname + "&item_number=" + ID + "&amount=" + Rate + "&no_shipping=1&return=" + objDb.UrlBasePay() + "Thanks.aspx&cancel_return=" + objDb.UrlBasePay() + "Default.aspx&notify_url=" + objDb.UrlBasePay() + "IPNValidatorTestAnalysis.aspx&cn=How+did+you+hear+about+us%3F&currency_code=USD");

2) My paypal.aspx:-

<%@ 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>  Payment   </title>
</head>
<body>
    <%--<form action="<%= Connect.PayPalRequestPath %>" method="post" name="PayPalForm">--%> <%-- <%=System.Web.Configuration.WebConfigurationManager.AppSettings["PayPalRequestPath"] %>--%>
   
		<form action="<%=System.Web.Configuration.WebConfigurationManager.AppSettings["PayPalRequestPath"] %>"
		method="post" name="PayPalForm">
		<input type="hidden" name="cmd" value="_xclick" />
		<input type="hidden" name="business" value="<%= Request.QueryString["business"]%>" />
			<input type="hidden" name="quantity" value="<%=Request.QueryString["quantity"]%>" />
			<input type="hidden" name="item_name" value="<%=Request.QueryString["item_name"]%>" />
			<input type="hidden" name="item_number" value="<%=Request.QueryString["item_number"]%>"/>
			<input type="hidden" name="amount"  value="<%=Request.QueryString["amount"]%>"/>
			<input type="hidden" name="no_shipping" value="<%=Request.QueryString["no_shipping"]%>" />
			<input type="hidden" name="return"  value="<%=Request.QueryString["return"]%>?item_number=<%=Request.QueryString["item_number"]%>" />
			<input type="hidden" name="cancel_return" value="<%=Request.QueryString["cancel_return"]%>" />
			<input type="hidden" name="notify_url"  value="<%=Request.QueryString["notify_url"]%>" />
			<input type="hidden" name="cn"  value="<%=Request.QueryString["cn"]%>" />
			<input type="hidden" name="currency_code" value="<%=Request.QueryString["currency_code"]%>" />					
		</form>
		 <script type="text/javascript" language="JavaScript">
  document.PayPalForm.submit();  
</script>

</body>
</html>

3) Redirect user to my web-site from Paypal and check the response.my Thanks.aspx.

If response is valid then update the databse.

string PayPalEmailId = System.Web.Configuration.WebConfigurationManager.AppSettings["paypalAccount"];
        
        string PayPalRequestPath = Convert.ToString(System.Web.Configuration.WebConfigurationManager.AppSettings["PayPalRequestPath"]);
        if (!IsPostBack)
        {
            //'Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest) 
            CreateLog();
            //' to maintain the log 
            StepByStepLog("start:", DateTime.Now.ToString() + "----------------------------------------------------------");

            //GolfConfiguration.PayPalRequestPath

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(System.Web.Configuration.WebConfigurationManager.AppSettings["PayPalRequestPath"].ToString());

            //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 = strRequest + "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;

            StepByStepLog("request To paypal:", strRequest);


            //Send the request to PayPal and get the response 

            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();

            StepByStepLog("response from paypal:", strResponse);

            WriteRequestFormVariables(Request.Form);
            if (Request.QueryString["Res"] != null)
            {
                strResponse = Request.QueryString["Res"].ToString();
            }

            if (strResponse == "VERIFIED" || strResponse == "Free")
            {
   else
            {
               
            }
}
    }

ABOVE CODE IS WORKING FINE IF THE AUTO-RETURN IS FALSE ( RECEIVED THE RESPONSE AS "VALID" in THANKS.ASPX), BUT WHEN AUTO-RETURN TRUE ( REQUIRED TO AUTOMATICALLY REDIRECT USER TO MY WEB_SITE FROM PAYPAL) IT IS NOT WORKING ( ALWAYS RECEIVED THE RESPONSE AS "INVALID" IN THANKS.ASPX).

Thanks and Regards.

Prashant Trivedi

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by PierlucSS
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.