5006:无法重定向到供应商网站。 SagePay

时间:2016-07-26 06:45:59

标签: asp.net-mvc payment-gateway sagepay

您好我在付款处理付款流程后使用SagePay服务器集成

  

5006:无法重定向到供应商网站。卖方未能如愿   提供RedirectionURL。

我的网络配置文件:

<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>

我的付款响应控制器:

 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();
        }
    }

我无法弄清楚我哪里出错了,请帮我搞清楚。任何形式的帮助都表示赞赏....

2 个答案:

答案 0 :(得分:0)

请参考以下代码,您必须通过URL成功通过request,我已通过使用以下代码实现此目的:

       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.

        }

希望它可以帮助你:)

答案 1 :(得分:0)

Sage不喜欢网址上的端口(来自Sage的文档):

  

Sage Pay服务器向服务器上的NotificationURL脚本发送HTTP或HTTPS POST,以使用端口80和443指示事务的结果。请确保您仅将这些端口用作硬编码,否则任何其他端口都将生成错误< / p>

SagePayMvc库使用当前上下文来构建通知,成功和失败URL,这意味着它还会添加当前请求端口。

在本地测试,我希望我的暂存(Azure)服务器会收到来自Sage的响应,但我的当前端口被添加到请求中,http://example.com:51118/PaymentResponse/Notify导致Sage抛出5006错误

我正在使用MVC5,因此我不得不调整库中的部分代码以使其正常工作。

我更改了BuildNotificationUrl类的DefaultUrlResolver属性,以便在不使用端口的情况下构建URL,因为默认情况下它必须是80或443。

你可以做更多这样的事情:

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);
}

希望这有帮助。