2

Hi I am using SagePay Server Integration after the payment process the payment process

5006 : Unable to redirect to Vendors web site. The Vendor failed to provide a RedirectionURL.

my web config file:

<sagePay>
  <!-- The public-facing hostname that SagePay can use to contact the site -->

    <add key="NotificationHostName" value="ubtfront.azurewebsites.net" />
  <!--<add key="NotificationHostName" value="ubtfront.azurewebsites.net" />-->
  <!-- The protocol defaults to http, but you can override that to https with the following setting -->
   <add key="Protocol" value="http" /> 
  <!-- Your notification controller -->
  <add key="NotificationController" value="PaymentResponse" />
  <!-- Your notification action. These three settings together are used to build the notification URL -->
  <!-- EG: http://my.external.hostname/PaymentResponse/Notify -->
  <add key="NotificationAction" value="Notify" />
  <!-- Action names for URLS that the user will be directed to after payment either succeeds or fails -->
  <!-- The URL is constructed from the notificationHostName and NotificationController. -->
  <!-- Eg: http://my.external.hostname/PaymentResponse/Success -->
  <add key="SuccessAction" value="Success" />
  <add key="FailedAction" value="Failed" />

  <!-- VAT multiplier. Currently at 20% -->
  <add key="VatMultiplier" value="1" />
  <!-- Name of vendor. You will need to change this -->
  <add key="VendorName" value="VendorName" />
  <!-- Simulator, Test or Live -->
  <add key="Mode" value="Test" />
</sagePay>

My Payment Response Controller:

 public class PaymentResponseController : Controller
    {
        IOrderRepository _orderRepository;

        public PaymentResponseController(IOrderRepository orderRepository)
        {
            _orderRepository = orderRepository;
        }

        public ActionResult Notify(SagePayResponse response)
        {
            // SagePay should have sent back the order ID
            if (string.IsNullOrEmpty(response.VendorTxCode))
            {
                return new ErrorResult();
            }

            // Get the order out of our "database"
            var order = _orderRepository.GetById(response.VendorTxCode);

            // IF there was no matching order, send a TransactionNotfound error
            if (order == null)
            {
                return new TransactionNotFoundResult(response.VendorTxCode);
            }

            // Check if the signature is valid.
            // Note that we need to look up the vendor name from our configuration.
            if (!response.IsSignatureValid(order.SecurityKey, SagePayMvc.Configuration.Current.VendorName))
            {
                return new InvalidSignatureResult(response.VendorTxCode);
            }

            // All good - tell SagePay it's safe to charge the customer.
            return new ValidOrderResult(order.VendorTxCode, response);
        }

        public ActionResult Failed(string vendorTxCode)
        {
            return View();
        }

        public ActionResult Success(string vendorTxCode)
        {
            return View();
        }
    }

I can't figure out where I am going wrong please help me figure it out. Any kind of help is appreciated....

kirushan
  • 508
  • 4
  • 20

2 Answers2

0

Please refer following code, you have to pass your success and failed URL with your request, I have achieved this by using following Code:

       private static void SetSagePayFormAPIData(IFormPayment request, PaymentGatewayRequest paymentRequest)
        {
            var isCollectRecipientDetails = SagePaySettings.IsCollectRecipientDetails;

            request.VpsProtocol = SagePaySettings.ProtocolVersion;
            request.TransactionType = SagePaySettings.DefaultTransactionType;
            request.Vendor = SagePaySettings.VendorName;

            //Assign Vendor tx Code.
            request.VendorTxCode = SagePayFormIntegration.GetNewVendorTxCode();

            request.Amount = paymentRequest.GrossAmount;
            request.Currency = SagePaySettings.Currency;
            request.Description = "Your Payment Description";              
            request.SuccessUrl = "Your SuccessUrl";
            request.FailureUrl = "Your FailureUrl"; 
            request.BillingSurname = paymentRequest.BillingSurname;
            request.BillingFirstnames = paymentRequest.BillingFirstnames;
            request.BillingAddress1 = paymentRequest.BillingAddress1;
            request.BillingCity = paymentRequest.BillingCity;//Pass Billing City Name
            request.BillingCountry = paymentRequest.BillingCountry;//Pass Billing City Name

            request.DeliverySurname = paymentRequest.DeliverySurname;
            request.DeliveryFirstnames = paymentRequest.DeliveryFirstnames;
            request.DeliveryAddress1 = paymentRequest.DeliveryAddress1;
            request.DeliveryCity = paymentRequest.DeliveryCity;//Pass Delivery City Name
            request.DeliveryCountry = paymentRequest.DeliveryCountry;//Pass Delivery Country

            //Optional
            request.CustomerName = paymentRequest.BillingFirstnames + " " + paymentRequest.BillingSurname;
            request.VendorEmail = SagePaySettings.VendorEmail;
            request.SendEmail = SagePaySettings.SendEmail;

            request.EmailMessage = SagePaySettings.EmailMessage;
            request.BillingAddress2 = paymentRequest.BillingAddress2;
            request.BillingPostCode = paymentRequest.BillingPostCode;
            request.BillingState = "UK";//Pass Billing State
            request.BillingPhone = paymentRequest.BillingPhone;
            request.DeliveryAddress2 = paymentRequest.DeliveryAddress2;
            request.DeliveryPostCode = paymentRequest.DeliveryPostCode; //Delivery Post Code
            request.DeliveryState = "UK"; //Pass Delivery State
            request.DeliveryPhone = paymentRequest.DeliveryPhone;

            request.AllowGiftAid = SagePaySettings.AllowGiftAid;
            request.ApplyAvsCv2 = SagePaySettings.ApplyAvsCv2;
            request.Apply3dSecure = SagePaySettings.Apply3dSecure;

            request.CustomerEmail = paymentRequest.CustomerEmail;

            request.BillingAgreement = "";
            request.ReferrerId = SagePaySettings.ReferrerID;

            request.BasketXml = SagePayPaymentController.ToBasketstring(paymentRequest);

            request.VendorData = string.Empty; //Use this to pass any data you wish to be displayed against the transaction in My Sage Pay.

        }

Hope it helps you :)

Sunil Kumar
  • 3,142
  • 1
  • 19
  • 33
  • In server type integration you have to pass `Notification URL` Like this : `NotificationUrl = ServerPaymentRequest.NotificationUrl;` – Sunil Kumar Aug 02 '16 at 04:38
0

Sage doesn't like ports on the URLs (From Sage's docs):

The Sage Pay servers send an HTTP or HTTPS POST to the NotificationURL script on your server to indicate the outcome of the transaction using ports 80 and 443. Please ensure you use these ports only as hard coding any other ports will generate errors

The SagePayMvc library uses the current context to build the Notify, Success and Failure URLs, meaning it also adds the current request port.

Testing locally, I was expecting my staging (Azure) server would receive the response from Sage but my current port was being added to the request, http://example.com:51118/PaymentResponse/Notify resulting in the 5006 error being thrown by Sage.

I am using MVC5 so I've had to tweak parts of the code in the library to make it work.

I changed the BuildNotificationUrl property on the DefaultUrlResolver class to build the URL without using the port as it would have to be 80 or 443 by default.

You could do something more less like this:

public virtual string BuildNotificationUrl(RequestContext context) {
    var configuration = Configuration.Current;
    var urlHelper = new UrlHelper(context);
    var routeValues = new RouteValueDictionary(new {controller = configuration.NotificationController, action = configuration.NotificationAction});
    var url = urlHelper.RouteUrl(null, routeValues, configuration.Protocol, configuration.NotificationHostName);
    var uri = new Uri(url);

    return uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped);
}

Hope this helps.

Diego
  • 786
  • 10
  • 22