Palak Shah
Well-known member
- Joined
- Apr 29, 2020
- Messages
- 97
- Programming Experience
- 1-3
Hello Everyone,
I have created one class - and it has 3 methods in it - I tried refactoring code considering all the factors; however I am not sure if there is more room for improvement in my code or not
So seek help to review my code and suggest me any means of improvement; so that I can improve more and do coding in standard way
I have created one class - and it has 3 methods in it - I tried refactoring code considering all the factors; however I am not sure if there is more room for improvement in my code or not
So seek help to review my code and suggest me any means of improvement; so that I can improve more and do coding in standard way
Class File:
using Base;
using Config;
using Entities;
using JsonModel;
using Model.PaymentOptions;
using Repositories;
using System.Linq;
namespace Helpers
{
public static class PaymentOptionsHelper
{
public static PaymentMethod[] checkoutGroup = { PaymentMethod.AdyenDropIn, PaymentMethod.PayPalDirect, PaymentMethod.Braintree, PaymentMethod.BankTransfer, };
/// <summary>
/// Below method will set the Payment Type based on the low priority type retrieved from DB
/// </summary>
/// <param name="testConfiguration"></param>
/// <param name="siteId"></param>
/// <returns></returns>
public static PaymentOptions GetPaymentOptions_Auto(TestConfigurationCDO testConfiguration, int siteId)
{
var paymentOptionList = SitePaymentRepository.GetSitePaymentInfoBySiteId(
testConfiguration,
siteId);
var lowestPriority = paymentOptionList.Min(x => x.Priority);
var paymentAuto = paymentOptionList.FirstOrDefault(x => x.Priority == lowestPriority);
PaymentOptions paymentOptions;
switch (paymentAuto.PaymentType)
{
case PaymentMethod.PayPalDirect:
case PaymentMethod.Braintree:
case PaymentMethod.BankTransfer:
case PaymentMethod.AdyenDropIn:
paymentOptions = new ClientCheckoutOptions() { paymentMethod = paymentAuto.PaymentType };
break;
case PaymentMethod.Klarna:
paymentOptions = new KlarnaOptions();
break;
case PaymentMethod.PayPalExpress:
default:
paymentOptions = new PaypalOptions();
break;
}
return paymentOptions;
}
public enum Scenario { ManualScenario_1, ManualScenario_2, ManualScenario_3, ManualScenario_4, ManualScenario_5, ManualScenario_6, ManualScenario_7, ManualScenario_8, ManualScenario_10, ManualScenario_11, ManualScenario_12, ManualScenario_13, ManualScenario_14 }
/// <summary>
/// Below method will set the Payment Type based on the Manual Regression Scenario
/// </summary>
/// <param name="testConfiguration"></param>
/// <param name="siteId"></param>
/// <returns></returns>
public static PaymentOptions GetPaymentOptions_ManualRegression(SharedParameters shared_parameters, Scenario Scenario)
{
var cultureCode = shared_parameters.site.EnumCultureCode();
if (cultureCode == CultureEnum.GB)
{
switch (Scenario)
{
case Scenario.ManualScenario_1:
case Scenario.ManualScenario_3:
case Scenario.ManualScenario_10:
return new ClientCheckoutOptions()
{
delivery = DeliveryMethod.Billing,
paymentMethod = PaymentMethod.PayPalDirect
};
case Scenario.ManualScenario_5:
return new KlarnaOptions()
{
klarnaPaymentOptions = KlarnaPaymentOptions.PayLater,
delivery = DeliveryMethod.Billing
};
case Scenario.ManualScenario_8:
case Scenario.ManualScenario_12:
return new KlarnaOptions()
{
klarnaPaymentOptions = KlarnaPaymentOptions.ByCard,
delivery = DeliveryMethod.Billing
};
case Scenario.ManualScenario_2:
case Scenario.ManualScenario_4:
case Scenario.ManualScenario_6:
case Scenario.ManualScenario_7:
case Scenario.ManualScenario_11:
case Scenario.ManualScenario_13:
case Scenario.ManualScenario_14:
default:
return new PaypalOptions()
{
byAccount = true
};
}
}
else
{
return GetPaymentOptions_NonGBCulture(shared_parameters.testConfiguration,
shared_parameters.site.SiteId);
}
}
/// <summary>
/// Specific to NonGB Culture: Below method will set the Payment Type from pre-defined selection
/// </summary>
/// <param name="testConfiguration"></param>
/// <param name="siteId"></param>
/// <returns></returns>
public static PaymentOptions GetPaymentOptions_NonGBCulture(TestConfigurationCDO testConfiguration, int siteId)
{
var paymentOptionList = SitePaymentRepository.GetSitePaymentInfoBySiteId(
testConfiguration,
siteId);
var paymentAuto = paymentOptionList.First(x => checkoutGroup.Contains(x.PaymentType));
return new ClientCheckoutOptions() { paymentMethod = paymentAuto.PaymentType };
}
}
}