Adding Barclays functionality
This commit is contained in:
parent
f65d2df7cf
commit
3506539420
5 changed files with 106 additions and 1 deletions
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BankingBot.Attributes;
|
||||
using BankingBot.Contracts;
|
||||
using BankingBot.Enums;
|
||||
using BankingBot.LoginCredentials;
|
||||
using BankingBot.Responses;
|
||||
using OpenQA.Selenium;
|
||||
|
||||
namespace BankingBot.ActionManagers.LoginManagers
|
||||
{
|
||||
[ProviderIdentifier(Provider.Barclays)]
|
||||
public class BarclaysLoginManager : IProviderLoginManager
|
||||
{
|
||||
private readonly IScriptManager _scriptManager;
|
||||
private readonly IBrowserBot _browserBot;
|
||||
|
||||
private static class Urls
|
||||
{
|
||||
public const string Login = "https://bank.barclays.co.uk/olb/auth/LoginLink.action";
|
||||
}
|
||||
|
||||
public BarclaysLoginManager(
|
||||
IBrowserBot browserBot,
|
||||
IScriptManager scriptManager)
|
||||
{
|
||||
_browserBot = browserBot;
|
||||
_scriptManager = scriptManager;
|
||||
}
|
||||
|
||||
public Response Login(ILoginCredentials credentials)
|
||||
{
|
||||
var barcCreds = credentials as BarclaysLoginCredentials;
|
||||
|
||||
_browserBot.WebDriver.Url = Urls.Login;
|
||||
_browserBot.WebDriver.Navigate();
|
||||
|
||||
_browserBot.WebDriver.FindElement(By.Id("surname")).SendKeys(barcCreds.Surname);
|
||||
|
||||
// Chosen to use membership number
|
||||
if (barcCreds.MembershipNumber != null)
|
||||
{
|
||||
_browserBot.WebDriver.FindElement(By.Id("membership-radio")).Click();
|
||||
_browserBot.WebDriver.FindElement(By.Id("membership-num")).SendKeys(barcCreds.MembershipNumber);
|
||||
}
|
||||
// Chosen to use card number
|
||||
else if (barcCreds.CardNumber != null)
|
||||
{
|
||||
_browserBot.WebDriver.FindElement(By.Id("card-radio")).Click();
|
||||
|
||||
var cardSplit = Helpers.CardHelpers.SplitCardNumber(barcCreds.CardNumber);
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
var fieldId = $"debitCardSet{i + 1}";
|
||||
_browserBot.WebDriver.FindElement(By.Id(fieldId)).SendKeys(cardSplit[i]);
|
||||
}
|
||||
}
|
||||
|
||||
_browserBot.WebDriver.FindElement(By.Id("forward")).Click();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -61,6 +61,7 @@
|
|||
<Compile Include="Contracts\IScriptManager.cs" />
|
||||
<Compile Include="Enums\Provider.cs" />
|
||||
<Compile Include="Enums\ResponseStatus.cs" />
|
||||
<Compile Include="LoginCredentials\BarclaysLoginCredentials.cs" />
|
||||
<Compile Include="LoginCredentials\LloydsLoginCredentials.cs" />
|
||||
<Compile Include="LoginCredentials\LoginCredentials.cs" />
|
||||
<Compile Include="ActionManagers\LoginManagers\LloydsLoginManager.cs" />
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
{
|
||||
public enum Provider
|
||||
{
|
||||
Lloyds
|
||||
Lloyds,
|
||||
Barclays
|
||||
}
|
||||
}
|
21
BankingBot/Helpers/CardHelpers.cs
Normal file
21
BankingBot/Helpers/CardHelpers.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace BankingBot.Helpers
|
||||
{
|
||||
public static class CardHelpers
|
||||
{
|
||||
public static string[] SplitCardNumber(string cardNumber)
|
||||
{
|
||||
if (cardNumber.Length != 16)
|
||||
throw new ArgumentException("Card number was have a length of 16 characters.");
|
||||
|
||||
return new[]
|
||||
{
|
||||
cardNumber.Substring(0, 4),
|
||||
cardNumber.Substring(4, 4),
|
||||
cardNumber.Substring(8, 4),
|
||||
cardNumber.Substring(12, 4)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
17
BankingBot/LoginCredentials/BarclaysLoginCredentials.cs
Normal file
17
BankingBot/LoginCredentials/BarclaysLoginCredentials.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using BankingBot.Attributes;
|
||||
using BankingBot.Enums;
|
||||
|
||||
namespace BankingBot.LoginCredentials
|
||||
{
|
||||
[ProviderIdentifier(Provider.Barclays)]
|
||||
public class BarclaysLoginCredentials : LoginCredentials
|
||||
{
|
||||
public string Surname;
|
||||
public string MembershipNumber;
|
||||
public string CardNumber;
|
||||
public string SortCode;
|
||||
public string AccountNumber;
|
||||
public string Password;
|
||||
public string MemorableWord;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue