paypal / ipn-code-samples

Other
562 stars 486 forks source link

Always getting back invalid payment #105

Closed davidbuckleyni closed 7 years ago

davidbuckleyni commented 7 years ago

General information

I am using the following code for sandbox but I am always getting returned invalid even though paypal says the sandbox payment was sucesfull any ideas what could be wrong my html form I am using to post is as follows

`

` ` 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&test_ipn=1" req.ContentLength = strRequest.Length Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols) Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType) ServicePointManager.SecurityProtocol = Tls12 '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() 'Assign payment variables strOrderNo = HttpContext.Current.Request("item_number")`
randstraw commented 7 years ago

I think it could be due to you appending &test_ipn=1 to the IPN validation request. Can you provide the ipn_track_id value from the IPN body?

davidbuckleyni commented 7 years ago

Hi not sure but i am using local host can the ipn script reach local host when complete the purchases it just sits on the purchase complete screen. I am using the sandbox enviroment so is that not what should I use. i was setting the value raw as per documentation? Its not hitting my page I had the same page in return url so it was never actually getting to my ipn i cant see how i set it

randstraw commented 7 years ago

Are you using Instant Payment Notification or Payment Data Transfer? This FAQ might help you answer https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNPDTAnAlternativetoIPN/.

Payment Data Transfer is a client side redirect and will work with your localhost. To test IPN with your localhost you may need to look at a tunnel solution like https://ngrok.com/.

davidbuckleyni commented 7 years ago

Basically i am wanting to capture if the payment been sucessfull and gross amount and all we currenlty use the above method on live and its fine just not sandbox so not going to re event the code

davidbuckleyni commented 7 years ago

Progress it works fine from the simluator now but my payment form is not sending it to that page its just staying on the payment completed page on paypal.

randstraw commented 7 years ago

The Payment form will not send the customer to your IPN page. The IPN page receives an event message from PayPal. If you are looking for payment confirmation then that is where the Payment Data Transfer might come in. How are you integrating? A PayPal HTML button?

Are you just wanting to accept PayPal payments? If so, you might want to look at the Checkout JS product https://developer.paypal.com/demo/checkout/#/pattern/client.

davidbuckleyni commented 7 years ago

its all sorted we just going use releax to process the paypal payments thanks anyway.