Reputation: 1
How do we integrate SagePay with .NET MVC
When we try to use in MVC its returning vpsprotocol as 2.23 only instead of 3.00
Can someone let us know how to include the reference for the dll properly in .NET MVC
Upvotes: 0
Views: 1591
Reputation: 111
Here is my example of implementation Sage Pay Server Integration and Protocol Guidelines 3.00 with MVC and .Net Core 2.2
The part of code with "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}
};
}
The whole project is available on GitHub https://github.com/AleksandrChuikov/SagePay-ServerIntegration-MVC-.NET-Core-2.2
Upvotes: 2