Reputation: 238
I have downloaded and installed to a project the .Net sagepay integration kit, and am trying to implement the Server integration.
All works well up to when the user is transferred to sagepay, and you can successfully make payment, but when sagepay POSTs to my Notification.aspx page, I am not receiving any data.
The POST is definitely being made as the server log sees it come in, and the redirectURL is passed back so that Sagepay redirects the user back to my site, but I cannot find any POST data to process and know what transaction I am dealing with.
The code from the kit that should handle this is:
public partial class Server_Notification : System.Web.UI.Page
{
private const string OK = "OK";
private const string INVALID = "INVALID";
protected void Page_Load(object sender, EventArgs e)
{
IServerNotificationRequest serverNotificationRequest = new SagePayServerIntegration().GetServerNotificationRequest();
try
{
OrderDataService.handleNotification(serverNotificationRequest);
if (Request.QueryString["uid"] != null && !string.IsNullOrEmpty(Request.QueryString["uid"]))
{
new CardDB().Add(Convert.ToInt32(Request.QueryString["uid"]), serverNotificationRequest.Token, serverNotificationRequest.Last4Digits);
}
if (serverNotificationRequest.Status == SagePay.IntegrationKit.ResponseStatus.OK)
{
ShoppingCart.Current().Clean();
}
}
catch (Exception ex)
{
Debug.WriteLine("ERROR: " + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
}
Response.Clear();
Response.ContentType = "text/plain";
Response.Write(string.Format("Status={0}\n", serverNotificationRequest.Status == ResponseStatus.ERROR ? INVALID : OK));
Response.Write(string.Format("RedirectURL={0}server/Result.aspx?Status={1}&VendorTxCode={2}", SagePaySettings.SiteFqdn, serverNotificationRequest.Status, serverNotificationRequest.VendorTxCode));
}
}
The specific line that is failing is IServerNotificationRequest serverNotificationRequest = new SagePayServerIntegration().GetServerNotificationRequest();
This is returning an empty object with no transaction data.
I have added some logging and tried to extract any POST data manually, but am not finding anything using Request.InputStream
, Request.Form.AllKeys
or in Request.QueryString
(apart from the customer UID that I pass myself).
I have tried asking sagepay for help but they "...cannot provide direct development support for the kits, as they are examples".
I am out of ideas and wondered if anyone else could help shed some light, please?
Cheers
Simon
Upvotes: 1
Views: 336
Reputation: 238
Finally have a solution, thanks to https://www.mikesdotnetting.com/article/293/request-form-is-empty-when-posting-to-aspx-page
The problem was friendly URLs. Simply commenting out //settings.AutoRedirectMode = RedirectMode.Permanent;
in RouteConfig.cs solved the problem!
Upvotes: 1