Sage Pay Server与.NET MVC的集成

k5ifujac  于 2023-05-30  发布在  .NET
关注(0)|答案(1)|浏览(115)

我们如何将SagePay与.NET MVC集成
当我们尝试在MVC中使用它时,它返回的vpsprotocol仅为2.23,而不是3.00
有人能告诉我们如何在. NETMVC中正确地包含dll的引用吗

qq24tv8q

qq24tv8q1#

下面是我使用MVC和.Net Core 2.2实现Sage Pay Server Integration and Protocol Guidelines 3.00的示例
带有“VPSProtocol”、“3.00”的代码部分

[HttpPost("submited")]
    public async Task<IActionResult> SubmitedPayment(PaymentDTO paymentDTO)
    {
        paymentDTO.Description = "Invoice Description";
        paymentDTO.VendorTxCode = Guid.NewGuid().ToString().ToUpper();
        paymentDTO.NotificationURL = $"{_configuration["AppUrl"]}/Payment/RedirectURL";
        paymentDTO.Vendor = _configuration["Vendor"];
        var client = new HttpClient();
        var data = PostData(paymentDTO);
        var result = await client.PostAsync(_configuration["SagePayUrl"], new FormUrlEncodedContent(data));
        var contentResponse = await result.Content.ReadAsStringAsync();
        if (contentResponse.Contains("Status=OK"))
            return Redirect(await SaveSuccessResponseData(paymentDTO, contentResponse));
        ViewBag.StatusDetail = contentResponse;
        return View("Error");
    }
   private Dictionary<string, string> PostData(PaymentDTO paymentDTO)
    {
        return new Dictionary<string, string>
        {
            { "VPSProtocol", "3.00" },
            { "TxType", "PAYMENT" },
            { "Vendor", _configuration["Vendor"] },
            { "Currency", paymentDTO.Currency },
            { "Amount", paymentDTO.Amount.ToString() },
            { "Description", paymentDTO.Description },
            { "VendorTxCode", paymentDTO.VendorTxCode },
            { "NotificationURL", paymentDTO.NotificationURL},
            { "BillingFirstnames", paymentDTO.BillingFirstnames },
            { "BillingSurname", paymentDTO.BillingSurname },
            { "BillingAddress1", paymentDTO.BillingAddress1 },
            { "BillingAddress2", paymentDTO.BillingAddress2 },
            { "BillingCity", paymentDTO.BillingCity },
            { "BillingPostCode", paymentDTO.BillingPostCode },
            { "BillingCountry", paymentDTO.BillingCountry },
            { "DeliveryFirstnames", paymentDTO.DeliveryFirstnames ?? paymentDTO.BillingFirstnames},
            { "DeliverySurname", paymentDTO.DeliverySurname ?? paymentDTO.BillingSurname},
            { "DeliveryAddress1", paymentDTO.DeliveryAddress1 ?? paymentDTO.BillingAddress1},
            { "DeliveryAddress2", paymentDTO.DeliveryAddress2 ?? paymentDTO.BillingAddress2},
            { "DeliveryCity", paymentDTO.DeliveryCity ?? paymentDTO.BillingCity},
            { "DeliveryPostCode", paymentDTO.DeliveryPostCode ?? paymentDTO.BillingPostCode},
            { "DeliveryCountry", paymentDTO.DeliveryCountry ?? paymentDTO.BillingCountry},
            { "BillingState", paymentDTO.BillingState },
            { "DeliveryState", paymentDTO.DeliveryState ?? paymentDTO.BillingState},
            { "CustomerEMail", paymentDTO.CustomerEMail}
        };
    }

整个项目在GitHub https://github.com/AleksandrChuikov/SagePay-ServerIntegration-MVC-.NET-Core-2.2上可用

相关问题