We need to customise the notification url in uCommerce in order to use to test it locally. Sys guys suggested that I use one of our servers as the notification URL (e.g. the ourserver.com/notification-url will redirect the request to local.mylocalhost.com/notification-url).
This seems nice, but how do I find the notification path?
You can override the notification URL in the SagePay.config to anything you want. Ultimately though you'll have to hit the PaymentProcessor.axd, end point with proper parameter to ensure that the payment is updated with the correct status and the Basket converted to an Order.
Yes Søren, I can see that now. And I have found that we need to put two parameters in the URL /{paymentMethodId}/{paymentId}/PaymentProcessor.axd.
Then how can we configure this parameters? I could hardcode the paymentMethodId for testing purposes but not the paymentId that changes everytime.
I managed to sort the problem with Portfusion and binding my site to the same URL of the server that redirects to the requests to my machine. But if we have an option (auto) in notificationURL I wonder if there exists somewhere documentation about how to actually customise it without hardcoding values to it.
You can actually implement a secondary interface, which lets you take over how payment information is extracted from the callback and thus which information you can support.
You can inherit the default SagePay provider, implement this interface, and completely take over how the payment is located.
/// <summary>
/// Extracts a <see cref="Payment"/> from HTTP request.
/// </summary>
/// <remarks>
/// The extractor is typically used when dealing with a callback or IPNs from a remote payment gateway,
/// which does not support dynamic URLs in the form of /#PaymentMethodId#/#PaymentId#/PaymentProcessor.axd.
/// The extractor will find the unique payment id or reference id in the HTTP request and load up the appropriate
/// payment.
/// </remarks>
public interface IHttpPaymentExtractor
{
Payment Extract(HttpRequest httpRequest);
}
Here's an example of how we use it to find the proper payment for Amazon:
/// <summary>
/// Responsible for extracting payment from Amazon IPN requests.
/// </summary>
public class AmazonHttpPaymentExtractor : IHttpPaymentExtractor
{
/// <summary>
/// Extracts the specified HTTP request.
/// </summary>
/// <param name="httpRequest">The HTTP request.</param>
/// <returns></returns>
public Payment Extract(HttpRequest httpRequest)
{
var callerReference = httpRequest["callerReference"];
if (string.IsNullOrEmpty(callerReference))
throw new NullReferenceException(string.Format("'callerReference' not posted to the extractor. Query string: {0}.", httpRequest.QueryString));
Payment payment = Payment.All().SingleOrDefault(x => x.ReferenceId == callerReference);
if (payment == null)
throw new NullReferenceException(string.Format("Could not find a payment with 'callerReference': {0}.", callerReference));
return payment;
}
}
uCommerce: How to customise notification URL?
Hi Fabio,
You can override the notification URL in the SagePay.config to anything you want. Ultimately though you'll have to hit the PaymentProcessor.axd, end point with proper parameter to ensure that the payment is updated with the correct status and the Basket converted to an Order.
Yes Søren, I can see that now. And I have found that we need to put two parameters in the URL /{paymentMethodId}/{paymentId}/PaymentProcessor.axd.
Then how can we configure this parameters? I could hardcode the paymentMethodId for testing purposes but not the paymentId that changes everytime.
I managed to sort the problem with Portfusion and binding my site to the same URL of the server that redirects to the requests to my machine. But if we have an option (auto) in notificationURL I wonder if there exists somewhere documentation about how to actually customise it without hardcoding values to it.
Does it exist some I haven't found?
Thanks!
It's possible, but it's undocumented.
You can actually implement a secondary interface, which lets you take over how payment information is extracted from the callback and thus which information you can support.
You can inherit the default SagePay provider, implement this interface, and completely take over how the payment is located.
Here's an example of how we use it to find the proper payment for Amazon:
Hope this helps.
Sorry I didn't reply to this. I had implemented without customising the notification URL.
But certainly this will be helpful in the future!
Thanks,
Fabio
is working on a reply...