Results 1 to 11 of 11

Thread: Please help me make paypal IPN work!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Please help me make paypal IPN work!

    I am using the code below for paypal notifications.

    I checked the notification history and it comes back as payment_status is Complete BUT the VB code performs the code for the "INVALID" case...

    Any pointers would be most appreciated...............

    Code:
      'Post back to either sandbox or live
            Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
            Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
            Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
    
            'Set values for the request back
            req.Method = "POST"
            req.ContentType = "application/x-www-form-urlencoded"
            Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
            Dim strRequest As String = Encoding.ASCII.GetString(Param)
            strRequest = strRequest + "&cmd=_notify-validate"
            req.ContentLength = strRequest.Length
    
            'for proxy
            'Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
            'req.Proxy = proxy
    
            'Send the request to PayPal and get the response
            Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
            streamOut.Write(strRequest)
            streamOut.Close()
            Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
            Dim strResponse As String = streamIn.ReadToEnd()
            streamIn.Close()
            Dim order_item_no, order_trans_id, order_pay_status As String
            order_item_no = Request.Form("item_number1")
            order_trans_id = Request.Form("txn_id")
            order_pay_status = Request.Form("payment_status")
            If strResponse = "VERIFIED" Then
                '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
                If order_pay_status = "Completed" Then
    
                    If Mid(order_item_no, 1, 1) = "Z" Then
                        order_item_no = order_item_no.Replace("Z", "")
                        Call GetInvoiceDetails("", "", "", order_item_no, "")
                        Call DBgeneral("UPDATE tblInvoice SET invPaid='1' WHERE invID=" & order_item_no & ";")
                        Call DBgeneral("INSERT INTO tblInvoiceInfo(iiInvoiceID,iiType,iiReference,iiNote) VALUES('" & order_item_no & "','1','" & order_trans_id & "','PayPal Payment made!');")
                        Call SendMail(InvUser(0), "Payment received with thanks!", "1", "payment_received", order_item_no, "")
                        If InvStatus(0) = "0" Then
                            Call DBgeneral("UPDATE tblInvoice SET invStatus='1' WHERE invID=" & order_item_no)
                        End If
                    End If
                Else
    
                End If
                Call SendMail("", "Completed:Order PPI", "0", "Order ID:" & order_item_no & " <p>Completed<p>", "", "")
    
            ElseIf strResponse = "INVALID" Then
                'log for manual investigation
                ' Call SendMail("", "Invalid:Order PPI", order_item_no & "<p>" & order_trans_id, "", "")
                Call SendMail("", "INVALID:Order PPI Response:" & strResponse, "0", "Order ID:" & order_item_no & " <p>Completed<p>", "", "")
            Else
                'Response wasn't VERIFIED or INVALID, log for manual investigation
                ' Call SendMail("", "Other:Order PPI", order_item_no & "<p>" & order_trans_id, "", "")
                Call SendMail("", "ELSE:Order PPI", "0", "Order ID:" & order_item_no & " <p>Completed<p>", "", "")
            End If
            '  Call SendMail("", "API LOAD0", "0", "Order ID:" & order_item_no & " <p>Completed<p>", "", "")
            Call SendMail("", "API DATA", "0", strResponse, "", "")
    Last edited by arcon5; Jul 18th, 2011 at 02:31 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Please help me make paypal IPN work!

    If the code for the "INVALID" branch of your if/else statement is running, then strResponse MUST contain the string "INVALID". I suggest you set a breakpoint and step through the running code line by line.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Please help me make paypal IPN work!

    Thats whats confusing. This is the IPN message PayPal have sent (personal info removed):

    handling_amount=0.00&payer_id=X5MQVWNK9QAA8&address_country_code=GB&address_zip=NG317DW&shipping=1.2 0&charset=windows-1252&payment_gross=&address_status=confirmed&address_street=a street&contact_phone=&verify_sign=AiPC9BjkCyDFQXbSkoZcgqH3hpacAgwmACszE7wpRBtlSDtXc8-kmsgE&item_name=PrintNine.com Order&txn_type=web_accept&receiver_id=J85MDHTPD4R74&payment_fee=&mc_currency=GBP&transaction_subject =PrintNine.com Order&custom=&protection_eligibility=Eligible&address_country=United Kingdom&payer_status=unverified&first_name=someone&address_name=somebody&mc_gross=23.18&payment_date =04:09:47 Mar 14, 2011 PDT&payment_status=Completed&quantity=1&[email protected]&item_number=Z1016&last_name=su rname&address_state=Lincolnshire&txn_id=ANIDHERE&mc_fee=0.87&resend=true&payment_type=instant&notify _version=3.1&[email protected]&receiver_email=paypal@xxcom&address_city=Lincs&tax=0.00&re sidence_country=GB

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Please help me make paypal IPN work!

    Do you know how to set breakpoints and debug code?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Please help me make paypal IPN work!

    Quote Originally Posted by kleinma View Post
    Do you know how to set breakpoints and debug code?
    Erm.. no

    I've always trialled and errored code but thats not an option here. As when I use paypal sandpit it works perfectly fine.. but when real transactions come through it doesn't work properly

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Please help me make paypal IPN work!

    You are still using sandbox on the code you provided.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Please help me make paypal IPN work!

    Quote Originally Posted by arcon5 View Post
    Erm.. no

    I've always trialled and errored code but thats not an option here. As when I use paypal sandpit it works perfectly fine.. but when real transactions come through it doesn't work properly
    You set breakpoints in code by clicking the left most area of the code window (it will have a slightly different color than the code window itself). This will place a red circle on that line of code. Then when you run your code in the IDE, when you get to that specific line where the breakpoint is, the program will pause and bring you to the code. From there you can mouse over variables to see their values, and you can step through your code line by line to see things process. This is way, way more valuable than just running the code over and over and guessing where the problem is. This will help you find the problem right away, because you can see the exact line of code where things don't turn out as you expect them to.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    137

    Re: Please help me make paypal IPN work!

    Quote Originally Posted by sapator View Post
    You are still using sandbox on the code you provided.

    Oh dear. That explains it all


    You set breakpoints in code by clicking the left most area of the code window (it will have a slightly different color than the code window itself). This will place a red circle on that line of code. Then when you run your code in the IDE, when you get to that specific line where the breakpoint is, the program will pause and bring you to the code. From there you can mouse over variables to see their values, and you can step through your code line by line to see things process. This is way, way more valuable than just running the code over and over and guessing where the problem is. This will help you find the problem right away, because you can see the exact line of code where things don't turn out as you expect them to.
    Thank you -- being able to view values line by line will be so much easier !!!

  9. #9
    New Member
    Join Date
    Aug 2013
    Posts
    2

    Re: Please help me make paypal IPN work!

    Arcon5 , i got the same problem, can you fix it, my ipn works perfectly con sandbox, but not in live, i find i need to put http header, and conection close, did you know something??

  10. #10
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Please help me make paypal IPN work!

    Quote Originally Posted by kntuz View Post
    Arcon5 , i got the same problem, can you fix it, my ipn works perfectly con sandbox, but not in live, i find i need to put http header, and conection close, did you know something??
    You're only 2 years too late.

  11. #11
    New Member
    Join Date
    Aug 2013
    Posts
    2

    Re: Please help me make paypal IPN work!

    [QUOTE=MetalInquisitor;4493883]You're only 2 years too late. [/QUOTE

    LMFAO i know man, and i find the solution already

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width