hello,
in my asp.net application i use paypal for payment its all thing working fine
but IPN not working in website i mean i am not get IPN info from paypal
but if i test IPN.aspx in IPN simulater its working fine coz in IPN.aspx i maintain a log.txt file or database entry its working fine
from IPN simulator but when i pay from website and its all thing workin but i am not get anything in IPN.aspx
so anybody give me some idea or info about IPN
thanks
Loading

Ajitender VijayPosted Jan 3, 2012, 4:02 AM
Please visit this link https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_code_ipn_code_samples
thanks
Ajitender vijay
Dharmesh SharmaPosted Jan 3, 2012, 3:51 AM
i have used this code earlior
but that code not work in IPN simulator test as well
ok let me try again
so can you tell me how to get all values like my code for database entry or log creating for testing that my IPN.aspx page get value or not on server
then i ll test on IPN simulator......
thanks
Anuja PawarPosted Jan 3, 2012, 3:13 AM
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
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")
{
//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")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
Dharmesh SharmaPosted Jan 3, 2012, 2:59 AM
but i have allready check this link i give you my code so please check if i make any mistak cos
all setting i done in paypal sandbox
so please check this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Text;
using System.Configuration;
using System.Net;
using System.IO;
using System.Data;
public partial class IPNHandler : System.Web.UI.Page
{
private string business = ConfigurationManager.AppSettings["BusinessEmail"];
private string currency_code = ConfigurationManager.AppSettings["CurrencyCode"];
static DataSet requests = new DataSet();
static DataSet responses = new DataSet();
connection con = new connection();
protected void Page_Load(object sender, EventArgs e)
{
CultureInfo ci = new CultureInfo("en-us");
string strFormValues = Encoding.ASCII.GetString(Request.BinaryRead(Request.ContentLength));
string strNewValue;
// getting the URL to work with
string URL = null;
if (ConfigurationManager.AppSettings["UseSandbox"].ToString() == "true")
{
URL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
else
{
URL = "https://www.paypal.com/cgi-bin/webscr";
}
// Create the request back
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;
// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();
//send the request, read the response
HttpWebResponse strResponse = (HttpWebResponse)req.GetResponse();
Stream IPNResponseStream = strResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(IPNResponseStream, encode);
Char[] read = new Char[257];
// Reads 256 characters at a time.
int count = readStream.Read(read, 0, 256);
while (count > 0)
{
// Dumps the 256 characters to a string
String IPNResponse = new String(read, 0, count);
count = readStream.Read(read, 0, 256);
string amount = null;
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
provider.NumberGroupSeparator = ",";
provider.NumberGroupSizes = new int[] { 3 };
// if the request is verified
if (IPNResponse == "VERIFIED")
{
// check the receiver's e-mail (login is user's identifier in PayPal) and the transaction type
if (Request["receiver_email"] != business | Request["txn_type"] != "web_accept")
{
try
{
// parameters are not correct. Write a response from PayPal and create a record in the Log file.
CreatePaymentResponses(Request["txn_id"], Request["mc_gross"], Request["payer_email"], Request["first_name"], Request["last_name"], Request["address_street"], Request["address_city"], Request["address_state"], Request["address_zip"], Request["address_country"], Request["custom"], "True", "", "Paid");
StreamWriter log;
if (!File.Exists(Server.MapPath("log.txt")))
{
log = new StreamWriter(Server.MapPath("log.txt"));
}
else
{
log = File.AppendText(Server.MapPath("log.txt"));
}
// Write to the file:
log.WriteLine(DateTime.Now);
log.WriteLine(strResponse);
log.WriteLine("IPN Log " + Request["txn_id"].ToString() + "," + Request["mc_gross"].ToString() + "," + Request["payer_email"] + "," + Request["first_name"] + "," + Request["last_name"] + "," + Request["address_street"] + "," + Request["address_city"] + "," + Request["address_state"] + "," + Request["address_zip"] + "," + Request["address_country"] + "," + Request["custom"] + "," + "INVALID paymetn's parameters (receiver_email or txn_type)" + Request["custom"]);
// Close the stream:
log.Close();
}
catch (Exception ex)
{
StreamWriter log;
if (!File.Exists(Server.MapPath("log.txt")))
{
log = new StreamWriter(Server.MapPath("log.txt"));
}
else
{
log = File.AppendText(Server.MapPath("log.txt"));
}
// Write to the file:
log.WriteLine(DateTime.Now);
log.WriteLine("IPN Error:" + ex.Message);
// Close the stream:
log.Close();
}
readStream.Close();
strResponse.Close();
return;
}
// check whether this request was performed earlier for its identifier
//if (IsDuplicateID(Request("txn_id")))
//{
// // the current request is processed. Write a response from PayPal and create a record in the Log file.
// CreatePaymentResponses(Request("txn_id"), Convert.ToDecimal(Request("mc_gross"), provider), Request("payer_email"), Request("first_name"), Request("last_name"), Request("address_street"), Request("address_city"), Request("address_state"), Request("address_zip"), Request("address_country"),
// Convert.ToInt32(Request("custom")), false, "Duplicate txn_id found");
// KBSoft.Carts.WriteFile("Error in IPNHandler: Duplicate txn_id found");
// readStream.Close();
// strResponse.Close();
// return;
//}
// the amount of payment, the status of the payment, amd a possible reason of delay
// The fact that Getting txn_type=web_accept or txn_type=subscr_payment are got odes not mean that
// seller will receive the payment.
// That's why we check payment_status=completed. The single exception is when the seller's account in
// not American and pending_reason=intl
//if (Request("mc_gross").ToString(ci) != amount | Request("mc_currency") != currency_code | (Request("payment_status") != "Completed" & Request("pending_reason") != "intl"))
//{
// // parameters are incorrect or the payment was delayed. A response from PayPal should not be
// // written to DB of an XML file
// // because it may lead to a failure of uniqueness check of the request identifier.
// // Create a record in the Log file with information about the request.
// KBSoft.Carts.WriteFile("Error in IPNHandler: INVALID paymetn's parameters. Request: " + strFormValues);
// readStream.Close();
// strResponse.Close();
// return;
//}
//try
//{
// // write a response from PayPal
// CreatePaymentResponses(Request("txn_id"), Convert.ToDecimal(Request("mc_gross"), provider), Request("payer_email"), Request("first_name"), Request("last_name"), Request("address_street"), Request("address_city"), Request("address_state"), Request("address_zip"), Request("address_country"),
// Convert.ToInt32(Request("custom")), true, "");
// KBSoft.Carts.WriteFile("Success in IPNHandler: PaymentResponses created");
// ///''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// // Here we notify the person responsible for goods delivery that
// // the payment was performed and providing him with all needed information about
// // the payment. Some flags informing that user paid for a services can be also set here.
// // For example, if user paid for registartion on the site, then the flag should be set
// // allowing the user who paid to access the site
// ///''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//}
//catch (Exception ex)
//{
// KBSoft.Carts.WriteFile("Error in IPNHandler: " + ex.Message);
//}
}
else
{
}
}
readStream.Close();
strResponse.Close();
}
public void CreatePaymentResponses(string txn_id, string payment_price, string email, string fname, string lname, string street, string city, string state, string zip, string country, string invocieid, string is_sucess, string reason_fault, string status)
{
con.Update_invocie_after_payment(invocieid, txn_id, payment_price, email, status, reason_fault);
}
}
and all thing on server i am not work on local
and this code work when i test IPN simulator
so please help me its too frustating
Anuja PawarPosted Jan 3, 2012, 2:48 AM
I suggest read this article
http://www.getcoderocket.com/Support/PayPalIPNHandler
http://www.codeproject.com/KB/aspnet/UsePayPalPaymentInASPNET.aspx
Dharmesh SharmaPosted Jan 3, 2012, 2:30 AM
as i am already said that my IPN.aspx page work for IPN Simulator and i am able to get this request coz in this ipn.aspx page i manage log fine and database entry and its work when i test IPN simulator
but when i pay payment by website then i am not get any log file change and database entry
and i am enable the IPN in business account of sendbox and add the IPN.aspx URL in this account
but its not working on server
so we can talk more if you free on skype or gmail
my id is [email protected]
[email protected]
please give me email to contact to you
Ajitender VijayPosted Jan 3, 2012, 1:16 AM
Config your IPN page in paypal Instant Payment Notification simulator see below image. it's not work at local environment
Regards
Ajitender vijay