PSU
PSU

Reputation: 187

SagePay RedirectURL failure

Using server integration and .net, I post the original request to SagePay and get the NextURL fine, and so go to the payment pages... step through them OK, but then I get the error:

Server error 5006: Unable to redirect to Vendor's web site. The Vendor failed to provide a RedirectionURL.

HTTP error 500: The request was unsuccessful due to an unexpected condition encountered by the server.

But I am sending a RedirectionURL (though the docs call is RedirectURL, which is somewhat confusing - anyway, I've tried using both. This si what I'm sending back from my NotificatioURL - what's wrong?

      Dim sb As New StringBuilder
  sb.Append("Status=OK")  
  sb.Append("&StatusDetail=Fine")
  sb.Append("&RedirectURL=https://mydomain.co.uk/sagepay.aspx")

  Dim urlTEST As String = "https://test.sagepay.com/gateway/service/vspserver-register.vsp"
  Dim urlLIVE As String = "https://live.sagepay.com/gateway/service/vspserver-register.vsp"

  Try
     Dim data As Byte() = Encoding.UTF8.GetBytes(sb.ToString)

     Dim request As WebRequest = WebRequest.Create(urlTEST)

     request.Method = "POST"
     request.ContentType = "application/x-www-form-urlencoded"
     request.ContentLength = data.Length
     ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteSSLCertificate
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

     Dim stream = request.GetRequestStream()
     stream.Write(data, 0, data.Length)
     stream.Close()

    Dim response As WebResponse = request.GetResponse()
     response.Close()

  Catch ex As Exception
    'log error

  End Try

Update: I gather this POST (unlike the initial one with the basket info) requires that the data be sent plain text key-value pairs separated by CrLf's, so I amended this to

          Dim sb As New StringBuilder
  sb.AppendLine("Status=OK")  
  sb.AppendLine("StatusDetail=Fine")
  sb.Append("RedirectURL=https://mydomain.co.uk/sagepay.aspx")

but it still fails with the same errors. I also tried using, instead of the WebRequst class, the simpler:

Dim client As WebClient = New WebClient()
Dim reply As String = client.UploadString(urlTEST, sb.ToString)

But still no joy. Also tried changing the request.ContentType to "text/plain", but nope.

Come on, someone, please - this si basic to the their operations, someone must have done it....

Upvotes: 0

Views: 592

Answers (1)

PSU
PSU

Reputation: 187

Blimey - it never pays to be clever. This script doesn't require WebRequest or anything, just write to the simple Response object. Sigh.. as Linus said ....

Upvotes: 1

Related Questions