Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone!

I have a query regarding to paypal ipn handler.
I was said to make such a stuff that user get automatically ipn data deleviry on notify_url enabled page from paypal. The aspx page will be on server.

I have configured my website on IIS, But I am not getting IPN data which I have to insert into database. I am not sending any request from website. I need to get redirected from paypal to my aspx web form when someony pay from website.

Following is a code
-----------------------------------
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Threading;
using System.Net;

public partial class paypal : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        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);

       
        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;

        
        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")
        {
            lblmc_gross.Text = Request.Form["mc_gross"].ToString();
            lblprotection_eligibility.Text = Request.Form["protection_eligibility"].ToString();
            lbladdress_status.Text = Request.Form["address_status"].ToString();
            lblpayer_id.Text = Request.Form["payer_id"].ToString();
            lbltax.Text = Request.Form["tax"].ToString();
            lbladdress_street.Text = Request.Form["address_street"].ToString();
            lblpayment_date.Text = Request.Form["payment_date"].ToString();
            lblpayment_status.Text = Request.Form["payment_status"].ToString();
            lblcharset.Text = Request.Form["charset"].ToString();
            lbladdress_zip.Text = Request.Form["address_zip"].ToString();
            lblfirst_name.Text = Request.Form["first_name"].ToString();
            lblmc_fee.Text = Request.Form["mc_fee"].ToString();
            lbladdress_country_code.Text = Request.Form["address_country_code"].ToString();

            lbladdress_name.Text = Request.Form["address_name"].ToString();
            lblnotify_version.Text = Request.Form["notify_version"].ToString();
            lblpayer_status.Text = Request.Form["payer_status"].ToString();

            lblbusiness.Text = Request.Form["business"].ToString();
            lbladdress_country.Text = Request.Form["address_country"].ToString();
            lbladdress_city.Text = Request.Form["address_city"].ToString();

            lblpayer_email.Text = Request.Form["payer_email"].ToString();
            lblpayer_email.Text = Request.Form["payer_email"].ToString();
            lbltxn_id.Text = Request.Form["txn_id"].ToString();

            lblpayment_type.Text = Request.Form["payment_type"].ToString();
            lbllast_name.Text = Request.Form["last_name"].ToString();
            lbladdress_state.Text = Request.Form["address_state"].ToString();

            lblreceiver_email.Text = Request.Form["receiver_email"].ToString();
            lblpayment_fee.Text = Request.Form["payment_fee"].ToString();
            lblreceiver_id.Text = Request.Form["receiver_id"].ToString();

            lbltxn_type.Text = Request.Form["txn_type"].ToString();
            lblitem_name.Text = Request.Form["item_name"].ToString();
            lblmc_currency.Text = Request.Form["mc_currency"].ToString();

            lblitem_number.Text = Request.Form["item_number"].ToString();
            lblresidence_country.Text = Request.Form["residence_country"].ToString();
            lbltest_ipn.Text = Request.Form["test_ipn"].ToString();

            lblhandling_amount.Text = Request.Form["handling_amount"].ToString();
            lbltransaction_subject.Text = Request.Form["transaction_subject"].ToString();
            lblpayment_gross.Text = Request.Form["payment_gross"].ToString();
            lblshipping.Text = Request.Form["shipping"].ToString();

        }
        else if (strResponse == "INVALID")
        {
            
        }
        else
        {  

        }
    }
}

I am sending this data using ajax post on a web service where i am inserting my data into database

Is this code right??????????
Posted
v2
Comments
[no name] 14-Aug-12 7:29am    
"Is this code right"... only you can answer that.
ZurdoDev 14-Aug-12 8:51am    
Have you tried running it?
sharmaravi123 16-Aug-12 4:26am    
Yes, I have tried running it, but when I write this code Request.Form["mc_gross"].ToString();
Ipn data not sent from paypal and web service not not called...

Actually I have to insert ipn data into invoice table.
How to get this data in
if (strResponse == "VERIFIED")
{

}
I want to get IPN data in VERIFY condition to insert.

[no name] 14-Aug-12 9:11am    
Why are you reposting this over and over?

1 solution

I dont know about your code, but I found a lot of interestiong stuff on the subject here:
PayPal articles[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900