I am trying to build an API (.NET Core 3.1) with a single endpoint. How this call should be processed depends on the data it was send with.
I found examples of polymorfism and custom data binding. But feels not right for this example because I want to process all depending of the given Type property.
[HttpPost]
public IActionResult CreatePayment([FromBody]PaymentRequest request)
{
if (request.Type == "MultiSafepay")
{
// cast and do specific logic
}
else if(request.Type == "Other")
{
// cast and do specific logic
}
return Ok();
}
Classes
public class MultiSafepayPaymentResponse : PaymentResponse
{
public string PaymentUrl { get; set; }
public string QRCodeUrl { get; set; }
}
public class PaymentRequest
{
public string Type { get; set; }
public string Amount { get; set; }
public string Description { get; set; }
}
I am breaking my head on this for days. Hope you people can help me out.
Thanks in advance!