Having Extreme Difficulties with PayPal PDT and ASP.Net Success

rcnjstudent
Contributor
Contributor

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%20N...

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

Login to Me Too
1 REPLY 1

solace2000
Contributor
Contributor

I feel your pain, PayPal is a very unfriendly and complicated set up, though they are doing there best to modernise it and provide support.

You could take a read of this helpful page that explains how to use PDT and IPN.  Suggest you to try to follow the tutorial to understand how it all works.

https://www.codexworld.com/paypal-standard-payment-gateway-integration-php/

 

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.