IPN for paypal in C#

Last post 09-29-2009 9:29 AM by Roly67. 6 replies.

Sort Posts:

  • IPN for paypal in C#

    11-22-2002, 6:06 PM
    Here is the code i use to integrate my .NET store with PayPal in C#. This will respond to Paypal IPN Update a transaction on your DB (you have to create a new table on your DB for the IPN variables and a new procedure to add the transaction in a ..\components\*.cs file) and sends you an email with the transaction. change the email address at the
    bottom of the page that says "sales@yourdomain.com" to your sales sender address. you can also test it at www.eliteweaver.com. I copied and pasted this from my transaction file and the formatting has gone a bit wild but if you copy and paste it into a .net page it should be OK.

    <%@ Page Language="C#" %>
    <%@ import Namespace="System.Net" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.Web.Mail" %>
    <script runat="server" >

    String CmdString, objHttp, OrderID, Txn_id, Payment_status, Receiver_email, Item_name,
    Item_number, Quantity, Invoice, Custom,
    Payment_gross, Payer_email, Pending_reason, Payment_date, Payment_fee,
    Txn_type, First_name, Last_name, Address_street, Address_city, Address_state,
    Address_zip, Address_country, Address_status, Payer_status, Payer_id, Payment_type,
    Notify_version, Verify_sign, Subscr_date, Period1, Period2, Period3,
    Amount1, Amount2, Amount3, Recurring, Reattempt, Retry_at, Recur_times,
    Username, Password, Subscr_id, response;


    private void Page_Init(object sender, System.EventArgs e)
    {
    string stringPost = Request.Form.ToString();
    // assign posted variables to local variables
    Txn_id = Request.Form["txn_id"];
    Receiver_email = Request.Form["receiver_email"];
    Item_name = Request.Form["item_name"];
    Item_number = Request.Form["item_number"];
    Quantity = Request.Form["quantity"];
    Invoice = Request.Form["invoice"];
    Custom = Request.Form["custom"];
    Payment_status = Request.Form["payment_status"];
    Pending_reason = Request.Form["pending_reason"];
    if(Payment_status != "Pending")
    {
    Pending_reason = " ";
    }
    Payment_date = Request.Form["payment_date"];
    Payment_fee = Request.Form["payment_fee"];
    Payment_gross = Request.Form["payment_gross"];
    Txn_type = Request.Form["txn_type"];
    First_name = Request.Form["first_name"];
    Last_name = Request.Form["last_name"];
    Address_street = Request.Form["address_street"];
    Address_city = Request.Form["address_city"];
    Address_state = Request.Form["address_state"];
    Address_zip = Request.Form["address_zip"];
    Address_country = Request.Form["address_country"];
    Address_status = Request.Form["address_status"];
    Payer_email = Request.Form["payer_email"];
    Payer_status = Request.Form["payer_status"];
    Payer_id = Request.Form["payer_id"];
    Payment_type = Request.Form["payment_type"];
    Notify_version = Request.Form["notify_version"];
    Verify_sign = Request.Form["verify_sign"];

    // post to paypal and await response : use: "https://www.paypal.com/cgi-bin/webscr" for real;
    // use: "http://www.eliteweaver.co.uk/testing/ipntest.php" to test;

    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");
    httpWebRequest.Method = "POST";
    // length plus 21 because &cmd=_notify-validate is 21 chars long
    httpWebRequest.ContentLength = stringPost.Length + 21;
    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
    StreamWriter streamWriter = null;
    streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
    stringPost = stringPost + "&cmd=_notify-validate";
    streamWriter.Write(stringPost);
    streamWriter.Close();
    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
    {
    response = streamReader.ReadToEnd();
    streamReader.Close();
    }

    // Step 1c: Process the response from PayPal.
    if (httpWebResponse.StatusCode != HttpStatusCode.OK )
    {
    // an error has occurred
    MailUsTheOrder("Status Error: " + httpWebResponse.StatusCode);
    }
    else
    {
    switch (response)
    {
    // check for new version of paypal if different send notify email
    case "VERIFIED":
    if ( Notify_version != "1.4" )
    {
    MailMessage mailObj = new MailMessage();
    mailObj.From = "CJC BodyCare";
    mailObj.To = Receiver_email;
    mailObj.Subject = "Paypal Version Change";
    mailObj.Body = "I see a new version of PayPal Notify IPN Service!!! Go check the PayPal site for updates!" + '\n'
    + "I currently see version: " + Notify_version;
    mailObj.BodyFormat = MailFormat.Html;
    SmtpMail.Send(mailObj);
    }
    //****************************************************
    // still to do
    //******************************************************
    // check that Txn_id has not been previously processed
    // check that Receiver_email is an email address in your PayPal account
    // process payment
    //******************************************************


    // check that Payment_status=Completed
    switch (Payment_status)
    {
    case "Completed": //The payment has been completed and the funds are successfully in your account balance

    //**************************
    // Perform steps 2-5 above.
    // Continue with automation processing if all steps succeeded.
    //**************************


    if (Receiver_email == "sales@christopherjohnconnelly.com")
    {
    switch (Txn_type)
    {
    case "web_accept": //The payment was sent by your customer via the Web Accept feature.
    case "cart": //This payment was sent by your customer via the Shopping Cart feature
    MailUsTheOrder("PROCESS ME: The order was completed successfully.");
    break;
    case "send_money": //This payment was sent by your customer from the PayPal website, using the "Send Money" tab
    MailUsTheOrder("PROCESS ME: Somebody sent us money!");
    break;
    case "subscr_signup": //This IPN is for a subscription sign-up
    MailUsTheOrder("PROCESS ME: Subscription signup.");
    break;
    case "subscr_cancel": //This IPN is for a subscription cancellation
    MailUsTheOrder("PROCESS ME: Subscription cancellation.");
    break;
    case "subscr_failed": //This IPN is for a subscription payment failure
    MailUsTheOrder("FAILURE: Subscription failed.");
    break;
    case "subscr_payment": //This IPN is for a subscription payment
    MailUsTheOrder("COOL: We got cash!");
    break;
    case "subscr_eot": //This IPN is for a subscription's end of term
    MailUsTheOrder("WHAT IS THIS? Subscription end of term.");
    break;
    }
    switch (Address_status)
    {
    case "confirmed": //Customer provided a Confirmed Address
    break;
    case "unconfirmed": //Customer provided an Unconfirmed Address
    break;
    }
    switch (Payer_status)
    {
    case "verified": //Customer has a Verified U.S. PayPal account
    break;
    case "unverified": //Customer has an Unverified U.S. PayPal account
    break;
    case "intl_verified": //Customer has a Verified International PayPal account
    break;
    case "intl_unverified": //Customer has an Unverified International PayPal account
    break;
    }
    switch (Payment_type)
    {
    case "echeck": //This payment was funded with an eCheck
    break;
    case "instant": //This payment was funded with PayPal balance, credit card, or Instant Transfer
    break;
    }
    }
    else
    {
    MailUsTheOrder("WEIRD: Someone is notifying us that the payments were received by someone else???");
    }
    break;
    case "Pending": //The payment is pending - see the "pending reason" variable below for more information. Note: You will receive another instant payment notification when the payment becomes "completed", "failed", or "denied"
    switch (Pending_reason)
    {
    case "echeck": // The payment is pending because it was made by an eCheck, which has not yet cleared
    break;
    case "intl": //The payment is pending because you, the merchant, hold an international account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview
    break;
    case "verify": //The payment is pending because you, the merchant, are not yet verified. You must verify your account before you can accept this payment
    break;
    case "address": //The payment is pending because your customer did not include a confirmed shipping address and you, the merchant, have your Payment Receiving Preferences set such that you want to manually accept or deny each of these payments. To change your preference, go to the "Preferences" section of your "Profile"
    break;
    case "upgrade": //The payment is pending because it was made via credit card and you, the merchant, must upgrade your account to Business or Premier status in order to receive the funds
    break;
    case "unilateral": //The payment is pending because it was made to an email address that is not yet registered or confirmed
    break;
    case "other": //The payment is pending for an "other" reason. For more information, contact customer service
    break;
    }
    MailUsTheOrder("PENDING: Order is waiting to be processed.");
    break;
    case "Failed": //The payment has failed. This will only happen if the payment was made from your customer's bank account
    MailUsTheOrder("FAILED: This only happens if the payment was made from our customer's bank account.");
    break;
    case "Denied": //You, the merchant, denied the payment. This will only happen if the payment was previously pending due to one of the "pending reasons"
    MailUsTheOrder("DENIED: We denied this payment.");
    break;
    }
    // add transaction to database
    IBuySpy.TransactionDB TransactionSystem = new IBuySpy.TransactionDB();
    TransactionSystem.AddTransaction( Txn_id, Receiver_email, Item_name, Item_number, Quantity, Invoice, Custom, Payment_status, Pending_reason, Payment_date, Payment_fee, Payment_gross, Txn_type, First_name, Last_name, Address_street, Address_city, Address_state, Address_zip, Address_country, Address_status, Payer_email, Payer_status, Payer_id, Payment_type, Notify_version, Verify_sign );
    break;
    case "INVALID":
    // Possible fraud. Log for investigation or an error
    MailUsTheOrder("INVALID: Possible fraud. Log for investigation or an error");
    break;
    default:
    // error
    MailUsTheOrder("Default: error: Response is: " + response);
    break;
    }
    }
    }
    private void MailUsTheOrder(string TagMsg)
    {
    MailMessage mailObj = new MailMessage();
    mailObj.From = "sales@yourdomain.com";
    mailObj.Subject = TagMsg;
    mailObj.Body = TagMsg + "<br>" + "<br>";
    mailObj.To = Receiver_email;
    mailObj.BodyFormat = MailFormat.Html;
    mailObj.Priority = MailPriority.High;
    mailObj.Body = mailObj.Body + "Order ID: " + OrderID + "<br>"
    + "Transaction ID: " + Txn_id + "<br>"
    + "Transaction Type:" + Txn_type + "<br>"
    + "Payment Type: " + Payment_type + "<br>"
    + "Payment Status: " + Payment_status + "<br>"
    + "Pending Reason: " + Pending_reason + "<br>"
    + "Payment Date: " + Payment_date + "<br>"
    + "Receiver Email: " + Receiver_email + "<br>"
    + "Invoice: " + Invoice + "<br>"
    + "Item Number: " + Item_number + "<br>"
    + "Item Name: " + Item_name + "<br>"
    + "Quantity: " + Quantity + "<br>"
    + "Custom: " + Custom + "<br>"
    + "Payment Gross: " + Payment_gross + "<br>"
    + "Payment Fee: " + Payment_fee + "<br>"
    + "Payer Email: " + Payer_email + "<br>"
    + "First Name: " + First_name + "<br>"
    + "Last Name: " + Last_name + "<br>"
    + "Street Address: " + Address_street + "<br>"
    + "City: " + Address_city + "<br>"
    + "State: " + Address_state + "<br>"
    + "Zip Code: " + Address_zip + "<br>"
    + "Country: " + Address_country + "<br>"
    + "Address Status: " + Address_status + "<br>"
    + "Payer Status: " + Payer_status + "<br>"
    + "Verify Sign: " + Verify_sign + "<br>"
    + "Subscriber Date: " + Subscr_date + "<br>"
    + "Period 1: " + Period1 + "<br>"
    + "Period 2: " + Period2 + "<br>"
    + "Period 3: " + Period3 + "<br>"
    + "Amount 1: " + Amount1 + "<br>"
    + "Amount 2: " + Amount2 + "<br>"
    + "Amount 3: " + Amount3 + "<br>"
    + "Recurring: " + Recurring + "<br>"
    + "Reattempt: " + Reattempt + "<br>"
    + "Retry At: " + Retry_at + "<br>"
    + "Recur Times: " + Recur_times + "<br>"
    + "UserName: " + Username + "<br>"
    + "Password: " + Password + "<br>"
    + "Subscriber ID: " + Subscr_id + "<br>"
    + "Notify Version: " + Notify_version + "<br>";
    SmtpMail.Send(mailObj);
    }

    </SCRIPT>

    <html>
    <head>
    </head>
    <body>

    </body>
    </html>
  • Re: IPN for paypal in C#

    10-26-2004, 9:22 PM
    • Participant
      1,245 point Participant
    • big_jim_mcbob
    • Member since 07-28-2003, 7:21 PM
    • Winnipeg, Manitoba, Canada
    • Posts 249
    I know this is over 2 years old, but very nice to see!

    Thanks Chris!
  • Re: IPN for paypal in C#

    11-04-2007, 5:48 PM
    • Member
      10 point Member
    • ImDaFrEaK
    • Member since 12-30-2006, 4:57 AM
    • Posts 5

    There is an awesome PayPal IPN Class for VB.NET / C# / J# / any .NET language with instructions at this site. http://www.ggg-3.com/PayPal_Demo.aspx
    This is the class I use in my projects and it works perfectly.  It is even loaded with XML Documentation straight from PayPal so that you know which and what veriables and methods to use just by reading the intellisense with Visual Studio.  And I have tried a few other IPN Classes, that I really didn't like and this one is the easiest and smartest by far.  There are no text variables to worry about.  Basic Paypal variables and information is stored with enum values making the properties and methods really easy to use and understand.  Two events are fired, Verified and UnVerified.  If you have a few bucks man I suggest this route.  Even if its just to borrow the intellisense you'll be saving a lot of time and trouble.

  • Re: IPN for paypal in C#

    11-04-2007, 5:49 PM
    • Member
      10 point Member
    • ImDaFrEaK
    • Member since 12-30-2006, 4:57 AM
    • Posts 5

    There is an awesome PayPal IPN Class for VB.NET / C# / J# / any .NET language with instructions at this site.  http://www.ggg-3.com/PayPal_Demo.aspx
    This is the class I use in my projects and it works perfectly.  It is even loaded with XML Documentation straight from PayPal so that you know which and what veriables and methods to use just by reading the intellisense with Visual Studio.  And I have tried a few other IPN Classes, that I really didn't like and this one is the easiest and smartest by far.  There are no text variables to worry about.  Basic Paypal variables and information is stored with enum values making the properties and methods really easy to use and understand.  Two events are fired, Verified and UnVerified.  If you have a few bucks man I suggest this route.  Even if its just to borrow the intellisense you'll be saving a lot of time and trouble.

  • Re: IPN for paypal in C#

    11-04-2007, 11:39 PM
    • Contributor
      2,260 point Contributor
    • ahsanm.m
    • Member since 08-27-2007, 10:51 AM
    • Dhaka, Bangladesh
    • Posts 364

    Very nice article. Thanx for share.

    Hope that this link will helpful for other:

    http://www.codeguru.com/csharp/.net/net_asp/miscellaneous/article.php/c13851/

     

    Ahsan 

    Ahsan Murshed
    __________________________
    Please "Mark as Answered" if helpful for you.
    ASP BOSS
  • Re: IPN for paypal in C#

    11-10-2007, 12:25 PM
    • Member
      455 point Member
    • dotnet_lee
    • Member since 08-25-2006, 12:45 PM
    • UK
    • Posts 190

    This is the VB version of the first post in case it helps anyone

     

      

    Private CmdString As String, objHttp As String, OrderID As String, Txn_id As String, Payment_status As String, Receiver_email As String, _
    	Item_name As String, Item_number As String, Quantity As String, Invoice As String, [Custom] As String, Payment_gross As String, _
    	Payer_email As String, Pending_reason As String, Payment_date As String, Payment_fee As String, Txn_type As String, First_name As String, _
    	Last_name As String, Address_street As String, Address_city As String, Address_state As String, Address_zip As String, Address_country As String, _
    	Address_status As String, Payer_status As String, Payer_id As String, Payment_type As String, Notify_version As String, Verify_sign As String, _
    	Subscr_date As String, Period1 As String, Period2 As String, Period3 As String, Amount1 As String, Amount2 As String, _
    	Amount3 As String, Recurring As String, Reattempt As String, Retry_at As String, Recur_times As String, Username As String, _
    	Password As String, Subscr_id As String, response As String
    
    
    
    Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim stringPost As String = Request.Form.ToString()
        ' assign posted variables to local variables
        Txn_id = Request.Form("txn_id")
        Receiver_email = Request.Form("receiver_email")
        Item_name = Request.Form("item_name")
        Item_number = Request.Form("item_number")
        Quantity = Request.Form("quantity")
        Invoice = Request.Form("invoice")
        [Custom] = Request.Form("custom")
        Payment_status = Request.Form("payment_status")
        Pending_reason = Request.Form("pending_reason")
        If Payment_status <> "Pending" Then
            Pending_reason = " "
        End If
        Payment_date = Request.Form("payment_date")
        Payment_fee = Request.Form("payment_fee")
        Payment_gross = Request.Form("payment_gross")
        Txn_type = Request.Form("txn_type")
        First_name = Request.Form("first_name")
        Last_name = Request.Form("last_name")
        Address_street = Request.Form("address_street")
        Address_city = Request.Form("address_city")
        Address_state = Request.Form("address_state")
        Address_zip = Request.Form("address_zip")
        Address_country = Request.Form("address_country")
        Address_status = Request.Form("address_status")
        Payer_email = Request.Form("payer_email")
        Payer_status = Request.Form("payer_status")
        Payer_id = Request.Form("payer_id")
        Payment_type = Request.Form("payment_type")
        Notify_version = Request.Form("notify_version")
        Verify_sign = Request.Form("verify_sign")
        
        ' post to paypal and await response : use: "https://www.paypal.com/cgi-bin/webscr" for real;
        ' use: "http://www.eliteweaver.co.uk/testing/ipntest.php" to test;
        
        Dim httpWebRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"), HttpWebRequest)
        httpWebRequest.Method = "POST"
        ' length plus 21 because &cmd=_notify-validate is 21 chars long
        httpWebRequest.ContentLength = stringPost.Length + 21
        httpWebRequest.ContentType = "application/x-www-form-urlencoded"
        Dim streamWriter As StreamWriter = Nothing
        streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
        stringPost = stringPost + "&cmd=_notify-validate"
        streamWriter.Write(stringPost)
        streamWriter.Close()
        Dim httpWebResponse As HttpWebResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
        Using streamReader As New StreamReader(httpWebResponse.GetResponseStream())
            response = streamReader.ReadToEnd()
            streamReader.Close()
        End Using
        
        ' Step 1c: Process the response from PayPal.
        If httpWebResponse.StatusCode <> HttpStatusCode.OK Then
            ' an error has occurred
            MailUsTheOrder("Status Error: " + httpWebResponse.StatusCode)
        Else
            Select Case response
                Case "VERIFIED"
                    ' check for new version of paypal if different send notify email
                    If Notify_version <> "1.4" Then
                        Dim mailObj As New MailMessage()
                        mailObj.From = "CJC BodyCare"
                        mailObj.[To] = Receiver_email
                        mailObj.Subject = "Paypal Version Change"
                        mailObj.Body = "I see a new version of PayPal Notify IPN Service!!! Go check the PayPal site for updates!" + Chr(10) + "I currently see version: " + Notify_version
                        mailObj.BodyFormat = MailFormat.Html
                        SmtpMail.Send(mailObj)
                    End If
                    '****************************************************
                    ' still to do
                    '******************************************************
                    ' check that Txn_id has not been previously processed
                    ' check that Receiver_email is an email address in your PayPal account
                    ' process payment
                    '******************************************************
                    
                    
                    ' check that Payment_status=Completed
                    Select Case Payment_status
                        Case "Completed"
                            'The payment has been completed and the funds are successfully in your account balance
                            '**************************
                            ' Perform steps 2-5 above.
                            ' Continue with automation processing if all steps succeeded.
                            '**************************
                            
                            
                            If Receiver_email = "sales@christopherjohnconnelly.com" Then
                                Select Case Txn_type
                                    Case "web_accept", "cart"
                                        'The payment was sent by your customer via the Web Accept feature.
                                        'This payment was sent by your customer via the Shopping Cart feature
                                        MailUsTheOrder("PROCESS ME: The order was completed successfully.")
                                        Exit Select
                                    Case "send_money"
                                        'This payment was sent by your customer from the PayPal website, using the "Send Money" tab
                                        MailUsTheOrder("PROCESS ME: Somebody sent us money!")
                                        Exit Select
                                    Case "subscr_signup"
                                        'This IPN is for a subscription sign-up
                                        MailUsTheOrder("PROCESS ME: Subscription signup.")
                                        Exit Select
                                    Case "subscr_cancel"
                                        'This IPN is for a subscription cancellation
                                        MailUsTheOrder("PROCESS ME: Subscription cancellation.")
                                        Exit Select
                                    Case "subscr_failed"
                                        'This IPN is for a subscription payment failure
                                        MailUsTheOrder("FAILURE: Subscription failed.")
                                        Exit Select
                                    Case "subscr_payment"
                                        'This IPN is for a subscription payment
                                        MailUsTheOrder("COOL: We got cash!")
                                        Exit Select
                                    Case "subscr_eot"
                                        'This IPN is for a subscription's end of term
                                        MailUsTheOrder("WHAT IS THIS? Subscription end of term.")
                                        Exit Select
                                End Select
                                Select Case Address_status
                                    Case "confirmed"
                                        'Customer provided a Confirmed Address
                                        Exit Select
                                    Case "unconfirmed"
                                        'Customer provided an Unconfirmed Address
                                        Exit Select
                                End Select
                                Select Case Payer_status
                                    Case "verified"
                                        'Customer has a Verified U.S. PayPal account
                                        Exit Select
                                    Case "unverified"
                                        'Customer has an Unverified U.S. PayPal account
                                        Exit Select
                                    Case "intl_verified"
                                        'Customer has a Verified International PayPal account
                                        Exit Select
                                    Case "intl_unverified"
                                        'Customer has an Unverified International PayPal account
                                        Exit Select
                                End Select
                                Select Case Payment_type
                                    Case "echeck"
                                        'This payment was funded with an eCheck
                                        Exit Select
                                    Case "instant"
                                        'This payment was funded with PayPal balance, credit card, or Instant Transfer
                                        Exit Select
                                End Select
                            Else
                                MailUsTheOrder("WEIRD: Someone is notifying us that the payments were received by someone else???")
                            End If
                            Exit Select
                        Case "Pending"
                            'The payment is pending - see the "pending reason" variable below for more information. Note: You will receive another instant payment notification when the payment becomes "completed", "failed", or "denied"
                            Select Case Pending_reason
                                Case "echeck"
                                    ' The payment is pending because it was made by an eCheck, which has not yet cleared
                                    Exit Select
                                Case "intl"
                                    'The payment is pending because you, the merchant, hold an international account and do not have a withdrawal mechanism. You must manually accept or deny this payment from your Account Overview
                                    Exit Select
                                Case "verify"
                                    'The payment is pending because you, the merchant, are not yet verified. You must verify your account before you can accept this payment
                                    Exit Select
                                Case "address"
                                    'The payment is pending because your customer did not include a confirmed shipping address and you, the merchant, have your Payment Receiving Preferences set such that you want to manually accept or deny each of these payments. To change your preference, go to the "Preferences" section of your "Profile"
                                    Exit Select
                                Case "upgrade"
                                    'The payment is pending because it was made via credit card and you, the merchant, must upgrade your account to Business or Premier status in order to receive the funds
                                    Exit Select
                                Case "unilateral"
                                    'The payment is pending because it was made to an email address that is not yet registered or confirmed
                                    Exit Select
                                Case "other"
                                    'The payment is pending for an "other" reason. For more information, contact customer service
                                    Exit Select
                            End Select
                            MailUsTheOrder("PENDING: Order is waiting to be processed.")
                            Exit Select
                        Case "Failed"
                            'The payment has failed. This will only happen if the payment was made from your customer's bank account
                            MailUsTheOrder("FAILED: This only happens if the payment was made from our customer's bank account.")
                            Exit Select
                        Case "Denied"
                            'You, the merchant, denied the payment. This will only happen if the payment was previously pending due to one of the "pending reasons"
                            MailUsTheOrder("DENIED: We denied this payment.")
                            Exit Select
                    End Select
                    ' add transaction to database
                    Dim TransactionSystem As New IBuySpy.TransactionDB()
                    TransactionSystem.AddTransaction(Txn_id, Receiver_email, Item_name, Item_number, Quantity, Invoice, _
                    	[Custom], Payment_status, Pending_reason, Payment_date, Payment_fee, Payment_gross, _
                    	Txn_type, First_name, Last_name, Address_street, Address_city, Address_state, _
                    	Address_zip, Address_country, Address_status, Payer_email, Payer_status, Payer_id, _
                    	Payment_type, Notify_version, Verify_sign)
                    Exit Select
                Case "INVALID"
                    ' Possible fraud. Log for investigation or an error
                    MailUsTheOrder("INVALID: Possible fraud. Log for investigation or an error")
                    Exit Select
                Case Else
                    ' error
                    MailUsTheOrder("Default: error: Response is: " + response)
                    Exit Select
            End Select
        End If
    End Sub
    Private Sub MailUsTheOrder(ByVal TagMsg As String)
        Dim mailObj As New MailMessage()
        mailObj.From = "sales@yourdomain.com"
        mailObj.Subject = TagMsg
        mailObj.Body = TagMsg + "<br>" + "<br>"
        mailObj.[To] = Receiver_email
        mailObj.BodyFormat = MailFormat.Html
        mailObj.Priority = MailPriority.High
        mailObj.Body = mailObj.Body + "Order ID: " + OrderID + "<br>" + "Transaction ID: " + Txn_id + "<br>" + "Transaction Type:" + Txn_type + "<br>" + "Payment Type: " + Payment_type + "<br>" + "Payment Status: " + Payment_status + "<br>" + "Pending Reason: " + Pending_reason + "<br>" + "Payment Date: " + Payment_date + "<br>" + "Receiver Email: " + Receiver_email + "<br>" + "Invoice: " + Invoice + "<br>" + "Item Number: " + Item_number + "<br>" + "Item Name: " + Item_name + "<br>" + "Quantity: " + Quantity + "<br>" + "Custom: " + [Custom] + "<br>" + "Payment Gross: " + Payment_gross + "<br>" + "Payment Fee: " + Payment_fee + "<br>" + "Payer Email: " + Payer_email + "<br>" + "First Name: " + First_name + "<br>" + "Last Name: " + Last_name + "<br>" + "Street Address: " + Address_street + "<br>" + "City: " + Address_city + "<br>" + "State: " + Address_state + "<br>" + "Zip Code: " + Address_zip + "<br>" + "Country: " + Address_country + "<br>" + "Address Status: " + Address_status + "<br>" + "Payer Status: " + Payer_status + "<br>" + "Verify Sign: " + Verify_sign + "<br>" + "Subscriber Date: " + Subscr_date + "<br>" + "Period 1: " + Period1 + "<br>" + "Period 2: " + Period2 + "<br>" + "Period 3: " + Period3 + "<br>" + "Amount 1: " + Amount1 + "<br>" + "Amount 2: " + Amount2 + "<br>" + "Amount 3: " + Amount3 + "<br>" + "Recurring: " + Recurring + "<br>" + "Reattempt: " + Reattempt + "<br>" + "Retry At: " + Retry_at + "<br>" + "Recur Times: " + Recur_times + "<br>" + "UserName: " + Username + "<br>" + "Password: " + Password + "<br>" + "Subscriber ID: " + Subscr_id + "<br>" + "Notify Version: " + Notify_version + "<br>"
        SmtpMail.Send(mailObj)
    End Sub
    
     
  • Re: IPN for paypal in C#

    09-29-2009, 9:29 AM
    • Member
      2 point Member
    • Roly67
    • Member since 09-29-2009, 9:22 AM
    • Posts 1

    Take a look at this component for easy PayPal IPN to .NET integration.

    http://www.ipn-easy.com/.

    We hooked up IPN to .NET in minutes (using the examples in the documentation) and had it running with MSMQ(by WCF) and Windows Workflow.

    Hope this helps.

Page 1 of 1 (7 items)