Is there a better way to refactor my below code where I have many conditions in if and else statement
The reason for refactoring is to make code cleaner and readable
public static PaymentOptions GetPaymentOptions_Auto(TestConfigurationCDO testConfiguration, int siteId)
{
var paymentOptions = new PaymentOptions();
var paymentOptionList = SitePaymentRepository.GetSitePaymentInfoBySiteId(
testConfiguration,
siteId);
var lowestPriority = paymentOptionList.Min(x => x.Priority);
var paymentAuto = paymentOptionList.Where(x => x.Priority == lowestPriority).FirstOrDefault();
if (paymentAuto.PaymentType == PaymentMethod.Klarna)
{
paymentOptions = new KlarnaOptions();
}
else if (paymentAuto.PaymentType == PaymentMethod.PayPalDirect ||
paymentAuto.PaymentType == PaymentMethod.Braintree ||
paymentAuto.PaymentType == PaymentMethod.BankTransfer || paymentAuto.PaymentType == PaymentMethod.AdyenDropIn)
{
paymentOptions = new ClientCheckoutOptions()
{
paymentMethod = paymentAuto.PaymentType
};
}
else if (paymentAuto.PaymentType == PaymentMethod.PayPalExpress)
{
paymentOptions = new PaypalOptions();
}
else
{
paymentOptions = new PaypalOptions();
}
return paymentOptions;
}