So I'm trying to add PayPal to my test site and the payment part works just fine with the hosted button. The problem I'm encountering is with the return back to my site to verify payment was successful. I've tried so many different scripts online and from YouTube and I just can't get this to work. I've never felt so stupid before in my entire life. I'm trying with PDT verification first since it seemed the simplest. I keep getting a message stating FAIL for some reason. I'm using my facilitator account from Sandbox to have the PayPal Merchant ID button and am using the buyer account to place the payment. I've been working on this for over a week and just can't get this to work :(. Can anyone advise what I'm doing wrong here? Is there any way I can get a more detailed error output to see what's going on? Here's the sample return value from the website (has been anonymized a bit but you still can see what I'm getting back): http://samplesitename.com/Verify_PayPal_Transaction.aspx?amt=10.00&cc=USD&item_name=Sample%20Buy%20Now%20Button&st=Completed&tx=90S9306NA3174205 Returning Error: FAIL Imports System.Collections.Generic Imports System.Net Imports System.IO ' ASP.NET VB Partial Class Verify_PayPal_Transaction Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 'Am = Amount 'St = Status 'CUSTOMIZE THIS: This Is the seller's Payment Data Transfer authorization token. ' Replace this with the PDT token in "Website Payment Preferences" under your account. '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) Dim authToken As String = "M9KpLUf_kdFkfTp96FTGV6Faedjq6n5hWxw6_JZaZ6Psg19e11AyLvJQx1O" Dim txToken As String = Request.QueryString("tx") Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken 'Set values for the request back req.Method = "POST" req.ContentType = "application/x-www-form-urlencoded" 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() If Not String.IsNullOrEmpty(strResponse) Then Dim results As New Dictionary(Of String, String) Dim reader As New StringReader(strResponse) Dim line As String = reader.ReadLine() If line = "SUCCESS" Then While True Dim aLine As String aLine = reader.ReadLine If aLine IsNot Nothing Then Dim strArr() As String strArr = aLine.Split("=") results.Add(strArr(0), strArr(1)) Else Exit While End If End While '<p><h3>Your order has been received.</h3></p>") '<b>Details</b><br>") '<li>Name: " + results("first_name") & " " & results("last_name") & "</li>") '<li>Item: " & results("item_name") & "</li>") '<li>Amount: " & results("payment_gross") & "</li>") '<hr>") ElseIf line = "FAIL" Then 'log for manual investigation Response.Write(strResponse) 'Unable to retreive transaction detail") End If Else 'Unknown Error") End If End Class
... View more