Properly passing the transaction variables of Succesful PAYPAL back to
site (without clicking the Return to site link)
I've been searching for an answer and the IPN transaction variables are ok
on PayPal side however the transaction variables themselves do not post
back to my site.
<form method="post" id="Form1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="rxx.xxx@xxxx.com">
<input type="hidden" name="item_name" value="Auto Return Check">
<input type="hidden" name="item_number" value="1234">
<input type="hidden" name="amount" value=".64">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="showHostedThankyouPage" value="false">
<input type='hidden' name='notify_url'
value='http://xxxuser.somee.com/pdthandler.aspx' />
And my pdthandler.aspx which acts like notify_url (because IPN history are
all succesful/verified) looks like this (which I copied elsewhere)
string authToken, txToken, query, strResponse;
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();
// sanity check
Label2.Text = strResponse;
char fslash = (char) 47;
if (strResponse.StartsWith("SUCCESS"))
{
if ((String.IsNullOrEmpty(txToken)) || txToken == "")
txToken = "success";
str_ = "?PayPalTransactionID=" + txToken + "&OrderID=" +
HttpContext.Current.Session["OrderID"] + "";
str_ = "http://returntomysite.com/Heresyourorder.aspx" + str_;
//I've tried redirect does not work as well :'(
//Response.Redirect(str_);
str_1 = "<script src=\"http://code.jquery.com/jquery-1.9.0.js\"><" +
fslash + "script>";
str_1 += "<script>" +
"$(document).ready(function () { " +
" var url = '"+str_+"'; " +
" $(location).attr('href', url); " +
" }); " +
"<" + fslash + "script>";
//Response.Write("<" + Convert.ToChar(2F) + "script>");
Response.Write(str_1);
}
else
{
Label1.Text = "Oooops, something went wrong...";
}
Now there's no problem with PayPal the IPN history seems ok but the
problem is either one of the redirects below does not take me back to my
site.
I've tried auto-return URL and that only works with Paypal account not
credit card payments.
And for everyone's reference I tried
4. http://forums.asp.net/t/1764224.aspx
5. https://github.com/paypal/pdt-code-samples/blob/master/PDT-aspnet.txt
6.
https://www.paypal-community.com/t5/How-to-use-PayPal-Archive/return-the-transaction-id-back-to-my-website/td-p/34542
How it works: * If the buyer pays with a PayPal account, they are
automatically taken back to the site.
If the buyer pays with the Credit Card Option, they are taken to the
receipt page where PayPal gives them the chance to print out a receipt.
This is a legal requirement. After that, the buyer must click on the
"Return to Merchant" link in order to return to the site.
Any help and I will be grateful I think it has been weeks that I can't
solve this. Thank you very much. God bless all
No comments:
Post a Comment