diff --git a/.gitignore b/.gitignore index d8d2ca6..a78477e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ -## Ignore Visual Studio temporary files, build results, and +## ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files *.suo *.user +*.userprefs *.sln.docstates # Build results @@ -191,3 +192,8 @@ Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ *.nupkg + +# Visual studio files +.vs + + diff --git a/.travis.yml b/.travis.yml index 77983a6..21d73f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,14 @@ -sudo: false +sudo: required language: csharp -solution: PromisePayDotNet.sln -install: - - nuget restore PromisePayDotNet.sln - - nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner -script: - - xbuild /p:Configuration=Release PromisePayDotNet.sln - - mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./PromisePayDotNet.Tests/bin/Release/PromisePayDotNet.Tests.dll \ No newline at end of file +dotnet: 1.0.3 +mono: + - 4.8.0 +dist: trusty +os: + - linux +script: + - dotnet restore + - dotnet build PromisePayDotNet + - dotnet build PromisePayDotNet.Tests + - cd PromisePayDotNet.Tests + - dotnet test diff --git a/PromisePayDotNet.Tests/AbstractTest.cs b/PromisePayDotNet.Tests/AbstractTest.cs index ec5a3a1..ef1781f 100644 --- a/PromisePayDotNet.Tests/AbstractTest.cs +++ b/PromisePayDotNet.Tests/AbstractTest.cs @@ -1,13 +1,42 @@ -using Moq; -using RestSharp; -using RestSharp.Authenticators; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Moq; +using PromisePayDotNet.Internals; +using PromisePayDotNet.Settings; using System; using System.Net; +using System.Threading.Tasks; namespace PromisePayDotNet.Tests { - public class AbstractTest + public abstract class AbstractTest { + private static IServiceProvider CreateDi(IRestClient client = null) + { + var services = new ServiceCollection(); + if (null != client) + { + services.AddTransient(ci => client); + } + services.AddPromisePay(new PromisePaySettings + { + ApiUrl = "https://test.api.promisepay.com", + Login = "idsidorov@gmail.com", + Password = "mJrUGo2Vxuo9zqMVAvkw" + }); + if (null != client) + { + services.AddTransient(ci => client); + } + services.AddOptions(); + services.AddLogging(); + return services.BuildServiceProvider(); + } + + + protected TRepo Get() => CreateDi().GetRequiredService(); + protected TRepo Get(IRestClient client) => CreateDi(client).GetRequiredService(); + protected Mock GetMockClient(string content) { return GetMockClient(content, HttpStatusCode.OK); @@ -15,7 +44,7 @@ protected Mock GetMockClient(string content) protected Mock GetMockClient(string content, HttpStatusCode StatusCode) { - var response = new Mock(MockBehavior.Strict); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns(""); @@ -24,7 +53,7 @@ protected Mock GetMockClient(string content, HttpStatusCode StatusC var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); return client; } diff --git a/PromisePayDotNet.Tests/AddressTest.cs b/PromisePayDotNet.Tests/AddressTest.cs index 89bb267..45dfb3d 100644 --- a/PromisePayDotNet.Tests/AddressTest.cs +++ b/PromisePayDotNet.Tests/AddressTest.cs @@ -1,35 +1,35 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Implementations; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; using System.IO; +using Xunit; namespace PromisePayDotNet.Tests { public class AddressTest : AbstractTest { - [Test] + [Fact] public void AddressDeserialization() { var jsonStr = "{ \"addressline1\": null, \"addressline2\": null, \"postcode\": null, \"city\": null, \"state\": null, \"id\": \"07ed45e5-bb9d-459f-bb7b-a02ecb38f443\", \"country\": \"Australia\", \"links\": { \"self\": \"/addresses/07ed45e5-bb9d-459f-bb7b-a02ecb38f443\" }}"; var address = JsonConvert.DeserializeObject
(jsonStr); - Assert.IsNotNull(address); - Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id); + Assert.NotNull(address); + Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id); } - [Test] + [Fact] public void GetAddressSuccessfully() { - var content = File.ReadAllText("../../Fixtures/address_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/address_get_by_id.json"); var client = GetMockClient(content); - var repo = new AddressRepository(client.Object); + var repo = Get(client.Object); var address = repo.GetAddressById("07ed45e5-bb9d-459f-bb7b-a02ecb38f443"); client.VerifyAll(); - Assert.IsNotNull(address); - Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id); + Assert.NotNull(address); + Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", address.Id); } } diff --git a/PromisePayDotNet.Tests/BankAccountTest.cs b/PromisePayDotNet.Tests/BankAccountTest.cs index 0244991..2c7c731 100644 --- a/PromisePayDotNet.Tests/BankAccountTest.cs +++ b/PromisePayDotNet.Tests/BankAccountTest.cs @@ -1,30 +1,31 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; using System; using System.IO; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class BankAccountTest : AbstractTest { - [Test] + [Fact] public void BankAccountDeserialization() { const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:24:19.248Z\", \"updated_at\": \"2015-04-26T06:24:19.248Z\", \"id\": \"8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"currency\": \"USD\", \"bank\": { \"bank_name\": \"Test Me\", \"country\": \"AUS\", \"account_name\": \"Test Account\", \"routing_number\": \"XXXXXXX3\", \"account_number\": \"XXXX344\", \"holder_type\": \"personal\", \"account_type\": \"savings\" }, \"links\": { \"self\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"users\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a/users\" } }"; var bankAccount = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("8d65c86c-14f4-4abf-a979-eba0a87b283a", bankAccount.Id); - Assert.AreEqual("USD", bankAccount.Currency); + Assert.Equal("8d65c86c-14f4-4abf-a979-eba0a87b283a", bankAccount.Id); + Assert.Equal("USD", bankAccount.Currency); } - [Test] + [Fact] public void CreateBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_create.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_create.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var account = new BankAccount @@ -44,61 +45,61 @@ public void CreateBankAccountSuccessfully() }; var createdAccount = repo.CreateBankAccount(account); client.VerifyAll(); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount.Id); - Assert.AreEqual("AUD", createdAccount.Currency); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount.CreatedAt); - Assert.IsNotNull(createdAccount.UpdatedAt); - Assert.AreEqual("XXX789", createdAccount.Bank.AccountNumber); //Account number is masked + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); + Assert.Equal("XXX789", createdAccount.Bank.AccountNumber); //Account number is masked } - [Test] + [Fact] public void GetBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_get_by_id.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string id = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; var gotAccount = repo.GetBankAccountById(id); client.VerifyAll(); - Assert.AreEqual(id, gotAccount.Id); + Assert.Equal(id, gotAccount.Id); } - [Test] + [Fact] public void GetBankAccountEmptyId() { var client = GetMockClient(""); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.GetBankAccountById(string.Empty)); } - [Test] + [Fact] public void GetUserForBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_get_users.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var gotUser = repo.GetUserForBankAccount("ec9bf096-c505-4bef-87f6-18822b9dbf2c"); client.VerifyAll(); - Assert.IsNotNull(gotUser); + Assert.NotNull(gotUser); - Assert.AreEqual(userId, gotUser.Id); + Assert.Equal(userId, gotUser.Id); } - [Test] + [Fact] public void DeleteBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_delete.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); var result = repo.DeleteBankAccount("e923013e-61e9-4264-9622-83384e13d2b9"); client.VerifyAll(); - Assert.IsTrue(result); + Assert.True(result); } } } diff --git a/PromisePayDotNet.Tests/CardAccountTest.cs b/PromisePayDotNet.Tests/CardAccountTest.cs index 9305897..ed31e9b 100644 --- a/PromisePayDotNet.Tests/CardAccountTest.cs +++ b/PromisePayDotNet.Tests/CardAccountTest.cs @@ -1,31 +1,31 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Implementations; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; using System; using System.IO; +using Xunit; namespace PromisePayDotNet.Tests { public class CardAccountTest : AbstractTest { - [Test] + [Fact] public void CardAccountDeserialization() { const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:28:55.559Z\", \"updated_at\": \"2015-04-26T06:28:55.559Z\", \"id\": \"ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"currency\": \"USD\", \"card\": { \"type\": \"visa\", \"full_name\": \"Joe Frio\", \"number\": \"XXXX-XXXX-XXXX-1111\", \"expiry_month\": \"5\", \"expiry_year\": \"2016\" }, \"links\": { \"self\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"users\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19/users\" } }"; var cardAccount = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("ea464d25-fc9a-4887-861a-3d8ec2e12c19", cardAccount.Id); - Assert.AreEqual("USD", cardAccount.Currency); - Assert.AreEqual("Joe Frio", cardAccount.Card.FullName); + Assert.Equal("ea464d25-fc9a-4887-861a-3d8ec2e12c19", cardAccount.Id); + Assert.Equal("USD", cardAccount.Currency); + Assert.Equal("Joe Frio", cardAccount.Card.FullName); } - [Test] + [Fact] public void CreateCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_create.json"); + var content = Files.ReadAllText("./Fixtures/card_account_create.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var account = new CardAccount @@ -44,61 +44,61 @@ public void CreateCardAccountSuccessfully() }; var createdAccount = repo.CreateCardAccount(account); client.VerifyAll(); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount.Id); - Assert.AreEqual("AUD", createdAccount.Currency); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount.CreatedAt); - Assert.IsNotNull(createdAccount.UpdatedAt); + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); } - [Test] + [Fact] public void GetCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/card_account_get_by_id.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); var gotAccount = repo.GetCardAccountById("25d34744-8ef0-46a4-8b18-2a8322933cd1"); client.VerifyAll(); - Assert.AreEqual("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount.Id); + Assert.Equal("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount.Id); } - [Test] + [Fact] public void GetCardAccountEmptyId() { var client = GetMockClient(""); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.GetCardAccountById(string.Empty)); } - [Test] + [Fact] public void GetUserForCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/card_account_get_users.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); var gotUser = repo.GetUserForCardAccount("25d34744-8ef0-46a4-8b18-2a8322933cd1"); client.VerifyAll(); - Assert.IsNotNull(gotUser); - Assert.AreEqual("1", gotUser.Id); + Assert.NotNull(gotUser); + Assert.Equal("1", gotUser.Id); } - [Test] + [Fact] public void DeleteCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/card_account_delete.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); const string id = "25d34744-8ef0-46a4-8b18-2a8322933cd1"; var result = repo.DeleteCardAccount(id); client.VerifyAll(); - Assert.IsTrue(result); + Assert.True(result); } } diff --git a/PromisePayDotNet.Tests/CompanyTest.cs b/PromisePayDotNet.Tests/CompanyTest.cs index 492cb2d..86cf0da 100644 --- a/PromisePayDotNet.Tests/CompanyTest.cs +++ b/PromisePayDotNet.Tests/CompanyTest.cs @@ -1,57 +1,58 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; using System.IO; using System.Linq; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class CompanyTest : AbstractTest { - [Test] + [Fact] public void CompanyDeserialization() { const string jsonStr = "{ \"legal_name\": \"Igor\", \"name\": null, \"id\": \"e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\", \"related\": { \"address\": \"07ed45e5-bb9d-459f-bb7b-a02ecb38f443\" }, \"links\": { \"self\": \"/companies/e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\" } }"; var company = JsonConvert.DeserializeObject(jsonStr); - Assert.IsNotNull(company); - Assert.AreEqual("Igor", company.LegalName); - Assert.AreEqual("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", company.Id); + Assert.NotNull(company); + Assert.Equal("Igor", company.LegalName); + Assert.Equal("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", company.Id); } - [Test] + [Fact] public void ListCompaniesSuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_list.json"); + var content = Files.ReadAllText("./Fixtures/companies_list.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var companies = repo.ListCompanies(); client.VerifyAll(); - Assert.IsNotNull(companies); - Assert.IsTrue(companies.Any()); + Assert.NotNull(companies); + Assert.True(companies.Any()); } - [Test] + [Fact] public void GetCompanyByIdSuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/companies_get_by_id.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var company = repo.GetCompanyById("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5"); client.VerifyAll(); - Assert.IsNotNull(company); - Assert.AreEqual("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5",company.Id); + Assert.NotNull(company); + Assert.Equal("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5",company.Id); } - [Test] + [Fact] public void CreateCompanySuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_create.json"); + var content = Files.ReadAllText("./Fixtures/companies_create.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; var createdCompany = repo.CreateCompany(new Company { @@ -60,17 +61,17 @@ public void CreateCompanySuccessfully() Country = "AUS" }, userId); client.VerifyAll(); - Assert.IsNotNull(createdCompany); - Assert.IsNotNull(createdCompany.Id); + Assert.NotNull(createdCompany); + Assert.NotNull(createdCompany.Id); } - [Test] + [Fact] public void EditCompanySuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_edit.json"); + var content = Files.ReadAllText("./Fixtures/companies_edit.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var editedCompany = repo.EditCompany(new Company { Id = "739dcfc5-adf0-4a00-b639-b4e05922994d", @@ -79,7 +80,7 @@ public void EditCompanySuccessfully() Country = "AUS" }); client.VerifyAll(); - Assert.AreEqual("Test company #2", editedCompany.Name); + Assert.Equal("Test company #2", editedCompany.Name); } diff --git a/PromisePayDotNet.Tests/ConfigTest.cs b/PromisePayDotNet.Tests/ConfigTest.cs deleted file mode 100644 index 4132d2a..0000000 --- a/PromisePayDotNet.Tests/ConfigTest.cs +++ /dev/null @@ -1,25 +0,0 @@ -using NUnit.Framework; -using System; -using System.Collections; -using System.Configuration; - -namespace PromisePayDotNet.Tests -{ - public class ConfigTest - { - [Test] - public void TestPromisePayConfig() - { - var ht = ConfigurationManager.GetSection("PromisePay/Settings") as Hashtable; - if (ht != null) - { - var keyVal = ht["ApiUrl"] as String; - Assert.AreEqual("https://test.api.promisepay.com", keyVal, "App.config section is wrong"); - } - else - { - Assert.Fail(); - } - } - } -} diff --git a/PromisePayDotNet.Tests/DITest.cs b/PromisePayDotNet.Tests/DITest.cs deleted file mode 100644 index 9bf7c2f..0000000 --- a/PromisePayDotNet.Tests/DITest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.Practices.Unity; -using NUnit.Framework; -using PromisePayDotNet.DI; -using PromisePayDotNet.Interfaces; - -namespace PromisePayDotNet.Tests -{ - public class DITest - { - [Test] - public void TestDIContainer() - { - var container = new UnityContainer(); - InitUnityContainer.Init(container); - var userService = container.Resolve(); - Assert.IsNotNull(userService); - } - } -} diff --git a/PromisePayDotNet.Tests/DynamicAddressTest.cs b/PromisePayDotNet.Tests/DynamicAddressTest.cs index 5b963f4..39d5d9d 100644 --- a/PromisePayDotNet.Tests/DynamicAddressTest.cs +++ b/PromisePayDotNet.Tests/DynamicAddressTest.cs @@ -1,35 +1,35 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System.Collections.Generic; using System.IO; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class DynamicAddressTest : AbstractTest { - [Test] + [Fact] public void AddressDeserialization() { var jsonStr = "{ \"addressline1\": null, \"addressline2\": null, \"postcode\": null, \"city\": null, \"state\": null, \"id\": \"07ed45e5-bb9d-459f-bb7b-a02ecb38f443\", \"country\": \"Australia\", \"links\": { \"self\": \"/addresses/07ed45e5-bb9d-459f-bb7b-a02ecb38f443\" }}"; var address = JsonConvert.DeserializeObject>(jsonStr); - Assert.IsNotNull(address); - Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", (string)address["id"]); + Assert.NotNull(address); + Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", (string)address["id"]); } - [Test] + [Fact] public void GetAddressSuccessfully() { - var content = File.ReadAllText("../../Fixtures/address_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/address_get_by_id.json"); var client = GetMockClient(content); - var repo = new AddressRepository(client.Object); + var repo = Get(client.Object); var address = repo.GetAddressById("07ed45e5-bb9d-459f-bb7b-a02ecb38f443"); client.VerifyAll(); - Assert.IsNotNull(address); - Assert.AreEqual("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", (string)address["id"]); + Assert.NotNull(address); + Assert.Equal("07ed45e5-bb9d-459f-bb7b-a02ecb38f443", (string)address.Id); } } diff --git a/PromisePayDotNet.Tests/DynamicBankAccountTest.cs b/PromisePayDotNet.Tests/DynamicBankAccountTest.cs index 84ccc53..072529a 100644 --- a/PromisePayDotNet.Tests/DynamicBankAccountTest.cs +++ b/PromisePayDotNet.Tests/DynamicBankAccountTest.cs @@ -1,102 +1,103 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System; using System.Collections.Generic; using System.IO; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class DynamicBankAccountTest : AbstractTest { - [Test] + [Fact] public void BankAccountDeserialization() { const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:24:19.248Z\", \"updated_at\": \"2015-04-26T06:24:19.248Z\", \"id\": \"8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"currency\": \"USD\", \"bank\": { \"bank_name\": \"Test Me\", \"country\": \"AUS\", \"account_name\": \"Test Account\", \"routing_number\": \"XXXXXXX3\", \"account_number\": \"XXXX344\", \"holder_type\": \"personal\", \"account_type\": \"savings\" }, \"links\": { \"self\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a\", \"users\": \"/bank_accounts/8d65c86c-14f4-4abf-a979-eba0a87b283a/users\" } }"; - var bankAccount = JsonConvert.DeserializeObject>(jsonStr); - Assert.AreEqual("8d65c86c-14f4-4abf-a979-eba0a87b283a", (string)bankAccount["id"]); - Assert.AreEqual("USD", (string)bankAccount["currency"]); + var bankAccount = JsonConvert.DeserializeObject(jsonStr); + Assert.Equal("8d65c86c-14f4-4abf-a979-eba0a87b283a", (string)bankAccount.Id); + Assert.Equal("USD", (string)bankAccount.Currency); } - [Test] + [Fact] public void CreateBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_create.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_create.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before - var account = new Dictionary - { { "user_id", userId }, - { "active" , true }, - { "bank" , new Dictionary - { {"bank_name" , "Test bank, inc"}, - {"account_name" , "Test account"}, - {"account_number" , "8123456789"}, - {"account_type" , "savings"}, - {"country" , "AUS"}, - {"holder_type" , "personal"}, - {"routing_number" , "123456"} - }}}; + var account = new BankAccount + { UserId= userId , + Active = true , + Bank = new Bank + { BankName = "Test bank, inc", + AccountName = "Test account", + AccountNumber = "8123456789", + AccountType = "savings", + Country = "AUS", + HolderType = "personal", + RoutingNumber = "123456" + } + }; var createdAccount = repo.CreateBankAccount(account); client.VerifyAll(); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount["id"]); - Assert.AreEqual("AUD", (string)createdAccount["currency"]); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount["created_at"]); - Assert.IsNotNull(createdAccount["updated_at"]); - var bank = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(createdAccount["bank"])); - Assert.AreEqual("XXX789", (string)bank["account_number"]); //Account number is masked + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", (string)createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); + Assert.Equal("XXX789", (string)createdAccount.Bank.AccountNumber); //Account number is masked } - [Test] + [Fact] public void GetBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_get_by_id.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string id = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; var gotAccount = repo.GetBankAccountById(id); client.VerifyAll(); - Assert.AreEqual(id, gotAccount["id"]); + Assert.Equal(id, gotAccount.Id); } - [Test] + [Fact] public void GetBankAccountEmptyId() { var client = GetMockClient(""); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.GetBankAccountById(string.Empty)); } - [Test] + [Fact] public void GetUserForBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_get_users.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var gotUser = repo.GetUserForBankAccount("ec9bf096-c505-4bef-87f6-18822b9dbf2c"); client.VerifyAll(); - Assert.IsNotNull(gotUser); + Assert.NotNull(gotUser); - Assert.AreEqual(userId, gotUser["id"]); + Assert.Equal(userId, gotUser.Id); } - [Test] + [Fact] public void DeleteBankAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/bank_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/bank_account_delete.json"); var client = GetMockClient(content); - var repo = new BankAccountRepository(client.Object); + var repo = Get(client.Object); var result = repo.DeleteBankAccount("e923013e-61e9-4264-9622-83384e13d2b9"); client.VerifyAll(); - Assert.IsTrue(result); + Assert.True(result); } } diff --git a/PromisePayDotNet.Tests/DynamicCardAccountTest.cs b/PromisePayDotNet.Tests/DynamicCardAccountTest.cs index 730b122..c3a4f2e 100644 --- a/PromisePayDotNet.Tests/DynamicCardAccountTest.cs +++ b/PromisePayDotNet.Tests/DynamicCardAccountTest.cs @@ -1,106 +1,106 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System; using System.Collections.Generic; using System.IO; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class DynamicCardAccountTest : AbstractTest { - [Test] + [Fact] public void CardAccountDeserialization() { const string jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-26T06:28:55.559Z\", \"updated_at\": \"2015-04-26T06:28:55.559Z\", \"id\": \"ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"currency\": \"USD\", \"card\": { \"type\": \"visa\", \"full_name\": \"Joe Frio\", \"number\": \"XXXX-XXXX-XXXX-1111\", \"expiry_month\": \"5\", \"expiry_year\": \"2016\" }, \"links\": { \"self\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19\", \"users\": \"/card_accounts/ea464d25-fc9a-4887-861a-3d8ec2e12c19/users\" } }"; - var cardAccount = JsonConvert.DeserializeObject>(jsonStr); - Assert.AreEqual("ea464d25-fc9a-4887-861a-3d8ec2e12c19", (string)cardAccount["id"]); - Assert.AreEqual("USD", (string)cardAccount["currency"]); - var card = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(cardAccount["card"])); - - Assert.AreEqual("Joe Frio", card["full_name"]); + var cardAccount = JsonConvert.DeserializeObject(jsonStr); + Assert.Equal("ea464d25-fc9a-4887-861a-3d8ec2e12c19", (string)cardAccount.Id); + Assert.Equal("USD", (string)cardAccount.Currency); + + Assert.Equal("Joe Frio", cardAccount.Card.FullName); } - [Test] + [Fact] public void CreateCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_create.json"); + var content = Files.ReadAllText("./Fixtures/card_account_create.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); const string userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before - var account = new Dictionary - { - { "user_id", userId }, - { "active", true }, - { "card" , new Dictionary - { - { "full_name", "Batman" }, - { "expiry_month", "11" }, - { "expiry_year", "2020" }, - { "number" , "4111111111111111"}, - { "type" , "visa"}, - { "cvv" , "123"} + var account = new CardAccount + { + //userid = userId , + // active = true , + Card = new Card + { + FullName = "Batman", + ExpiryMonth = "11", + ExpiryYear = "2020", + Number = "4111111111111111", + Type = "visa", + CVV = "123" } - }}; + }; var createdAccount = repo.CreateCardAccount(account); client.VerifyAll(); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount["id"]); - Assert.AreEqual("AUD", (string)createdAccount["currency"]); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount["created_at"]); - Assert.IsNotNull(createdAccount["updated_at"]); + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", (string)createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); } - [Test] + [Fact] public void GetCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/card_account_get_by_id.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); var gotAccount = repo.GetCardAccountById("25d34744-8ef0-46a4-8b18-2a8322933cd1"); client.VerifyAll(); - Assert.AreEqual("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount["id"]); + Assert.Equal("25d34744-8ef0-46a4-8b18-2a8322933cd1", gotAccount.Id); } - - [Test] + + [Fact] public void GetCardAccountEmptyId() { var client = GetMockClient(""); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.GetCardAccountById(string.Empty)); } - - [Test] + + [Fact] public void GetUserForCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/card_account_get_users.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); var gotUser = repo.GetUserForCardAccount("25d34744-8ef0-46a4-8b18-2a8322933cd1"); client.VerifyAll(); - Assert.IsNotNull(gotUser); - Assert.AreEqual("1", gotUser["id"]); + Assert.NotNull(gotUser); + Assert.Equal("1", gotUser.Id); } - - [Test] + + [Fact] public void DeleteCardAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/card_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/card_account_delete.json"); var client = GetMockClient(content); - var repo = new CardAccountRepository(client.Object); + var repo = Get(client.Object); const string id = "25d34744-8ef0-46a4-8b18-2a8322933cd1"; var result = repo.DeleteCardAccount(id); client.VerifyAll(); - Assert.IsTrue(result); + Assert.True(result); } - + } } diff --git a/PromisePayDotNet.Tests/DynamicCompanyTest.cs b/PromisePayDotNet.Tests/DynamicCompanyTest.cs index 953a340..6d99709 100644 --- a/PromisePayDotNet.Tests/DynamicCompanyTest.cs +++ b/PromisePayDotNet.Tests/DynamicCompanyTest.cs @@ -1,98 +1,99 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System.Collections.Generic; using System.IO; using System.Linq; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class DynamicCompanyTest : AbstractTest { - [Test] + [Fact] public void CompanyDeserialization() { const string jsonStr = "{ \"legal_name\": \"Igor\", \"name\": null, \"id\": \"e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\", \"related\": { \"address\": \"07ed45e5-bb9d-459f-bb7b-a02ecb38f443\" }, \"links\": { \"self\": \"/companies/e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\" } }"; - var company = JsonConvert.DeserializeObject>(jsonStr); - Assert.IsNotNull(company); - Assert.AreEqual("Igor", (string)company["legal_name"]); - Assert.AreEqual("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", (string)company["id"]); + var company = JsonConvert.DeserializeObject(jsonStr); + Assert.NotNull(company); + Assert.Equal("Igor", (string)company.LegalName); + Assert.Equal("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", (string)company.Id); } - [Test] + [Fact] public void ListCompaniesSuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_list.json"); + var content = Files.ReadAllText("./Fixtures/companies_list.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var companies = repo.ListCompanies(); client.VerifyAll(); - Assert.IsNotNull(companies); - Assert.IsTrue(companies.Any()); + Assert.NotNull(companies); + Assert.True(companies.Any()); } - [Test] + [Fact] public void GetCompanyByIdSuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/companies_get_by_id.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); + var repo = Get(client.Object); var company = repo.GetCompanyById("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5"); client.VerifyAll(); - Assert.IsNotNull(company); - Assert.AreEqual("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", (string)company["id"]); + Assert.NotNull(company); + Assert.Equal("e466dfb4-f05c-4c7f-92a3-09a0a28c7af5", (string)company.Id); } - [Test] + [Fact] public void CreateCompanySuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_create.json"); + var content = Files.ReadAllText("./Fixtures/companies_create.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); - var createdCompany = repo.CreateCompany(new Dictionary - { { "legal_name", "Test company #1" }, - { "name", "Test company #1" }, - {"country", "AUS"}, - {"tax_number", string.Empty}, - {"charge_tax", string.Empty}, - {"address_line1", string.Empty}, - {"address_line2", string.Empty}, - {"city", string.Empty}, - {"state", string.Empty}, - {"zip", string.Empty} - }); + var repo = Get(client.Object); + var createdCompany = repo.CreateCompany(new Company + {LegalName = "Test company #1" , + Name = "Test company #1" , + Country = "AUS", + TaxNumber = string.Empty, + ChargeTax = string.Empty, + AddressLine1 = string.Empty, + AddressLine2 = string.Empty, + City = string.Empty, + State = string.Empty, + Zip = string.Empty + }, "234345"); client.VerifyAll(); - Assert.IsNotNull(createdCompany); - Assert.IsNotNull(createdCompany["id"]); - Assert.AreEqual("Test company #1", (string)createdCompany["legal_name"]); + Assert.NotNull(createdCompany); + Assert.NotNull(createdCompany.Id); + Assert.Equal("Test company #1", (string)createdCompany.LegalName); } - [Test] + [Fact] public void EditCompanySuccessfully() { - var content = File.ReadAllText("../../Fixtures/companies_edit.json"); + var content = Files.ReadAllText("./Fixtures/companies_edit.json"); var client = GetMockClient(content); - var repo = new CompanyRepository(client.Object); - var editedCompany = repo.EditCompany(new Dictionary + var repo = Get(client.Object); + var editedCompany = repo.EditCompany(new Company { - {"id" , "739dcfc5-adf0-4a00-b639-b4e05922994d"}, - {"legal_name" , "Test company #2"}, - {"name" , "Test company #2"}, - {"country" , "AUS"}, - {"tax_number", string.Empty}, - {"charge_tax", string.Empty}, - {"address_line1", string.Empty}, - {"address_line2", string.Empty}, - {"city", string.Empty}, - {"state", string.Empty}, - {"zip", string.Empty} + Id = "739dcfc5-adf0-4a00-b639-b4e05922994d", + LegalName = "Test company #2", + Name = "Test company #2", + Country = "AUS", + TaxNumber = string.Empty, + ChargeTax = string.Empty, + AddressLine1 = string.Empty, + AddressLine2 = string.Empty, + City = string.Empty, + State = string.Empty, + Zip = string.Empty }); client.VerifyAll(); - Assert.AreEqual("Test company #2", (string)editedCompany["name"]); + Assert.Equal("Test company #2", (string)editedCompany.Name); } diff --git a/PromisePayDotNet.Tests/DynamicFeeTest.cs b/PromisePayDotNet.Tests/DynamicFeeTest.cs index f3a2922..d373d0b 100644 --- a/PromisePayDotNet.Tests/DynamicFeeTest.cs +++ b/PromisePayDotNet.Tests/DynamicFeeTest.cs @@ -1,88 +1,94 @@ using Newtonsoft.Json; -using NUnit.Framework; +using Xunit; using PromisePayDotNet.Exceptions; -using PromisePayDotNet.Dynamic.Implementations; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Enums; namespace PromisePayDotNet.Tests { public class DynamicFeeTest : AbstractTest { - [Test] + [Fact] public void FeeDeserialization() { const string jsonStr = "{ \"id\": \"58e15f18-500e-4cdc-90ca-65e1f1dce565\", \"created_at\": \"2014-12-29T08:31:42.168Z\", \"updated_at\": \"2014-12-29T08:31:42.168Z\", \"name\": \"Buyer Fee @ 10%\", \"fee_type_id\": 2, \"amount\": 1000, \"cap\": null, \"min\": null, \"max\": null, \"to\": \"buyer\", \"links\": { \"self\": \"/fees/58e15f18-500e-4cdc-90ca-65e1f1dce565\" } }"; - var fee = JsonConvert.DeserializeObject>(jsonStr); - Assert.IsNotNull(fee); - Assert.AreEqual("58e15f18-500e-4cdc-90ca-65e1f1dce565", (string)fee["id"]); - Assert.AreEqual("Buyer Fee @ 10%", (string)fee["name"]); + var fee = JsonConvert.DeserializeObject(jsonStr); + Assert.NotNull(fee); + Assert.Equal("58e15f18-500e-4cdc-90ca-65e1f1dce565", (string)fee.Id); + Assert.Equal("Buyer Fee @ 10%", (string)fee.Name); } - [Test] + [Fact] public void CreateFeeSuccessfully() { - var content = File.ReadAllText("../../Fixtures/fees_create.json"); + var content = Files.ReadAllText("./Fixtures/fees_create.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var feeId = Guid.NewGuid().ToString(); - var createdFee = repo.CreateFee(new Dictionary - { { "id", feeId }, - { "amount" , "1000"}, - { "name" , "Test fee #1"}, - { "fee_type_id" , "1"}, - { "cap" , "1"}, - { "max" , "3"}, - { "min" , "2"}, - { "to" , "buyer"} + var createdFee = repo.CreateFee(new Fee + { + Id = feeId, + Amount = 1000, + Name = "Test fee #1", + FeeType = (FeeType)1, + Cap = "1", + Max = "3", + Min = "2", + To = FeeToType.Buyer }); - Assert.IsNotNull(createdFee); + Assert.NotNull(createdFee); + Assert.Equal(FeeToType.Buyer, createdFee.To); + Assert.Equal(FeeType.Fixed, createdFee.FeeType); } - [Test] + [Fact] public void CreateFeeWrongTo() { var client = GetMockClient(""); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var feeId = Guid.NewGuid().ToString(); - Assert.Throws(() => repo.CreateFee(new Dictionary - { { "id", feeId }, - { "amount" , "1000"}, - { "name" , "Test fee #1"}, - { "fee_type_id" , "1"}, - { "cap" , "1"}, - { "max" , "3"}, - { "min" , "2"}, - { "to" , ""} + Assert.Throws(() => repo.CreateFee(new Fee + { + Id = feeId, + Amount = 1000, + Name = "Test fee #1", + FeeType = (FeeType)1, + Cap = "1", + Max = "3", + Min = "2" + //To = None })); } - [Test] + [Fact] public void GetFeeByIdSuccessfull() { - var content = File.ReadAllText("../../Fixtures/fees_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/fees_get_by_id.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); const string id = "79116c9f-d750-4faa-85c7-b7da36f23b38"; var fee = repo.GetFeeById(id); - Assert.AreEqual(id, (string)fee["id"]); + Assert.Equal(id, (string)fee.Id); } - [Test] + [Fact] public void ListFeeSuccessfully() { - var content = File.ReadAllText("../../Fixtures/fees_list.json"); + var content = Files.ReadAllText("./Fixtures/fees_list.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var fees = repo.ListFees(); - Assert.IsNotNull(fees); - Assert.IsTrue(fees.Any()); + Assert.NotNull(fees); + Assert.True(fees.Any()); } } } diff --git a/PromisePayDotNet.Tests/DynamicItemTest.cs b/PromisePayDotNet.Tests/DynamicItemTest.cs index ab28ff0..9c5ca44 100644 --- a/PromisePayDotNet.Tests/DynamicItemTest.cs +++ b/PromisePayDotNet.Tests/DynamicItemTest.cs @@ -1,112 +1,112 @@ using Moq; using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using PromisePayDotNet.Exceptions; -using RestSharp; -using RestSharp.Authenticators; +using PromisePayDotNet.Internals; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Enums; namespace PromisePayDotNet.Tests { public class DynamicItemTest : AbstractTest { - [Test] + [Fact] public void ItemDeserialization() { var jsonStr = " { \"id\": \"293\", \"name\": \"Testing\", \"description\": \"This is the description\", \"created_at\": \"2015-05-01T04:42:25.595Z\", \"updated_at\": \"2015-05-01T04:42:25.595Z\", \"state\": \"pending\", \"deposit_reference\": \"9140122157\", \"payment_type_id\": 1, \"status\": 22000,\"amount\": 6000, \"buyer_name\": \"Joe Frio\", \"buyer_country\": \"USA\", \"buyer_email\": \"joe.test@promisepay.com\",\"seller_name\": \"Julie Boatsman\", \"seller_country\": \"USA\", \"seller_email\": \"julie.test@promisepay.com\", \"currency\": \"USD\",\"links\": { \"self\": \"/items/293\", \"buyers\": \"/items/293/buyers\", \"sellers\": \"/items/293/sellers\", \"status\": \"/items/293/status\", \"fees\": \"/items/293/fees\", \"transactions\": \"/items/293/transactions\" } }"; var item = JsonConvert.DeserializeObject>(jsonStr); - Assert.AreEqual("293", item["id"]); + Assert.Equal("293", item["id"]); } - [Test] + [Fact] public void CreateItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_create.json"); + var content = Files.ReadAllText("./Fixtures/items_create.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); const string id = "5e81906c-e14b-42a8-952f-4a0d1f1a4bb8"; const string buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before const string sellerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e"; //some user created before - var item = new Dictionary + var item = new Item { - {"id" , id}, - {"name" , "Test Item #1"}, - {"amount" , 1000}, - {"payment_type" , 2}, - {"buyer_id" , buyerId}, - {"seller_id" , sellerId}, - {"fee_ids" , ""}, - {"description" , "Test item #1 description"} + Id= id, + Name= "Test Item #1", + Amount= 1000, + PaymentType= (PaymentType)2, + BuyerId= buyerId, + SellerId= sellerId, + Description= "Test item #1 description" }; var createdItem = repo.CreateItem(item); - Assert.AreEqual(item["id"], createdItem["id"]); - Assert.AreEqual(item["name"], createdItem["name"]); - Assert.AreEqual(item["amount"], createdItem["amount"]); - Assert.AreEqual(item["payment_type"], createdItem["payment_type_id"]); - Assert.AreEqual(item["description"], createdItem["description"]); + Assert.Equal(item.Id, createdItem.Id); + Assert.Equal(item.Name, createdItem.Name); + Assert.Equal(item.Amount, createdItem.Amount); + Assert.Equal(item.PaymentType, createdItem.PaymentType); + Assert.Equal(item.Description, createdItem.Description); } - [Test] + [Fact] public void ListAllItemsSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_list.json"); + var content = Files.ReadAllText("./Fixtures/items_list.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items var items = repo.ListItems(200); - Assert.IsNotNull(items); - Assert.IsTrue(items.Any()); + Assert.NotNull(items); + Assert.True(items.Any()); } - [Test] + [Fact] public void ListAllItemsNegativeParams() { var client = GetMockClient(""); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items Assert.Throws(() => repo.ListItems(-10, -10)); } - [Test] + [Fact] public void ListAllItemsTooHighLimit() { var client = GetMockClient(""); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items Assert.Throws(() => repo.ListItems(500)); } - [Test] + [Fact] public void GetItemSuccessful() { //First, create a user with known id - var content = File.ReadAllText("../../Fixtures/items_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/items_get_by_id.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); const string id = "5e81906c-e14b-42a8-952f-4a0d1f1a4bb8"; var gotItem = repo.GetItemById(id); - Assert.IsNotNull(gotItem); - Assert.AreEqual(id, gotItem["id"]); + Assert.NotNull(gotItem); + Assert.Equal(id, gotItem.Id); } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void GetItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_not_found.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_not_found.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -115,29 +115,29 @@ public void GetItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); Assert.Throws(() => repo.GetItemById(id)); } - [Test] + [Fact] public void DeleteItemSuccessful() { var id = "db3d95aa-2e35-4d87-95b4-5c9b41ba7346"; - var content = File.ReadAllText("../../Fixtures/items_delete.json"); + var content = Files.ReadAllText("./Fixtures/items_delete.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); - Assert.IsTrue(repo.DeleteItem(id)); + var repo = Get(client.Object); + Assert.True(repo.DeleteItem(id)); client.VerifyAll(); } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void DeleteItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_delete_unsuccessful.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_delete_unsuccessful.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -146,50 +146,50 @@ public void DeleteItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); Assert.Throws(() => repo.DeleteItem(id)); } - [Test] + [Fact] public void EditItemSuccessful() { //First, create a item we'll work with - var content = File.ReadAllText("../../Fixtures/items_edit.json"); + var content = Files.ReadAllText("./Fixtures/items_edit.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var id = "172500df-0f2a-4e43-8fe7-f4a36dfbd1a2"; var buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var sellerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e"; //some user created before - var item = new Dictionary + var item = new Item { - {"id" , id}, - {"name" , "Test Item #1"}, - {"amount" , 1000}, - {"payment_type" , 2}, - {"buyer_id" , buyerId}, - {"seller_id" , sellerId}, - {"fee_ids" , ""}, - {"description" , "Test item #1 description"} + Id = id, + Name = "Test Item #1", + Amount = 1000, + PaymentType= (PaymentType)2, + BuyerId = buyerId, + SellerId = sellerId, + //fee_ids = "", + Description = "Test item #1 description" }; //Now, try to edit newly created item - item["name"] = "Test123"; - item["description"] = "Test123"; + item.Name = "Test123"; + item.Description = "Test123"; var updatedItem = repo.UpdateItem(item); - Assert.AreEqual("Test123", updatedItem["name"]); - Assert.AreEqual("Test123", updatedItem["description"]); + Assert.Equal("Test123", updatedItem.Name); + Assert.Equal("Test123", updatedItem.Description); } - [Test] + [Fact] public void EditItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_edit_unsuccessful.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_edit_unsuccessful.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -198,96 +198,96 @@ public void EditItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); var buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var sellerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e"; //some user created before - var item = new Dictionary + var item = new Item { - {"id" , id}, - {"name" , "Test Item #1"}, - {"amount" , 1000}, - {"payment_type" , 2}, - {"buyer_id" , buyerId}, - {"seller_id" , sellerId}, - {"fee_ids" , ""}, - {"description" , "Test item #1 description"} + Id = id, + Name = "Test Item #1", + Amount = 1000, + PaymentType = (PaymentType)2, + BuyerId = buyerId, + SellerId = sellerId, + //fee_ids = "", + Description = "Test item #1 description" }; Assert.Throws(() => repo.UpdateItem(item)); } - [Test] + [Fact] public void ListTransactionsForItem() { - var content = File.ReadAllText("../../Fixtures/items_list_transactions.json"); + var content = Files.ReadAllText("./Fixtures/items_list_transactions.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var transactions = repo.ListTransactionsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); Assert.NotNull(transactions); } - [Test] + [Fact] public void GetStatusForItem() { - var content = File.ReadAllText("../../Fixtures/items_get_status.json"); + var content = Files.ReadAllText("./Fixtures/items_get_status.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var status = repo.GetStatusForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(status); + Assert.NotNull(status); } - [Test] + [Fact] public void ListFeesForItem() { - var content = File.ReadAllText("../../Fixtures/items_list_fees.json"); + var content = Files.ReadAllText("./Fixtures/items_list_fees.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var fees = repo.ListFeesForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(fees); + Assert.NotNull(fees); } - [Test] + [Fact] public void GetBuyerForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_buyer.json"); + var content = Files.ReadAllText("./Fixtures/items_get_buyer.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var buyer = repo.GetBuyerForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(buyer); + Assert.NotNull(buyer); } - [Test] + [Fact] public void GetSellerForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_seller.json"); + var content = Files.ReadAllText("./Fixtures/items_get_seller.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var sellers = repo.GetSellerForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(sellers); + Assert.NotNull(sellers); } - [Test] + [Fact] public void GetWireDetailsForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_wire_details.json"); + var content = Files.ReadAllText("./Fixtures/items_get_wire_details.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var wireDetails = repo.GetWireDetailsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(wireDetails); + Assert.NotNull(wireDetails); } - [Test] + [Fact] public void GetBPayDetailsForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_bpay_details.json"); + var content = Files.ReadAllText("./Fixtures/items_get_bpay_details.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var bPayDetails = repo.GetBPayDetailsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(bPayDetails); + Assert.NotNull(bPayDetails); } } diff --git a/PromisePayDotNet.Tests/DynamicPayPalAccountTest.cs b/PromisePayDotNet.Tests/DynamicPayPalAccountTest.cs index 8eea32f..6794ee1 100644 --- a/PromisePayDotNet.Tests/DynamicPayPalAccountTest.cs +++ b/PromisePayDotNet.Tests/DynamicPayPalAccountTest.cs @@ -1,100 +1,101 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System; using System.Collections.Generic; using System.IO; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class DynamicPayPalAccountTest : AbstractTest { - [Test] + [Fact] public void PayPalAccountDeserialization() { var jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-25T12:31:39.324Z\", \"updated_at\": \"2015-04-25T12:31:39.324Z\", \"id\": \"70d93fe3-6c2e-4a1c-918f-13b8e7bb3779\", \"currency\": \"USD\", \"paypal\": { \"email\": \"test.me@promisepay.com\" }, \"links\": { \"self\": \"/paypal_accounts/70d93fe3-6c2e-4a1c-918f-13b8e7bb3779\", \"users\": \"/paypal_accounts/70d93fe3-6c2e-4a1c-918f-13b8e7bb3779/users\" } }"; - var payPalAccount = JsonConvert.DeserializeObject>(jsonStr); - Assert.AreEqual("70d93fe3-6c2e-4a1c-918f-13b8e7bb3779", (string)payPalAccount["id"]); - Assert.AreEqual("USD", (string)payPalAccount["currency"]); - var paypal = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(payPalAccount["paypal"])); - Assert.AreEqual("test.me@promisepay.com", (string)paypal["email"]); + var payPalAccount = JsonConvert.DeserializeObject(jsonStr); + Assert.Equal("70d93fe3-6c2e-4a1c-918f-13b8e7bb3779", (string)payPalAccount.Id); + Assert.Equal("USD", (string)payPalAccount.Currency); + Assert.Equal("test.me@promisepay.com", (string)payPalAccount.PayPal.Email); } - [Test] + [Fact] public void CreatePayPalAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/paypal_account_create.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_create.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before - var account = new Dictionary - { { "user_id", userId }, - {"active" , true}, - {"paypal" , new Dictionary + var account = new PayPalAccount + { + //userid = userId , + //active = true, + PayPal = new PayPal { - {"email", "aaa@bbb.com"} - }} + Email = "aaa@bbb.com" + } }; var createdAccount = repo.CreatePayPalAccount(account); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount["id"]); - Assert.AreEqual("AUD", (string)createdAccount["currency"]); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount["created_at"]); - Assert.IsNotNull(createdAccount["updated_at"]); + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", (string)createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); } - [Test] + [Fact] public void GetPayPalAccountSuccessfully() { var id = "cd2ab053-25e5-491a-a5ec-0c32dbe76efa"; - var content = File.ReadAllText("../../Fixtures/paypal_account_create.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_create.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var gotAccount = repo.GetPayPalAccountById(id); - Assert.AreEqual(id, (string)gotAccount["id"]); + Assert.Equal(id, (string)gotAccount.Id); } - [Test] + [Fact] public void GetPayPalAccountEmptyId() { var client = GetMockClient(""); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.GetPayPalAccountById(string.Empty)); } - [Test] + [Fact] public void GetUserForPayPalAccountSuccessfully() { var id = "3a780d4a-5de0-409c-9587-080930ddea3c"; - var content = File.ReadAllText("../../Fixtures/paypal_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_get_users.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var gotUser = repo.GetUserForPayPalAccount(id); - Assert.IsNotNull(gotUser); + Assert.NotNull(gotUser); - Assert.AreEqual(userId, gotUser["id"]); + Assert.Equal(userId, gotUser.Id); } - [Test] + [Fact] public void DeletePayPalAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/paypal_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_delete.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var result = repo.DeletePayPalAccount("cd2ab053-25e5-491a-a5ec-0c32dbe76efa"); - Assert.IsTrue(result); + Assert.True(result); } } diff --git a/PromisePayDotNet.Tests/DynamicTokenTest.cs b/PromisePayDotNet.Tests/DynamicTokenTest.cs index 9508588..75eedfe 100644 --- a/PromisePayDotNet.Tests/DynamicTokenTest.cs +++ b/PromisePayDotNet.Tests/DynamicTokenTest.cs @@ -1,64 +1,62 @@ -using NUnit.Framework; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Dynamic.Implementations; -using RestSharp; -using System.Collections.Generic; +using Xunit; using System.IO; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class DynamicTokenTest : AbstractTest { - [Test] - [Ignore("it seems I have created a token already, so it return error")] + //[Fact] + //[Ignore("it seems I have created a token already, so it return error")] public void RequestToken() { - var repo = new TokenRepository(new RestClient()); - var token = repo.RequestToken(); + //var repo = new TokenRepository(new RestClient()); + //var token = repo.RequestToken(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void RequestSessionToken() { - var repo = new TokenRepository(new RestClient()); - var result = repo.RequestSessionToken(new Dictionary - { - {"current_user_id" , "ec9bf096-c505-4bef-87f6-18822b9dbf2c"}, - {"amount" , "$100.00"}, - {"external_item_id" , "b3b4d024-a6de-4b04-9f8d-6545eef3b28f"}, - {"external_buyer_id" , "fdf58725-96bd-4bf8-b5e6-9b61be20662e"}, - {"external_seller_id" , "ec9bf096-c505-4bef-87f6-18822b9dbf2c"}, - {"buyer_email" , "aaa@bbb.com"}, - {"seller_email" , "ccc@ddd.com"}, - {"buyer_country" , "AUS"}, - {"seller_country" , "AUS"}, - {"buyer_first_name" , "Preved"}, - {"seller_first_name" , "Medved"}, - {"item_name" , "Bear"} - }); + //var repo = new TokenRepository(new RestClient()); + //var result = repo.RequestSessionToken(new Dictionary + //{ + // {"current_user_id" , "ec9bf096-c505-4bef-87f6-18822b9dbf2c"}, + // {"amount" , "$100.00"}, + // {"external_item_id" , "b3b4d024-a6de-4b04-9f8d-6545eef3b28f"}, + // {"external_buyer_id" , "fdf58725-96bd-4bf8-b5e6-9b61be20662e"}, + // {"external_seller_id" , "ec9bf096-c505-4bef-87f6-18822b9dbf2c"}, + // {"buyer_email" , "aaa@bbb.com"}, + // {"seller_email" , "ccc@ddd.com"}, + // {"buyer_country" , "AUS"}, + // {"seller_country" , "AUS"}, + // {"buyer_first_name" , "Preved"}, + // {"seller_first_name" , "Medved"}, + // {"item_name" , "Bear"} + //}); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void Widget() { - var repo = new TokenRepository(new RestClient()); - var widget = repo.GetWidget("aaa-bbb-cc"); + //var repo = new TokenRepository(new RestClient()); + //var widget = repo.GetWidget("aaa-bbb-cc"); + throw new System.Exception(); } - [Test] + [Fact] public void GenerateCardToken() { - var content = File.ReadAllText("../../Fixtures/generate_card_token.json"); + var content = Files.ReadAllText("./Fixtures/generate_card_token.json"); var client = GetMockClient(content); - var repo = new TokenRepository(client.Object); + var repo = Get(client.Object); var result = repo.GenerateCardToken("card", "064d6800-fff3-11e5-86aa-5e5517507c66"); - Assert.AreEqual("card", result["token_type"]); - Assert.AreEqual("6e37598a3b33582b1dfcf13d5e2e45e3", result["token"]); - Assert.AreEqual("064d6800-fff3-11e5-86aa-5e5517507c66", result["user_id"]); + Assert.Equal("card", result.TokenType); + Assert.Equal("6e37598a3b33582b1dfcf13d5e2e45e3", result.Token); + Assert.Equal("064d6800-fff3-11e5-86aa-5e5517507c66", result.UserId); } } } diff --git a/PromisePayDotNet.Tests/DynamicTransactionTest.cs b/PromisePayDotNet.Tests/DynamicTransactionTest.cs index a0f3323..0ba6cdc 100644 --- a/PromisePayDotNet.Tests/DynamicTransactionTest.cs +++ b/PromisePayDotNet.Tests/DynamicTransactionTest.cs @@ -1,49 +1,49 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using System; using System.Collections.Generic; using System.IO; -using System.Linq; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class DynamicTransactionTest : AbstractTest { - [Test] + [Fact] public void TransactionDeserialization() { var jsonStr = "{\"id\": \"8d8237c2-8598-4100-9fa5-f4ced75e7d76\",\"created_at\": \"2014-12-29T09:40:47.046Z\",\"updated_at\": \"2014-12-29T09:40:47.489Z\",\"description\": \"Buyer Fee @ 10%\",\"amount\": 5000,\"currency\":\"USD\",\"type\":\"debit\",\"from\": \"Escrow Vault\",\"to\": \"Awesome Websites\",\"related\": {\"transactions\":\"6a5525cf-e82f-40e7-995a-ad747185052a\"},\"links\":{\"self\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76\",\"users\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76/users\",\"fees\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76/fees\"}}"; - var transaction = JsonConvert.DeserializeObject>(jsonStr); - Assert.AreEqual("8d8237c2-8598-4100-9fa5-f4ced75e7d76", (string)transaction["id"]); + var transaction = JsonConvert.DeserializeObject(jsonStr); + Assert.Equal("8d8237c2-8598-4100-9fa5-f4ced75e7d76", (string)transaction.Id); } - [Test] + [Fact] public void ListTransactionsSuccessful() { //First, create a user, so we'll have at least one - var content = File.ReadAllText("../../Fixtures/transactions_list.json"); + var content = Files.ReadAllText("./Fixtures/transactions_list.json"); var client = GetMockClient(content); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); //Then, list users var transactions = repo.ListTransactions(200); - Assert.IsNotNull(transactions); + Assert.NotNull(transactions); } - [Test] + [Fact] public void ListTransactionsNegativeParams() { var client = GetMockClient(""); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListTransactions(-10, -20)); } - [Test] + [Fact] public void ListTransactionsTooHighLimit() { var client = GetMockClient(""); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListTransactions(201)); } diff --git a/PromisePayDotNet.Tests/DynamicUploadTest.cs b/PromisePayDotNet.Tests/DynamicUploadTest.cs index bb39df2..4327f30 100644 --- a/PromisePayDotNet.Tests/DynamicUploadTest.cs +++ b/PromisePayDotNet.Tests/DynamicUploadTest.cs @@ -1,56 +1,56 @@ using Newtonsoft.Json; -using NUnit.Framework; -using RestSharp; +using Xunit; +using PromisePayDotNet.Internals; using System.Collections.Generic; namespace PromisePayDotNet.Tests { public class DynamicUploadTest : AbstractTest { - [Test] + [Fact] public void UploadDeserialization() { const string jsonStr = "{ \"id\": \"a2711d90-ed41-4d12-81d2-000000000002\", \"processed_lines\": 6, \"total_lines\": 6, \"update_lines\": 0, \"error_lines\": 6, \"progress\": 100.0 }"; var upload = JsonConvert.DeserializeObject>(jsonStr); - Assert.IsNotNull(upload); - Assert.AreEqual("a2711d90-ed41-4d12-81d2-000000000002", (string)upload["id"]); + Assert.NotNull(upload); + Assert.Equal("a2711d90-ed41-4d12-81d2-000000000002", (string)upload["id"]); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void CreateUploadSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void ListUploadsSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void GetUploadByIdSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void GetStatusSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void StartImportSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } } } diff --git a/PromisePayDotNet.Tests/DynamicUserTest.cs b/PromisePayDotNet.Tests/DynamicUserTest.cs index d8fb84b..741d362 100644 --- a/PromisePayDotNet.Tests/DynamicUserTest.cs +++ b/PromisePayDotNet.Tests/DynamicUserTest.cs @@ -1,11 +1,12 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.Dynamic.Implementations; +using Xunit; using PromisePayDotNet.Exceptions; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { @@ -14,373 +15,385 @@ public class DynamicUserTest : AbstractTest public string GetUserByIdResponse = "{\"created_at\":\"2015-05-18T06:50:51.684Z\",\"updated_at\":\"2015-05-18T11:36:14.050Z\",\"full_name\":\"Igor Sidorov\",\"email\":\"idsidorov@gmail.com\",\"mobile\":null,\"phone\":null,\"first_name\":\"Igor\",\"last_name\":\"Sidorov\",\"id\":\"ef831cd65790e232f6e8c316d6a2ce50\",\"verification_state\":\"pending\",\"held_state\":false,\"dob\":\"Not provided.\",\"government_number\":\"Not provided.\",\"drivers_license\":\"Not provided.\",\"related\":{\"addresses\":\"f08a5f8a-698f-41cf-ac2e-7d5cc52eb915\",\"companies\":\"e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\"},\"links\":{\"self\":\"/users/ef831cd65790e232f6e8c316d6a2ce50\",\"items\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/items\",\"card_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/card_accounts\",\"paypal_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/paypal_accounts\",\"bank_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/bank_accounts\"}}"; - [Test] + [Fact] public void TestUserDaoObject() { - var user = JsonConvert.DeserializeObject>(GetUserByIdResponse); - Assert.AreEqual("Igor Sidorov", (string)user["full_name"]); - Assert.IsTrue(((DateTime?)user["created_at"]).HasValue); - Assert.IsTrue(((DateTime?)user["updated_at"]).HasValue); + var user = JsonConvert.DeserializeObject>(GetUserByIdResponse); + Assert.Equal("Igor Sidorov", (string)user["full_name"]); + Assert.True(((DateTime?)user["created_at"]).HasValue); + Assert.True(((DateTime?)user["updated_at"]).HasValue); } - [Test] + [Fact] public void UserCreateSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary + var user = new User { - {"id" , id}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"} + Id = id, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" }; var createdUser = repo.CreateUser(user); - Assert.AreEqual(user["id"], createdUser["id"]); - Assert.AreEqual(user["first_name"], createdUser["first_name"]); - Assert.AreEqual(user["last_name"], createdUser["last_name"]); - Assert.AreEqual("Test Test", createdUser["full_name"]); - Assert.AreEqual(user["email"], createdUser["email"]); - Assert.IsTrue(((DateTime?)createdUser["created_at"]).HasValue); - Assert.IsTrue(((DateTime?)createdUser["updated_at"]).HasValue); + Assert.Equal(user.Id, createdUser.Id); + Assert.Equal(user.FirstName, createdUser.FirstName); + Assert.Equal(user.LastName, createdUser.LastName); + Assert.Equal("Test Test", createdUser.FullName); + Assert.Equal(user.Email, createdUser.Email); + Assert.True(createdUser.CreatedAt.HasValue); + Assert.True(createdUser.UpdatedAt.HasValue); } - [Test] + [Fact] public void ValidationErrorUserCreateMissedId() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary - {{"id" , null}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"}}; + var user = new User + { + Id = null, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" + }; Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ValidationErrorUserCreateMissedFirstName() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary - {{"id" , id}, - {"first_name" , null}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"}}; - Assert.Throws(() => repo.CreateUser(user)); + var user = new User + { + Id = id, + FirstName = null, + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" + }; + Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ValidationErrorUserCreateWrongCountry() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary - {{"id" , null}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "Australia"}, //Incorrect name - not an ISO code - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"}}; + var user = new User + { + Id = null, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "Australia", //Incorrect name - not an ISO code + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" + }; Assert.Throws(() => repo.CreateUser(user)); } - - [Test] + + [Fact] public void ValidationErrorUserCreateWrongEmail() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary - {{"id" , null}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id }}; + var user = new User + { + Id = null, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + }; Assert.Throws(() => repo.CreateUser(user)); } - - [Test] + + [Fact] public void ListUsersSuccessful() { var id = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //Then, list users - var content = File.ReadAllText("../../Fixtures/users_list.json"); + var content = Files.ReadAllText("./Fixtures/users_list.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var users = repo.ListUsers(200); - Assert.IsNotNull(users); - Assert.IsTrue(users.Any()); - Assert.IsTrue(users.Any(x => (string)x["id"] == id)); + Assert.NotNull(users); + Assert.True(users.Any()); + Assert.True(users.Any(x => (string)x.Id == id)); } - - [Test] + + [Fact] public void ListUsersNegativeParams() { - var content = File.ReadAllText("../../Fixtures/users_list.json"); + var content = Files.ReadAllText("./Fixtures/users_list.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListUsers(-10, -20)); } - [Test] + [Fact] public void ListUsersTooHighLimit() { - var content = File.ReadAllText("../../Fixtures/users_list.json"); + var content = Files.ReadAllText("./Fixtures/users_list.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListUsers(201)); } - - [Test] + + [Fact] public void GetUserSuccessful() { //First, create a user with known id - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; //Then, get user var gotUser = repo.GetUserById(id); - Assert.IsNotNull(gotUser); - Assert.AreEqual(id, (string)gotUser["id"], id); + Assert.NotNull(gotUser); + Assert.Equal(id, (string)gotUser.Id); } - - [Test] + + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void GetUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "asdfkjas;lkflaksndflaksndfklas"; Assert.Throws(() => repo.GetUserById(id)); } - - [Test] - [Ignore("Skipped until API method will be fixed")] + + //[Fact] + //[Ignore("Skipped until API method will be fixed")] public void DeleteUserSuccessful() { - Assert.Fail(); + //throw new System.Exception(); } - - [Test] + + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void DeleteUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, System.Net.HttpStatusCode.NotFound); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); - Assert.IsFalse(repo.DeleteUser(id)); + Assert.False(repo.DeleteUser(id)); } - - [Test] + + [Fact] public void EditUserSuccessful() { //First, create a user we'll work with - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; - var user = new Dictionary - {{"id" , id}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"}}; + var user = new User + { + Id = id, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" + }; var createdUser = repo.CreateUser(user); //Now, try to edit newly created user - user["first_name"] = "Test123"; - user["last_name"] = "Test123"; + user.FirstName = "Test123"; + user.LastName = "Test123"; - content = File.ReadAllText("../../Fixtures/user_update.json"); + content = Files.ReadAllText("./Fixtures/user_update.json"); client = GetMockClient(content); - repo = new UserRepository(client.Object); + repo = Get(client.Object); var modifiedUser = repo.UpdateUser(user); - Assert.AreEqual("Test123", modifiedUser["first_name"]); - Assert.AreEqual("Test123", modifiedUser["last_name"]); - Assert.AreEqual("Test123 Test123", modifiedUser["full_name"]); + Assert.Equal("Test123", modifiedUser.FirstName); + Assert.Equal("Test123", modifiedUser.LastName); + Assert.Equal("Test123 Test123", modifiedUser.FullName); } - [Test] + [Fact] public void EditUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); - var user = new Dictionary - {{"id" , id}, - {"first_name" , "Test"}, - {"last_name" , "Test"}, - {"city" , "Test"}, - {"address_line1" , "Line 1"}, - {"address_line2" , "Line 2"}, - {"country" , "AUS"}, - {"mobile" , "123123"}, - {"state" , "state"}, - {"zip" , "123456"}, - {"email" , id + "@google.com"}}; + var user = new User + { + Id = id, + FirstName = "Test", + LastName = "Test", + City = "Test", + AddressLine1 = "Line 1", + AddressLine2 = "Line 2", + Country = "AUS", + Mobile = "123123", + State = "state", + Zip = "123456", + Email = id + "@google.com" + }; Assert.Throws(() => repo.UpdateUser(user)); } - [Test] - [Ignore("Currently, this test returns 401")] + //[Fact] + //[Ignore("Currently, this test returns 401")] public void SendMobilePinSuccessful() { - Assert.Fail(); + throw new System.Exception(); } - - [Test] + + [Fact] public void ListUserItemsSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_items.json"); + var content = Files.ReadAllText("./Fixtures/user_items.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.ListItemsForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void ListUserDisbursementAccountsSuccessful() { - Assert.Fail(); + throw new System.Exception(); } - [Test] + [Fact] public void ListUserBankAccountsSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_bank_accounts.json"); + var content = Files.ReadAllText("./Fixtures/user_bank_accounts.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetBankAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); - Assert.AreEqual("c5d37185-4472-44c1-87e2-8a5a3abb96fc", items["id"]); + Assert.Equal("c5d37185-4472-44c1-87e2-8a5a3abb96fc", items.Id); } - [Test] + [Fact] public void GetUserCardAccountSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_card_accounts.json"); + var content = Files.ReadAllText("./Fixtures/user_card_accounts.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetCardAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); - Assert.AreEqual("81e44baa-b5df-4bcd-a6a7-39e5ecd91a74", items["id"]); + Assert.Equal("81e44baa-b5df-4bcd-a6a7-39e5ecd91a74", items.Id); } - [Test] + [Fact] public void GetUserPayPalAccountSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_paypal_accounts.json"); + var content = Files.ReadAllText("./Fixtures/user_paypal_accounts.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetPayPalAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); - Assert.AreEqual("fdc5e5e4-b5d2-456b-8d42-ff349ccf8346", items["id"]); + Assert.Equal("fdc5e5e4-b5d2-456b-8d42-ff349ccf8346", items.Id); } - [Test] + [Fact] public void GetUserBankAccountEmpty() { - var content = File.ReadAllText("../../Fixtures/user_bank_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_bank_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetBankAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void GetUserCardAccountEmpty() { - var content = File.ReadAllText("../../Fixtures/user_card_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_card_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetCardAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void GetUserPayPalAccountEmpty() { - var content = File.ReadAllText("../../Fixtures/user_paypal_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_paypal_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.GetPayPalAccountForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - - [Test] - [Ignore("Not implemented yet")] + + //[Fact] + //[Ignore("Not implemented yet")] public void ListUserDisbursementAccountsEmpty() { - Assert.Fail(); + //throw new System.Exception(); } } } diff --git a/PromisePayDotNet.Tests/FeeTest.cs b/PromisePayDotNet.Tests/FeeTest.cs index 92bb50d..1084874 100644 --- a/PromisePayDotNet.Tests/FeeTest.cs +++ b/PromisePayDotNet.Tests/FeeTest.cs @@ -1,34 +1,35 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Enums; using PromisePayDotNet.Exceptions; using PromisePayDotNet.Implementations; using System; using System.IO; using System.Linq; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class FeeTest : AbstractTest { - [Test] + [Fact] public void FeeDeserialization() { const string jsonStr = "{ \"id\": \"58e15f18-500e-4cdc-90ca-65e1f1dce565\", \"created_at\": \"2014-12-29T08:31:42.168Z\", \"updated_at\": \"2014-12-29T08:31:42.168Z\", \"name\": \"Buyer Fee @ 10%\", \"fee_type_id\": 2, \"amount\": 1000, \"cap\": null, \"min\": null, \"max\": null, \"to\": \"buyer\", \"links\": { \"self\": \"/fees/58e15f18-500e-4cdc-90ca-65e1f1dce565\" } }"; var fee = JsonConvert.DeserializeObject(jsonStr); - Assert.IsNotNull(fee); - Assert.AreEqual("58e15f18-500e-4cdc-90ca-65e1f1dce565", fee.Id); - Assert.AreEqual("Buyer Fee @ 10%", fee.Name); + Assert.NotNull(fee); + Assert.Equal("58e15f18-500e-4cdc-90ca-65e1f1dce565", fee.Id); + Assert.Equal("Buyer Fee @ 10%", fee.Name); } - [Test] + [Fact] public void CreateFeeSuccessfully() { - var content = File.ReadAllText("../../Fixtures/fees_create.json"); + var content = Files.ReadAllText("./Fixtures/fees_create.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var feeId = Guid.NewGuid().ToString(); var createdFee = repo.CreateFee(new Fee { @@ -39,17 +40,17 @@ public void CreateFeeSuccessfully() Cap = "1", Max = "3", Min = "2", - To = "buyer" + To = FeeToType.Buyer }); - Assert.IsNotNull(createdFee); + Assert.NotNull(createdFee); } - [Test] + [Fact] public void CreateFeeWrongTo() { var client = GetMockClient(""); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var feeId = Guid.NewGuid().ToString(); Assert.Throws(() => repo.CreateFee(new Fee { @@ -63,28 +64,28 @@ public void CreateFeeWrongTo() })); } - [Test] + [Fact] public void GetFeeByIdSuccessfull() { - var content = File.ReadAllText("../../Fixtures/fees_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/fees_get_by_id.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); const string id = "79116c9f-d750-4faa-85c7-b7da36f23b38"; var fee = repo.GetFeeById(id); - Assert.AreEqual(id, fee.Id); + Assert.Equal(id, fee.Id); } - [Test] + [Fact] public void ListFeeSuccessfully() { - var content = File.ReadAllText("../../Fixtures/fees_list.json"); + var content = Files.ReadAllText("./Fixtures/fees_list.json"); var client = GetMockClient(content); - var repo = new FeeRepository(client.Object); + var repo = Get(client.Object); var fees = repo.ListFees(); - Assert.IsNotNull(fees); - Assert.IsTrue(fees.Any()); + Assert.NotNull(fees); + Assert.True(fees.Any()); } } } diff --git a/PromisePayDotNet.Tests/FileHelper.cs b/PromisePayDotNet.Tests/FileHelper.cs new file mode 100644 index 0000000..abd2c3d --- /dev/null +++ b/PromisePayDotNet.Tests/FileHelper.cs @@ -0,0 +1,14 @@ +using System.IO; +using System.Reflection; + +namespace PromisePayDotNet.Tests +{ + class Files + { + private static string loc = Path.GetDirectoryName( typeof(Files).GetTypeInfo().Assembly.Location); + public static string ReadAllText(string path) + { + return File.ReadAllText(Path.Combine(loc, path)); + } + } +} diff --git a/PromisePayDotNet.Tests/Fixtures/fees_create.json b/PromisePayDotNet.Tests/Fixtures/fees_create.json index a9223d5..f9b0d54 100644 --- a/PromisePayDotNet.Tests/Fixtures/fees_create.json +++ b/PromisePayDotNet.Tests/Fixtures/fees_create.json @@ -1 +1,15 @@ -{"fees":{"id":"dcbe3dde-b01b-4a54-8177-fd3ebe9123f6","created_at":"2015-08-08T19:08:15.095Z","updated_at":"2015-08-08T19:08:15.095Z","name":"Test fee #1","fee_type_id":1,"amount":1000,"cap":1,"min":2,"max":3,"to":"buyer","links":{"self":"/fees/dcbe3dde-b01b-4a54-8177-fd3ebe9123f6"}}} \ No newline at end of file +{ + "fees": { + "id": "dcbe3dde-b01b-4a54-8177-fd3ebe9123f6", + "created_at": "2015-08-08T19:08:15.095Z", + "updated_at": "2015-08-08T19:08:15.095Z", + "name": "Test fee #1", + "fee_type_id": 1, + "amount": 1000, + "cap": 1, + "min": 2, + "max": 3, + "to": "buyer", + "links": { "self": "/fees/dcbe3dde-b01b-4a54-8177-fd3ebe9123f6" } + } +} \ No newline at end of file diff --git a/PromisePayDotNet.Tests/Fixtures/items_get_wire_details.json b/PromisePayDotNet.Tests/Fixtures/items_get_wire_details.json index 24ebce9..3a567f8 100644 --- a/PromisePayDotNet.Tests/Fixtures/items_get_wire_details.json +++ b/PromisePayDotNet.Tests/Fixtures/items_get_wire_details.json @@ -1 +1,20 @@ -{"items":{"id":"7c269f52-2236-4aa5-899e-a2e3ecadbc3f","wire_details":{"beneficiary":"PromisePay","address_line1":"500 Bourke Street","city":"Melbourne","state":"VIC","zip":"3000","BSB":"083001","account_number":"844144573","bank_name":"National Australia Bank","swift":"NATAAU3303M","reference":"9140139367","amount":"$10.00","currency":"AUD"}}} \ No newline at end of file +{ + "items": { + "id": "7c269f52-2236-4aa5-899e-a2e3ecadbc3f", + "wire_details": { + "beneficiary": "PromisePay", + "address_line1": "500 Bourke Street", + "city": "Melbourne", + "state": "VIC", + "zip": "3000", + "BSB": "083001", + "account_number": "844144573", + "bank_name": "National Australia Bank", + "swift": "NATAAU3303M", + "reference": "9140139367", + "amount": "$10.00", + "currency": "AUD", + "country": "Australia" + } + } +} \ No newline at end of file diff --git a/PromisePayDotNet.Tests/ItemActionsTest.cs b/PromisePayDotNet.Tests/ItemActionsTest.cs index 643e86a..e48e1b4 100644 --- a/PromisePayDotNet.Tests/ItemActionsTest.cs +++ b/PromisePayDotNet.Tests/ItemActionsTest.cs @@ -1,78 +1,73 @@ -using NUnit.Framework; +using Xunit; namespace PromisePayDotNet.Tests { public class ItemActionsTest { - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void MakePaymentSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void RequestPaymentSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void ReleasePaymentSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void RequestReleaseSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void CancelSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void AcknowledgeWireSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void AcknowledgePayPalSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void RevertWireSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void RequestRefundSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void RefundSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } } } diff --git a/PromisePayDotNet.Tests/ItemTest.cs b/PromisePayDotNet.Tests/ItemTest.cs index 6fb2f98..67328ec 100644 --- a/PromisePayDotNet.Tests/ItemTest.cs +++ b/PromisePayDotNet.Tests/ItemTest.cs @@ -2,35 +2,35 @@ using System.Net; using Moq; using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Enums; using PromisePayDotNet.Exceptions; using PromisePayDotNet.Implementations; using System; using System.Linq; -using RestSharp; -using RestSharp.Authenticators; +using PromisePayDotNet.Internals; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class ItemTest : AbstractTest { - [Test] + [Fact] public void ItemDeserialization() { var jsonStr = " { \"id\": \"293\", \"name\": \"Testing\", \"description\": \"This is the description\", \"created_at\": \"2015-05-01T04:42:25.595Z\", \"updated_at\": \"2015-05-01T04:42:25.595Z\", \"state\": \"pending\", \"deposit_reference\": \"9140122157\", \"payment_type_id\": 1, \"status\": 22000,\"amount\": 6000, \"buyer_name\": \"Joe Frio\", \"buyer_country\": \"USA\", \"buyer_email\": \"joe.test@promisepay.com\",\"seller_name\": \"Julie Boatsman\", \"seller_country\": \"USA\", \"seller_email\": \"julie.test@promisepay.com\", \"currency\": \"USD\",\"links\": { \"self\": \"/items/293\", \"buyers\": \"/items/293/buyers\", \"sellers\": \"/items/293/sellers\", \"status\": \"/items/293/status\", \"fees\": \"/items/293/fees\", \"transactions\": \"/items/293/transactions\" } }"; var item = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("293", item.Id); + Assert.Equal("293", item.Id); } - [Test] + [Fact] public void CreateItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_create.json"); + var content = Files.ReadAllText("./Fixtures/items_create.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); const string id = "5e81906c-e14b-42a8-952f-4a0d1f1a4bb8"; const string buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before const string sellerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e"; //some user created before @@ -46,68 +46,68 @@ public void CreateItemSuccessfully() Description = "Test item #1 description" }; var createdItem = repo.CreateItem(item); - Assert.AreEqual(item.Id, createdItem.Id); - Assert.AreEqual(item.Name, createdItem.Name); - Assert.AreEqual(item.Amount, createdItem.Amount); - Assert.AreEqual(item.PaymentType, createdItem.PaymentType); - Assert.AreEqual(item.Description, createdItem.Description); + Assert.Equal(item.Id, createdItem.Id); + Assert.Equal(item.Name, createdItem.Name); + Assert.Equal(item.Amount, createdItem.Amount); + Assert.Equal(item.PaymentType, createdItem.PaymentType); + Assert.Equal(item.Description, createdItem.Description); } - [Test] + [Fact] public void ListAllItemsSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_list.json"); + var content = Files.ReadAllText("./Fixtures/items_list.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items var items = repo.ListItems(200); - Assert.IsNotNull(items); - Assert.IsTrue(items.Any()); + Assert.NotNull(items); + Assert.True(items.Any()); } - [Test] + [Fact] public void ListAllItemsNegativeParams() { var client = GetMockClient(""); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items Assert.Throws(() => repo.ListItems(-10, -10)); } - [Test] + [Fact] public void ListAllItemsTooHighLimit() { var client = GetMockClient(""); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); //Then, list items Assert.Throws(() => repo.ListItems(500)); } - [Test] + [Fact] public void GetItemSuccessful() { //First, create a user with known id - var content = File.ReadAllText("../../Fixtures/items_get_by_id.json"); + var content = Files.ReadAllText("./Fixtures/items_get_by_id.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); const string id = "5e81906c-e14b-42a8-952f-4a0d1f1a4bb8"; var gotItem = repo.GetItemById(id); - Assert.IsNotNull(gotItem); - Assert.AreEqual(id, gotItem.Id); + Assert.NotNull(gotItem); + Assert.Equal(id, gotItem.Id); } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void GetItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_not_found.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_not_found.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -116,29 +116,29 @@ public void GetItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); Assert.Throws(() => repo.GetItemById(id)); } - [Test] + [Fact] public void DeleteItemSuccessful() { var id = "db3d95aa-2e35-4d87-95b4-5c9b41ba7346"; - var content = File.ReadAllText("../../Fixtures/items_delete.json"); + var content = Files.ReadAllText("./Fixtures/items_delete.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); - Assert.IsTrue(repo.DeleteItem(id)); + var repo = Get(client.Object); + Assert.True(repo.DeleteItem(id)); client.VerifyAll(); } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void DeleteItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_delete_unsuccessful.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_delete_unsuccessful.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -147,19 +147,19 @@ public void DeleteItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); Assert.Throws(() => repo.DeleteItem(id)); } - [Test] + [Fact] public void EditItemSuccessful() { //First, create a item we'll work with - var content = File.ReadAllText("../../Fixtures/items_edit.json"); + var content = Files.ReadAllText("./Fixtures/items_edit.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var id = "172500df-0f2a-4e43-8fe7-f4a36dfbd1a2"; var buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before @@ -181,15 +181,15 @@ public void EditItemSuccessful() item.Description = "Test123"; var updatedItem = repo.UpdateItem(item); - Assert.AreEqual("Test123", updatedItem.Name); - Assert.AreEqual("Test123", updatedItem.Description); + Assert.Equal("Test123", updatedItem.Name); + Assert.Equal("Test123", updatedItem.Description); } - [Test] + [Fact] public void EditItemMissingId() { - var content = File.ReadAllText("../../Fixtures/items_edit_unsuccessful.json"); - var response = new Mock(MockBehavior.Strict); + var content = Files.ReadAllText("./Fixtures/items_edit_unsuccessful.json"); + var response = new Mock(MockBehavior.Strict); response.SetupGet(x => x.Content).Returns(content); response.SetupGet(x => x.ResponseUri).Returns(new Uri("http://google.com")); response.SetupGet(x => x.StatusDescription).Returns("Unauthorized"); @@ -198,8 +198,8 @@ public void EditItemMissingId() var client = new Mock(MockBehavior.Strict); client.SetupSet(x => x.BaseUrl = It.IsAny()); client.SetupSet(x => x.Authenticator = It.IsAny()); - client.Setup(x => x.Execute(It.IsAny())).Returns(response.Object); - var repo = new ItemRepository(client.Object); + client.Setup(x => x.ExecuteAsync(It.IsAny())).ReturnsAsync(response.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); var buyerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var sellerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e"; //some user created before @@ -218,76 +218,78 @@ public void EditItemMissingId() Assert.Throws(() => repo.UpdateItem(item)); } - [Test] + [Fact] public void ListTransactionsForItem() { - var content = File.ReadAllText("../../Fixtures/items_list_transactions.json"); + var content = Files.ReadAllText("./Fixtures/items_list_transactions.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var transactions = repo.ListTransactionsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); Assert.NotNull(transactions); } - [Test] + [Fact] public void GetStatusForItem() { - var content = File.ReadAllText("../../Fixtures/items_get_status.json"); + var content = Files.ReadAllText("./Fixtures/items_get_status.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var status = repo.GetStatusForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(status); + Assert.NotNull(status); } - [Test] + [Fact] public void ListFeesForItem() { - var content = File.ReadAllText("../../Fixtures/items_list_fees.json"); + var content = Files.ReadAllText("./Fixtures/items_list_fees.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var fees = repo.ListFeesForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(fees); + Assert.NotNull(fees); } - [Test] + [Fact] public void GetBuyerForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_buyer.json"); + var content = Files.ReadAllText("./Fixtures/items_get_buyer.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var buyer = repo.GetBuyerForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(buyer); + Assert.NotNull(buyer); } - [Test] + [Fact] public void GetSellerForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_seller.json"); + var content = Files.ReadAllText("./Fixtures/items_get_seller.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var sellers = repo.GetSellerForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(sellers); + Assert.NotNull(sellers); } - [Test] + [Fact] public void GetWireDetailsForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_wire_details.json"); + var content = Files.ReadAllText("./Fixtures/items_get_wire_details.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var wireDetails = repo.GetWireDetailsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(wireDetails); - } + Assert.NotNull(wireDetails); + Assert.Equal("Australia", wireDetails.Country); + Assert.Equal("National Australia Bank", wireDetails.BankName); + } - [Test] + [Fact] public void GetBPayDetailsForItemSuccessfully() { - var content = File.ReadAllText("../../Fixtures/items_get_bpay_details.json"); + var content = Files.ReadAllText("./Fixtures/items_get_bpay_details.json"); var client = GetMockClient(content); - var repo = new ItemRepository(client.Object); + var repo = Get(client.Object); var bPayDetails = repo.GetBPayDetailsForItem("7c269f52-2236-4aa5-899e-a2e3ecadbc3f"); - Assert.IsNotNull(bPayDetails); + Assert.NotNull(bPayDetails); } } } diff --git a/PromisePayDotNet.Tests/PayPalAccountTest.cs b/PromisePayDotNet.Tests/PayPalAccountTest.cs index 281c7dd..faf7333 100644 --- a/PromisePayDotNet.Tests/PayPalAccountTest.cs +++ b/PromisePayDotNet.Tests/PayPalAccountTest.cs @@ -1,31 +1,32 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; -using RestSharp; +using PromisePayDotNet.Internals; using System; using System.IO; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class PayPalAccountTest : AbstractTest { - [Test] + [Fact] public void PayPalAccountDeserialization() { var jsonStr = "{ \"active\": true, \"created_at\": \"2015-04-25T12:31:39.324Z\", \"updated_at\": \"2015-04-25T12:31:39.324Z\", \"id\": \"70d93fe3-6c2e-4a1c-918f-13b8e7bb3779\", \"currency\": \"USD\", \"paypal\": { \"email\": \"test.me@promisepay.com\" }, \"links\": { \"self\": \"/paypal_accounts/70d93fe3-6c2e-4a1c-918f-13b8e7bb3779\", \"users\": \"/paypal_accounts/70d93fe3-6c2e-4a1c-918f-13b8e7bb3779/users\" } }"; var payPalAccount = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("70d93fe3-6c2e-4a1c-918f-13b8e7bb3779", payPalAccount.Id); - Assert.AreEqual("USD", payPalAccount.Currency); - Assert.AreEqual("test.me@promisepay.com", payPalAccount.PayPal.Email); + Assert.Equal("70d93fe3-6c2e-4a1c-918f-13b8e7bb3779", payPalAccount.Id); + Assert.Equal("USD", payPalAccount.Currency); + Assert.Equal("test.me@promisepay.com", payPalAccount.PayPal.Email); } - [Test] + [Fact] public void CreatePayPalAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/paypal_account_create.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_create.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var account = new PayPalAccount @@ -38,64 +39,64 @@ public void CreatePayPalAccountSuccessfully() } }; var createdAccount = repo.CreatePayPalAccount(account); - Assert.IsNotNull(createdAccount); - Assert.IsNotNull(createdAccount.Id); - Assert.AreEqual("AUD", createdAccount.Currency); // It seems that currency is determined by country - Assert.IsNotNull(createdAccount.CreatedAt); - Assert.IsNotNull(createdAccount.UpdatedAt); + Assert.NotNull(createdAccount); + Assert.NotNull(createdAccount.Id); + Assert.Equal("AUD", createdAccount.Currency); // It seems that currency is determined by country + Assert.NotNull(createdAccount.CreatedAt); + Assert.NotNull(createdAccount.UpdatedAt); } - [Test] + [Fact] public void GetPayPalAccountSuccessfully() { var id = "cd2ab053-25e5-491a-a5ec-0c32dbe76efa"; - var content = File.ReadAllText("../../Fixtures/paypal_account_create.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_create.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var gotAccount = repo.GetPayPalAccountById(id); - Assert.AreEqual(id, gotAccount.Id); + Assert.Equal(id, gotAccount.Id); } - [Test] + [Fact] public void GetPayPalAccountEmptyId() { var client = GetMockClient(""); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(()=>repo.GetPayPalAccountById(string.Empty)); } - [Test] + [Fact] public void GetUserForPayPalAccountSuccessfully() { var id = "3a780d4a-5de0-409c-9587-080930ddea3c"; - var content = File.ReadAllText("../../Fixtures/paypal_account_get_users.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_get_users.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var userId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; //some user created before var gotUser = repo.GetUserForPayPalAccount(id); - Assert.IsNotNull(gotUser); + Assert.NotNull(gotUser); - Assert.AreEqual(userId, gotUser.Id); + Assert.Equal(userId, gotUser.Id); } - [Test] + [Fact] public void DeletePayPalAccountSuccessfully() { - var content = File.ReadAllText("../../Fixtures/paypal_account_delete.json"); + var content = Files.ReadAllText("./Fixtures/paypal_account_delete.json"); var client = GetMockClient(content); - var repo = new PayPalAccountRepository(client.Object); + var repo = Get(client.Object); var result = repo.DeletePayPalAccount("cd2ab053-25e5-491a-a5ec-0c32dbe76efa"); - Assert.IsTrue(result); + Assert.True(result); } } diff --git a/PromisePayDotNet.Tests/PromisePayDotNet.Tests.csproj b/PromisePayDotNet.Tests/PromisePayDotNet.Tests.csproj index e734365..76e116f 100644 --- a/PromisePayDotNet.Tests/PromisePayDotNet.Tests.csproj +++ b/PromisePayDotNet.Tests/PromisePayDotNet.Tests.csproj @@ -1,215 +1,186 @@ - - - - Debug - AnyCPU - {A65DAC92-617C-4956-96B8-6225D31D2D56} - Library - Properties - PromisePayDotNet.Tests - PromisePayDotNet.Tests - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + + + + netcoreapp1.1 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll - - - - ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll - - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll - False - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll - False - - - False - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - False - - - ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - False - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - + + + + + + + - - {D7EC61A8-A481-49DA-85AE-280B0A3D08B0} - PromisePayDotNet - + + - + + - + + Fixtures\%(Filename)%(Extension) + PreserveNewest + + - + + Fixtures\address_get_by_id.json + + + Fixtures\bank_account_create.json + + + Fixtures\bank_account_delete.json + + + Fixtures\bank_account_get_by_id.json + + + Fixtures\bank_account_get_users.json + + + Fixtures\card_account_create.json + + + Fixtures\card_account_delete.json + + + Fixtures\card_account_get_by_id.json + + + Fixtures\card_account_get_users.json + + + Fixtures\companies_create.json + + + Fixtures\companies_edit.json + + + Fixtures\companies_get_by_id.json + + + Fixtures\companies_list.json + + + Fixtures\fees_create.json + + + Fixtures\fees_get_by_id.json + + + Fixtures\fees_list.json + + + Fixtures\generate_card_token.json + + + Fixtures\items_create.json + + + Fixtures\items_delete.json + + + Fixtures\items_delete_unsuccessful.json + + + Fixtures\items_edit.json + + + Fixtures\items_edit_unsuccessful.json + + + Fixtures\items_get_bpay_details.json + + + Fixtures\items_get_buyer.json + + + Fixtures\items_get_by_id.json + + + Fixtures\items_get_seller.json + + + Fixtures\items_get_status.json + + + Fixtures\items_get_wire_details.json + + + Fixtures\items_list.json + + + Fixtures\items_list_fees.json + + + Fixtures\items_list_transactions.json + + + Fixtures\items_not_found.json + + + Fixtures\paypal_account_create.json + + + Fixtures\paypal_account_delete.json + + + Fixtures\paypal_account_get_by_id.json + + + Fixtures\paypal_account_get_users.json + + + Fixtures\transactions_list.json + + + Fixtures\user_bank_accounts.json + + + Fixtures\user_bank_accounts_empty.json + + + Fixtures\user_card_accounts.json + + + Fixtures\user_card_accounts_empty.json + + + Fixtures\user_create.json + + + Fixtures\user_items.json + + + Fixtures\user_missing.json + + + Fixtures\user_paypal_accounts.json + + + Fixtures\user_paypal_accounts_empty.json + + + Fixtures\user_set_disbursement_account.json + + + Fixtures\user_update.json + + + Fixtures\users_list.json + - - - - - False - - - False - - - False - - - False - - - - - - - \ No newline at end of file diff --git a/PromisePayDotNet.Tests/Properties/AssemblyInfo.cs b/PromisePayDotNet.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 46fb64a..0000000 --- a/PromisePayDotNet.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("PromisePayDotNet.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("PromisePayDotNet.Tests")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("1cb11b5a-6ce3-414a-a467-414b2b2b2266")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PromisePayDotNet.Tests/TokenTest.cs b/PromisePayDotNet.Tests/TokenTest.cs index f775209..50cd0c3 100644 --- a/PromisePayDotNet.Tests/TokenTest.cs +++ b/PromisePayDotNet.Tests/TokenTest.cs @@ -1,48 +1,46 @@ -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; -using RestSharp; +using PromisePayDotNet.Internals; namespace PromisePayDotNet.Tests { public class TokenTest { - [Test] - [Ignore("it seems I have created a token already, so it return error")] + //[Fact] + //[Ignore("it seems I have created a token already, so it return error")] public void RequestToken() { - var repo = new TokenRepository(new RestClient()); - var token = repo.RequestToken(); + //var repo = new TokenRepository(new RestClient()); + //var token = repo.RequestToken(); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void RequestSessionToken() { - var repo = new TokenRepository(new RestClient()); - var result = repo.RequestSessionToken(new Token - { - CurrentUserId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c", - Amount = "$100.00", - ExternalItemId = "b3b4d024-a6de-4b04-9f8d-6545eef3b28f", - ExternalBuyerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e", - ExternalSellerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c", - BuyerEmail = "aaa@bbb.com", - SellerEmail = "ccc@ddd.com", - BuyerCountry = "AUS", - SellerCountry = "AUS", - BuyerFirstName = "Preved", - SellerFirstName = "Medved", - ItemName = "Bear" - }); + //var repo = new TokenRepository(new RestClient()); + //var result = repo.RequestSessionToken(new Token + //{ + // CurrentUserId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c", + // Amount = "$100.00", + // ExternalItemId = "b3b4d024-a6de-4b04-9f8d-6545eef3b28f", + // ExternalBuyerId = "fdf58725-96bd-4bf8-b5e6-9b61be20662e", + // ExternalSellerId = "ec9bf096-c505-4bef-87f6-18822b9dbf2c", + // BuyerEmail = "aaa@bbb.com", + // SellerEmail = "ccc@ddd.com", + // BuyerCountry = "AUS", + // SellerCountry = "AUS", + // BuyerFirstName = "Preved", + // SellerFirstName = "Medved", + // ItemName = "Bear" + //}); } - [Test] - [Ignore("Not implemented yet")] + //[Ignore("Not implemented yet")] public void Widget() { - var repo = new TokenRepository(new RestClient()); - var widget = repo.GetWidget("aaa-bbb-cc"); + //var repo = new TokenRepository(new RestClient()); + //var widget = repo.GetWidget("aaa-bbb-cc"); } } } diff --git a/PromisePayDotNet.Tests/TransactionTest.cs b/PromisePayDotNet.Tests/TransactionTest.cs index be6e31f..dd9a5f6 100644 --- a/PromisePayDotNet.Tests/TransactionTest.cs +++ b/PromisePayDotNet.Tests/TransactionTest.cs @@ -1,49 +1,50 @@ using System.IO; using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; using System; -using RestSharp; +using PromisePayDotNet.Internals; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { public class TransactionTest : AbstractTest { - [Test] + [Fact] public void TransactionDeserialization() { var jsonStr = "{\"id\": \"8d8237c2-8598-4100-9fa5-f4ced75e7d76\",\"created_at\": \"2014-12-29T09:40:47.046Z\",\"updated_at\": \"2014-12-29T09:40:47.489Z\",\"description\": \"Buyer Fee @ 10%\",\"amount\": 5000,\"currency\":\"USD\",\"type\":\"debit\",\"from\": \"Escrow Vault\",\"to\": \"Awesome Websites\",\"related\": {\"transactions\":\"6a5525cf-e82f-40e7-995a-ad747185052a\"},\"links\":{\"self\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76\",\"users\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76/users\",\"fees\":\"/transactions/8d8237c2-8598-4100-9fa5-f4ced75e7d76/fees\"}}"; var transaction = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("8d8237c2-8598-4100-9fa5-f4ced75e7d76", transaction.Id); + Assert.Equal("8d8237c2-8598-4100-9fa5-f4ced75e7d76", transaction.Id); } - [Test] + [Fact] public void ListTransactionsSuccessful() { //First, create a user, so we'll have at least one - var content = File.ReadAllText("../../Fixtures/transactions_list.json"); + var content = Files.ReadAllText("./Fixtures/transactions_list.json"); var client = GetMockClient(content); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); //Then, list users var transactions = repo.ListTransactions(200); - Assert.IsNotNull(transactions); + Assert.NotNull(transactions); } - [Test] + [Fact] public void ListTransactionsNegativeParams() { var client = GetMockClient(""); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListTransactions(-10, -20)); } - [Test] + [Fact] public void ListTransactionsTooHighLimit() { var client = GetMockClient(""); - var repo = new TransactionRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListTransactions(201)); } } diff --git a/PromisePayDotNet.Tests/UploadTest.cs b/PromisePayDotNet.Tests/UploadTest.cs index b4f0d69..3450d8b 100644 --- a/PromisePayDotNet.Tests/UploadTest.cs +++ b/PromisePayDotNet.Tests/UploadTest.cs @@ -1,57 +1,57 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Implementations; -using RestSharp; +using PromisePayDotNet.Internals; namespace PromisePayDotNet.Tests { public class UploadTest { - [Test] + [Fact] public void UploadDeserialization() { const string jsonStr = "{ \"id\": \"a2711d90-ed41-4d12-81d2-000000000002\", \"processed_lines\": 6, \"total_lines\": 6, \"update_lines\": 0, \"error_lines\": 6, \"progress\": 100.0 }"; var upload = JsonConvert.DeserializeObject(jsonStr); - Assert.IsNotNull(upload); - Assert.AreEqual("a2711d90-ed41-4d12-81d2-000000000002", upload.Id); + Assert.NotNull(upload); + Assert.Equal("a2711d90-ed41-4d12-81d2-000000000002", upload.Id); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void CreateUploadSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void ListUploadsSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void GetUploadByIdSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void GetStatusSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } - [Test] - [Ignore("Not implemented yet")] + //[Fact] + //[Ignore("Not implemented yet")] public void StartImportSuccessfully() { - Assert.Fail(); + throw new System.Exception(); } diff --git a/PromisePayDotNet.Tests/UserTest.cs b/PromisePayDotNet.Tests/UserTest.cs index 39e1a16..a362154 100644 --- a/PromisePayDotNet.Tests/UserTest.cs +++ b/PromisePayDotNet.Tests/UserTest.cs @@ -1,12 +1,13 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; using PromisePayDotNet.Implementations; using System; using System.Linq; -using RestSharp; +using PromisePayDotNet.Internals; using System.IO; +using PromisePayDotNet.Abstractions; namespace PromisePayDotNet.Tests { @@ -15,21 +16,21 @@ public class UserTest : AbstractTest public string GetUserByIdResponse = "{\"created_at\":\"2015-05-18T06:50:51.684Z\",\"updated_at\":\"2015-05-18T11:36:14.050Z\",\"full_name\":\"Igor Sidorov\",\"email\":\"idsidorov@gmail.com\",\"mobile\":null,\"phone\":null,\"first_name\":\"Igor\",\"last_name\":\"Sidorov\",\"id\":\"ef831cd65790e232f6e8c316d6a2ce50\",\"verification_state\":\"pending\",\"held_state\":false,\"dob\":\"Not provided.\",\"government_number\":\"Not provided.\",\"drivers_license\":\"Not provided.\",\"related\":{\"addresses\":\"f08a5f8a-698f-41cf-ac2e-7d5cc52eb915\",\"companies\":\"e466dfb4-f05c-4c7f-92a3-09a0a28c7af5\"},\"links\":{\"self\":\"/users/ef831cd65790e232f6e8c316d6a2ce50\",\"items\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/items\",\"card_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/card_accounts\",\"paypal_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/paypal_accounts\",\"bank_accounts\":\"/users/ef831cd65790e232f6e8c316d6a2ce50/bank_accounts\"}}"; - [Test] + [Fact] public void TestUserDaoObject() { var user = JsonConvert.DeserializeObject(GetUserByIdResponse); - Assert.AreEqual("Igor Sidorov", user.FullName); - Assert.IsTrue(user.CreatedAt.HasValue); - Assert.IsTrue(user.UpdatedAt.HasValue); + Assert.Equal("Igor Sidorov", user.FullName); + Assert.True(user.CreatedAt.HasValue); + Assert.True(user.UpdatedAt.HasValue); } - [Test] + [Fact] public void UserCreateSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -46,21 +47,21 @@ public void UserCreateSuccessful() var createdUser = repo.CreateUser(user); - Assert.AreEqual(user.Id, createdUser.Id); - Assert.AreEqual(user.FirstName, createdUser.FirstName); - Assert.AreEqual(user.LastName, createdUser.LastName); - Assert.AreEqual("Test Test", createdUser.FullName); - Assert.AreEqual(user.Email, createdUser.Email); - Assert.IsTrue(createdUser.CreatedAt.HasValue); - Assert.IsTrue(createdUser.UpdatedAt.HasValue); + Assert.Equal(user.Id, createdUser.Id); + Assert.Equal(user.FirstName, createdUser.FirstName); + Assert.Equal(user.LastName, createdUser.LastName); + Assert.Equal("Test Test", createdUser.FullName); + Assert.Equal(user.Email, createdUser.Email); + Assert.True(createdUser.CreatedAt.HasValue); + Assert.True(createdUser.UpdatedAt.HasValue); } - [Test] + [Fact] public void ValidationErrorUserCreateMissedId() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -77,12 +78,12 @@ public void ValidationErrorUserCreateMissedId() Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ValidationErrorUserCreateMissedFirstName() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -99,12 +100,12 @@ public void ValidationErrorUserCreateMissedFirstName() Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ValidationErrorUserCreateWrongCountry() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -121,12 +122,12 @@ public void ValidationErrorUserCreateWrongCountry() Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ValidationErrorUserCreateWrongEmail() { - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -143,13 +144,13 @@ public void ValidationErrorUserCreateWrongEmail() Assert.Throws(() => repo.CreateUser(user)); } - [Test] + [Fact] public void ListUsersSuccessful() { //First, create a user, so we'll have at least one - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "ec9bf096-c505-4bef-87f6-18822b9dbf2c"; var user = new User { @@ -167,44 +168,44 @@ public void ListUsersSuccessful() var createdUser = repo.CreateUser(user); //Then, list users - content = File.ReadAllText("../../Fixtures/users_list.json"); + content = Files.ReadAllText("./Fixtures/users_list.json"); client = GetMockClient(content); - repo = new UserRepository(client.Object); + repo = Get(client.Object); var users = repo.ListUsers(200); - Assert.IsNotNull(users); - Assert.IsTrue(users.Any()); - Assert.IsTrue(users.Any(x => x.Id == id)); + Assert.NotNull(users); + Assert.True(users.Any()); + Assert.True(users.Any(x => x.Id == id)); } - [Test] + [Fact] public void ListUsersNegativeParams() { - var content = File.ReadAllText("../../Fixtures/users_list.json"); + var content = Files.ReadAllText("./Fixtures/users_list.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(()=>repo.ListUsers(-10, -20)); } - [Test] + [Fact] public void ListUsersTooHighLimit() { - var content = File.ReadAllText("../../Fixtures/users_list.json"); + var content = Files.ReadAllText("./Fixtures/users_list.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); Assert.Throws(() => repo.ListUsers(201)); } - [Test] + [Fact] public void GetUserSuccessful() { //First, create a user with known id - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -224,27 +225,27 @@ public void GetUserSuccessful() //Then, get user var gotUser = repo.GetUserById(id); - Assert.IsNotNull(gotUser); - Assert.AreEqual(gotUser.Id, id); + Assert.NotNull(gotUser); + Assert.Equal(gotUser.Id, id); } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void GetUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "asdfkjas;lkflaksndflaksndfklas"; Assert.Throws(() => repo.GetUserById(id)); } - [Test] - [Ignore("Skipped until API method will be fixed")] + //[Fact] + //[Ignore("Skipped until API method will be fixed")] public void DeleteUserSuccessful() { //First, create a user with known id - var repo = new UserRepository(new RestClient()); + var repo = Get(); var id = Guid.NewGuid().ToString(); var user = new User { @@ -263,8 +264,8 @@ public void DeleteUserSuccessful() //Then, get user var gotUser = repo.GetUserById(id); - Assert.IsNotNull(gotUser); - Assert.AreEqual(gotUser.Id, id); + Assert.NotNull(gotUser); + Assert.Equal(gotUser.Id, id); //Now, delete user repo.DeleteUser(id); @@ -282,29 +283,29 @@ public void DeleteUserSuccessful() if (!success) { - Assert.Fail("Delete user failed!"); + throw new Exception("Delete user failed!"); } } - [Test] + [Fact] //That's bad idea not to distinguish between "wrong login/password" and "There is no such ID in DB" public void DeleteUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, System.Net.HttpStatusCode.NotFound); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); - Assert.IsFalse(repo.DeleteUser(id)); + Assert.False(repo.DeleteUser(id)); } - [Test] + [Fact] public void EditUserSuccessful() { //First, create a user we'll work with - var content = File.ReadAllText("../../Fixtures/user_create.json"); + var content = Files.ReadAllText("./Fixtures/user_create.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = "608ef7e7-6113-4981-a3a3-ab8cea04eb93"; var user = new User { @@ -325,21 +326,21 @@ public void EditUserSuccessful() user.FirstName = "Test123"; user.LastName = "Test123"; - content = File.ReadAllText("../../Fixtures/user_update.json"); + content = Files.ReadAllText("./Fixtures/user_update.json"); client = GetMockClient(content); - repo = new UserRepository(client.Object); + repo = Get(client.Object); var modifiedUser = repo.UpdateUser(user); - Assert.AreEqual("Test123", modifiedUser.FirstName); - Assert.AreEqual("Test123", modifiedUser.LastName); - Assert.AreEqual("Test123 Test123", modifiedUser.FullName); + Assert.Equal("Test123", modifiedUser.FirstName); + Assert.Equal("Test123", modifiedUser.LastName); + Assert.Equal("Test123 Test123", modifiedUser.FullName); } - [Test] + [Fact] public void EditUserMissingId() { - var content = File.ReadAllText("../../Fixtures/user_missing.json"); + var content = Files.ReadAllText("./Fixtures/user_missing.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var id = Guid.NewGuid().ToString(); var user = new User { @@ -358,64 +359,64 @@ public void EditUserMissingId() } - [Test] - [Ignore("Currently, this test returns 401")] + //[Fact] + //[Ignore("Currently, this test returns 401")] public void SendMobilePinSuccessful() { - var repo = new UserRepository(new RestClient()); + var repo = Get(); } - [Test] + [Fact] public void ListUserItemsSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_items.json"); + var content = Files.ReadAllText("./Fixtures/user_items.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.ListItemsForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void ListUserBankAccountsEmpty() { - var content = File.ReadAllText("../../Fixtures/user_bank_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_bank_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.ListBankAccountsForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void ListUserCardAccountsEmpty() { - var content = File.ReadAllText("../../Fixtures/user_card_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_card_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.ListCardAccountsForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void ListUserPayPalAccountsEmpty() { - var content = File.ReadAllText("../../Fixtures/user_paypal_accounts_empty.json"); + var content = Files.ReadAllText("./Fixtures/user_paypal_accounts_empty.json"); var client = GetMockClient(content, (System.Net.HttpStatusCode)422); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var items = repo.ListPayPalAccountsForUser("89592d8a-6cdb-4857-a90d-b41fc817d639"); } - [Test] + [Fact] public void SetDisbursementAccountsSuccessful() { - var content = File.ReadAllText("../../Fixtures/user_set_disbursement_account.json"); + var content = Files.ReadAllText("./Fixtures/user_set_disbursement_account.json"); var client = GetMockClient(content); - var repo = new UserRepository(client.Object); + var repo = Get(client.Object); var account = repo.SetDisbursementAccount("ec9bf096-c505-4bef-87f6-18822b9dbf2c", "09b5bb3c-c0fd-404d-b373-d675f42d8865"); - Assert.AreEqual("test sdfdf edited Test", account.FullName); - Assert.AreEqual("pending", account.VerificationState); + Assert.Equal("test sdfdf edited Test", account.FullName); + Assert.Equal("pending", account.VerificationState); } } diff --git a/PromisePayDotNet.Tests/WidgetTest.cs b/PromisePayDotNet.Tests/WidgetTest.cs index b498625..f61f997 100644 --- a/PromisePayDotNet.Tests/WidgetTest.cs +++ b/PromisePayDotNet.Tests/WidgetTest.cs @@ -1,19 +1,19 @@ using Newtonsoft.Json; -using NUnit.Framework; -using PromisePayDotNet.DTO; +using Xunit; +using PromisePayDotNet.Dto; namespace PromisePayDotNet.Tests { public class WidgetTest { - [Test] + [Fact] public void WidgetDeserialization() { const string jsonStr = "{ item_name: \"Toyota Hilux\", full_amount: \"$1,455.00\", amount: \"$1,500.00\", fees: \"$45.00\", fee_name: \"Seller Fee @ 3%\", remaining_amount: \"$1,500.00\", release_request_amount: null, currency: \"USD\", description: \"Payment has not yet been made.
Bobby Buyer must place the above amount into escrow to begin this transaction. Their payment will be locked in our vault until you have delivered 'Toyota Hilux'.\", action_name: \"Request payment\", status: \"pending\", has_pending_release: true, verification_state: \"pending\", verification_information: false, disbursement_account: false, payment_method: \"bank\", dispute_user: null, role: \"seller\", other_user_name: \"Bobby Buyer\", primary_color: null, secondary_color: null, third_color: null, fourth_color: null, bank_account: false, tax_invoice: null, buyer_url: \"C:/promisepay-marketplace/app/index.html\", seller_url: \"C:/promisepay-marketplace/app/index.html\" }"; var widget = JsonConvert.DeserializeObject(jsonStr); - Assert.AreEqual("Toyota Hilux", widget.ItemName); - Assert.AreEqual("bank", widget.PaymentMethod); + Assert.Equal("Toyota Hilux", widget.ItemName); + Assert.Equal("bank", widget.PaymentMethod); } } } diff --git a/PromisePayDotNet.Tests/packages.config b/PromisePayDotNet.Tests/packages.config deleted file mode 100644 index 0870de3..0000000 --- a/PromisePayDotNet.Tests/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/PromisePayDotNet/Abstractions/IAddressRepository.cs b/PromisePayDotNet/Abstractions/IAddressRepository.cs new file mode 100644 index 0000000..15f954f --- /dev/null +++ b/PromisePayDotNet/Abstractions/IAddressRepository.cs @@ -0,0 +1,28 @@ +using PromisePayDotNet.Dto; +using System.Threading.Tasks; +using PromisePayDotNet.Internals; +namespace PromisePayDotNet.Abstractions +{ + /// + /// User api + /// https://reference.assemblypayments.com/#addresses + /// Addresses are associated with a User and Companies. The User Address is required for Users that are assigned as sellers, and is optional for buyers. If the User is a principal of a Company, then the Company Address is also required. + /// While an Address is optional for users set as buyers, it is recommended that you capture and create all Users with an Address, as they may at some stage be a seller on your marketplace or platform. + /// + public interface IAddressRepository + { + /// + /// Show details of a specific Address using a given id. + /// + /// address ID + /// + Task
GetAddressByIdAsync(string addressId); + } + public static class AddressRepositoryExtensions + { + public static Address GetAddressById(this IAddressRepository repo, string addressId) + { + return repo.GetAddressByIdAsync(addressId).WrapResult(); + } + } +} diff --git a/PromisePayDotNet/Abstractions/IBankAccountRepository.cs b/PromisePayDotNet/Abstractions/IBankAccountRepository.cs new file mode 100644 index 0000000..3f23ff6 --- /dev/null +++ b/PromisePayDotNet/Abstractions/IBankAccountRepository.cs @@ -0,0 +1,36 @@ +using PromisePayDotNet.Dto; +using PromisePayDotNet.Internals; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Abstractions +{ + public interface IBankAccountRepository + { + Task GetBankAccountByIdAsync(string bankAccountId); + + Task CreateBankAccountAsync(BankAccount bankAccount); + + Task DeleteBankAccountAsync(string bankAccountId); + + Task GetUserForBankAccountAsync(string bankAccountId); + } + public static class BankAccountRepositoryExtensions + { + public static BankAccount GetBankAccountById(this IBankAccountRepository repo, string bankAccountId) + { + return repo.GetBankAccountByIdAsync(bankAccountId).WrapResult(); + } + public static BankAccount CreateBankAccount(this IBankAccountRepository repo, BankAccount bankAccount) + { + return repo.CreateBankAccountAsync(bankAccount).WrapResult(); + } + public static bool DeleteBankAccount(this IBankAccountRepository repo, string bankAccountId) + { + return repo.DeleteBankAccountAsync(bankAccountId).WrapResult(); + } + public static User GetUserForBankAccount(this IBankAccountRepository repo, string bankAccountId) + { + return repo.GetUserForBankAccountAsync(bankAccountId).WrapResult(); + } + } +} diff --git a/PromisePayDotNet/Interfaces/ICardAccountRepository.cs b/PromisePayDotNet/Abstractions/ICardAccountRepository.cs similarity index 81% rename from PromisePayDotNet/Interfaces/ICardAccountRepository.cs rename to PromisePayDotNet/Abstractions/ICardAccountRepository.cs index a0f58df..2fb4be0 100644 --- a/PromisePayDotNet/Interfaces/ICardAccountRepository.cs +++ b/PromisePayDotNet/Abstractions/ICardAccountRepository.cs @@ -1,6 +1,6 @@ -using PromisePayDotNet.DTO; +using PromisePayDotNet.Dto; -namespace PromisePayDotNet.Interfaces +namespace PromisePayDotNet.Abstractions { public interface ICardAccountRepository { diff --git a/PromisePayDotNet/Interfaces/ICompanyRepository.cs b/PromisePayDotNet/Abstractions/ICompanyRepository.cs similarity index 80% rename from PromisePayDotNet/Interfaces/ICompanyRepository.cs rename to PromisePayDotNet/Abstractions/ICompanyRepository.cs index d4e6564..59ac7ff 100644 --- a/PromisePayDotNet/Interfaces/ICompanyRepository.cs +++ b/PromisePayDotNet/Abstractions/ICompanyRepository.cs @@ -1,7 +1,7 @@ -using PromisePayDotNet.DTO; +using PromisePayDotNet.Dto; using System.Collections.Generic; -namespace PromisePayDotNet.Interfaces +namespace PromisePayDotNet.Abstractions { public interface ICompanyRepository { diff --git a/PromisePayDotNet/Abstractions/IFeeRepository.cs b/PromisePayDotNet/Abstractions/IFeeRepository.cs new file mode 100644 index 0000000..eda81ff --- /dev/null +++ b/PromisePayDotNet/Abstractions/IFeeRepository.cs @@ -0,0 +1,24 @@ +using PromisePayDotNet.Dto; +using System.Collections.Generic; +using System.Threading.Tasks; +using PromisePayDotNet.Internals; + +namespace PromisePayDotNet.Abstractions +{ + public interface IFeeRepository + { + + Task> ListFeesAsync(); + + Task GetFeeByIdAsync(string feeId); + + Task CreateFeeAsync(Fee fee); + } + + public static class IFeeRepositoryExtensions + { + public static IEnumerable ListFees(this IFeeRepository repo) => repo.ListFeesAsync().WrapResult(); + public static Fee GetFeeById(this IFeeRepository repo, string feeId) => repo.GetFeeByIdAsync(feeId).WrapResult(); + public static Fee CreateFee(this IFeeRepository repo, Fee item) => repo.CreateFeeAsync(item).WrapResult(); + } +} diff --git a/PromisePayDotNet/Abstractions/IItemRepository.cs b/PromisePayDotNet/Abstractions/IItemRepository.cs new file mode 100644 index 0000000..7844d17 --- /dev/null +++ b/PromisePayDotNet/Abstractions/IItemRepository.cs @@ -0,0 +1,135 @@ +using PromisePayDotNet.Dto; +using PromisePayDotNet.Internals; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Abstractions +{ + public interface IItemRepository + { + /// + /// Retrieve an ordered and paginated list of existing Items. + /// + Task> ListItemsAsync(int limit = 10, int offset = 0); + /// + /// Show details of a specific Item using a given :id. + /// + Task GetItemByIdAsync(string itemId); + /// + /// Create an Item. Items require two Users, a buyer and a seller. + /// + /// The payment type can be one of Escrow, Express, Escrow Partial Release or Approve. + /// + /// The buyer_id and seller_id are your unique user identifiers. + /// + Task CreateItemAsync(Item item); + /// + /// Delete an existing Item using a given :id. + /// + Task DeleteItemAsync(string itemId); + /// + /// Update an existing Items attributes using a given :id. + /// + Task UpdateItemAsync(Item item); + /// + /// Retrieve an ordered and paginated list of Transactions associated with the Item using a given :id. + /// + Task> ListTransactionsForItemAsync(string itemId); + /// + /// Show the status of an Item using a given :id. + /// + Task GetStatusForItemAsync(string itemId); + /// + /// Show the Fees associated with the Item using a given :id. + /// + Task> ListFeesForItemAsync(string itemId); + /// + /// Show the buyer User associated with the Item using a given :id. + /// + Task GetBuyerForItemAsync(string itemId); + /// + /// Show the seller User associated with the Item using a given :id. + /// + Task GetSellerForItemAsync(string itemId); + /// + /// Show the Item wire payment details using a given :id. + /// + Task GetWireDetailsForItemAsync(string itemId); + /// + /// Show the Item BPay payment details using a given :id. + /// + Task GetBPayDetailsForItemAsync(string itemId); + + //actions methods start here + /// + /// Make a payment for an Item. Pass the :account_id of a Bank Account or a Card Account associated with the Item’s buyer. + /// + /// The Item state will transition to one of payment_held, payment_pending, payment_deposited for an Escrow or Escrow Partial Release payment type. + /// + /// The Item state will transition to one of payment_held, payment_pending or completed for an Express or Approve payment type. + /// + Task MakePaymentAsync(string itemId, string accountId); + /// + /// Request payment for an Item. This can trigger an email or an SMS with instructions for payment. Contact support@assemblypayments.com if you require email or SMS notifications configured. This will transition the Item state to payment_required. + /// + Task RequestPaymentAsync(string itemId); + /// + /// Release funds held in escrow from an Item with an Escrow or Escrow Partial Release payment type. This will transition the Item state to completed. + /// + Task ReleasePaymentAsync(string itemId, int releaseAmount); + /// + /// Request release of funds held in escrow, from an Item with an Escrow or Escrow Partial Release payment type. This will transition the Item state to work_completed. + /// + Task RequestReleaseAsync(string itemId, int releaseAmount); + /// + /// Cancel an Item. This will transition the Item state to cancelled. Items can only be cancelled if they haven’t been actioned in any other way. + /// + Task CancelAsync(string itemId); + /// + /// Acknowledge that funds are being wired for payment. This will transition the Item state to wire_pending. + /// + Task AcknowledgeWireAsync(string itemId); + /// + /// + /// + Task AcknowledgePayPalAsync(string itemId); + /// + /// Revert an acknowledge wire Item Action. This will transition the Item state to pending. + /// + Task RevertWireAsync(string itemId); + /// + /// Request a refund for an Item. This will transition the Item status to refund_flagged. + /// + Task RequestRefundAsync(string itemId, string refundAmount, string refundMessage); + /// + /// Refund an Item’s funds held in escrow. An partial amount can be specified otherwise the full amount will be refunded. This will transition the Item state to ‘refunded’ if the full amount is refunded, or to the previously held state if a partial amount is specified. + /// + Task RefundAsync(string itemId, string refundAmount, string refundMessage); + } + + public static class ItemRepositoryExtensions + { + public static IEnumerable ListItems(this IItemRepository repo, int limit = 10, int offset = 0)=> repo.ListItemsAsync(offset: offset, limit:limit).WrapResult(); + public static Item GetItemById(this IItemRepository repo, string itemId) => repo.GetItemByIdAsync(itemId).WrapResult(); + public static Item CreateItem(this IItemRepository repo, Item item) => repo.CreateItemAsync(item).WrapResult(); + public static bool DeleteItem(this IItemRepository repo, string itemId) => repo.DeleteItemAsync(itemId).WrapResult(); + public static Item UpdateItem(this IItemRepository repo, Item item) => repo.UpdateItemAsync(item).WrapResult(); + public static IEnumerable ListTransactionsForItem(this IItemRepository repo, string itemId) => repo.ListTransactionsForItemAsync(itemId).WrapResult(); + public static ItemStatus GetStatusForItem(this IItemRepository repo, string itemId) => repo.GetStatusForItemAsync(itemId).WrapResult(); + public static IEnumerable ListFeesForItem(this IItemRepository repo, string itemId) => repo.ListFeesForItemAsync(itemId).WrapResult(); + public static User GetBuyerForItem(this IItemRepository repo, string itemId) => repo.GetBuyerForItemAsync(itemId).WrapResult(); + public static User GetSellerForItem(this IItemRepository repo, string itemId) => repo.GetSellerForItemAsync(itemId).WrapResult(); + public static WireDetails GetWireDetailsForItem(this IItemRepository repo, string itemId) => repo.GetWireDetailsForItemAsync(itemId).WrapResult(); + public static BPayDetails GetBPayDetailsForItem(this IItemRepository repo, string itemId) => repo.GetBPayDetailsForItemAsync(itemId).WrapResult(); + public static Item MakePayment(this IItemRepository repo, string itemId, string accountId) => repo.MakePaymentAsync(itemId, accountId).WrapResult(); + public static Item RequestPayment(this IItemRepository repo, string itemId) => repo.RequestPaymentAsync(itemId).WrapResult(); + public static Item ReleasePayment(this IItemRepository repo, string itemId, int releaseAmount) => repo.ReleasePaymentAsync(itemId, releaseAmount).WrapResult(); + public static Item RequestRelease(this IItemRepository repo, string itemId, int releaseAmount) => repo.RequestReleaseAsync(itemId, releaseAmount).WrapResult(); + public static Item Cancel(this IItemRepository repo, string itemId) => repo.CancelAsync(itemId).WrapResult(); + public static Item AcknowledgeWire(this IItemRepository repo, string itemId) => repo.AcknowledgeWireAsync(itemId).WrapResult(); + public static Item AcknowledgePayPal(this IItemRepository repo, string itemId) => repo.AcknowledgePayPalAsync(itemId).WrapResult(); + public static Item RevertWire(this IItemRepository repo, string itemId) => repo.RevertWireAsync(itemId).WrapResult(); + public static Item RequestRefund(this IItemRepository repo, string itemId, string refundAmount, string refundMessage) => repo.RequestRefundAsync(itemId, refundAmount, refundMessage).WrapResult(); + public static Item Refund(this IItemRepository repo, string itemId, string refundAmount, string refundMessage) => repo.RefundAsync(itemId, refundAmount, refundMessage).WrapResult(); + } +} diff --git a/PromisePayDotNet/Interfaces/IPayPalAccountRepository.cs b/PromisePayDotNet/Abstractions/IPayPalAccountRepository.cs similarity index 82% rename from PromisePayDotNet/Interfaces/IPayPalAccountRepository.cs rename to PromisePayDotNet/Abstractions/IPayPalAccountRepository.cs index 0deb0be..f6cadf4 100644 --- a/PromisePayDotNet/Interfaces/IPayPalAccountRepository.cs +++ b/PromisePayDotNet/Abstractions/IPayPalAccountRepository.cs @@ -1,6 +1,6 @@ -using PromisePayDotNet.DTO; +using PromisePayDotNet.Dto; -namespace PromisePayDotNet.Interfaces +namespace PromisePayDotNet.Abstractions { public interface IPayPalAccountRepository { diff --git a/PromisePayDotNet/Abstractions/ITokenRepository.cs b/PromisePayDotNet/Abstractions/ITokenRepository.cs new file mode 100644 index 0000000..8ea7279 --- /dev/null +++ b/PromisePayDotNet/Abstractions/ITokenRepository.cs @@ -0,0 +1,38 @@ +using PromisePayDotNet.Dto; +using PromisePayDotNet.Internals; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Abstractions +{ + public interface ITokenRepository + { + /// + /// NOTE: Not documented on site + /// + Task RequestTokenAsync(); + /// + /// NOTE: Not documented on site + /// + Task> RequestSessionTokenAsync(Token token); + /// + /// NOTE: Not documented on site + /// + Task GetWidgetAsync(string sessionToken); + /// + /// https://reference.assemblypayments.com/#token-auth + /// Create a card token that can be used with the PromisePay.js package to securely send Assembly credit card details. + /// + Task GenerateCardTokenAsync(string tokenType, string userId); + } + public static class TokenRepositoryExtensions + { + public static string RequestToken(this ITokenRepository repo) => repo.RequestTokenAsync().WrapResult(); + + public static IDictionary RequestSessionToken(this ITokenRepository repo,Token token) => repo.RequestSessionTokenAsync(token).WrapResult(); + + public static Widget GetWidget(this ITokenRepository repo, string sessionToken) => repo.GetWidgetAsync(sessionToken).WrapResult(); + + public static CardToken GenerateCardToken(this ITokenRepository repo, string tokenType, string userId) => repo.GenerateCardTokenAsync(tokenType, userId).WrapResult(); + } +} diff --git a/PromisePayDotNet/Abstractions/ITransactionRepository.cs b/PromisePayDotNet/Abstractions/ITransactionRepository.cs new file mode 100644 index 0000000..a280ca5 --- /dev/null +++ b/PromisePayDotNet/Abstractions/ITransactionRepository.cs @@ -0,0 +1,39 @@ +using PromisePayDotNet.Dto; +using PromisePayDotNet.Internals; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Abstractions +{ + public interface ITransactionRepository + { + /// + /// Retrieve an ordered and paginated list of Transactions. + /// + Task> ListTransactionsAsync(int limit = 10, int offset = 0); + /// + /// Show details of a specific Transaction using a given transactionId. + /// + Task GetTransactionAsync(string transactionId); + /// + /// Show the User associated with the Transaction using a given :id. + /// + Task GetUserForTransactionAsync(string transactionId); + /// + /// Show the Fees associated with the Transaction using a given :id. + /// + Task GetFeeForTransactionAsync(string transactionId); + } + + public static class TransactionRepositoryExtensions + { + public static IEnumerable ListTransactions(this ITransactionRepository repo, int limit = 10, int offset = 0) => + repo.ListTransactionsAsync(offset: offset, limit: limit).WrapResult(); + public static Transaction GetTransaction(this ITransactionRepository repo, string transactionId) => + repo.GetTransactionAsync(transactionId).WrapResult(); + public static User GetUserForTransaction(this ITransactionRepository repo, string transactionId) => + repo.GetUserForTransactionAsync(transactionId).WrapResult(); + public static Fee GetFeeForTransaction(this ITransactionRepository repo, string transactionId) => + repo.GetFeeForTransactionAsync(transactionId).WrapResult(); + } +} diff --git a/PromisePayDotNet/Interfaces/IUploadRepository.cs b/PromisePayDotNet/Abstractions/IUploadRepository.cs similarity index 81% rename from PromisePayDotNet/Interfaces/IUploadRepository.cs rename to PromisePayDotNet/Abstractions/IUploadRepository.cs index b295b27..acb956f 100644 --- a/PromisePayDotNet/Interfaces/IUploadRepository.cs +++ b/PromisePayDotNet/Abstractions/IUploadRepository.cs @@ -1,7 +1,7 @@ -using PromisePayDotNet.DTO; +using PromisePayDotNet.Dto; using System.Collections.Generic; -namespace PromisePayDotNet.Interfaces +namespace PromisePayDotNet.Abstractions { public interface IUploadRepository { diff --git a/PromisePayDotNet/Abstractions/IUserRepository.cs b/PromisePayDotNet/Abstractions/IUserRepository.cs new file mode 100644 index 0000000..d766e46 --- /dev/null +++ b/PromisePayDotNet/Abstractions/IUserRepository.cs @@ -0,0 +1,146 @@ +using PromisePayDotNet.Dto; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using PromisePayDotNet.Internals; +namespace PromisePayDotNet.Abstractions +{ + /// + /// https://reference.assemblypayments.com/#users + /// Payments can be paid and received by Users (buyers and/or sellers). Once a user is set up they can be associated with various objects, including Accounts, Items, Companies, and Addresses. There are a number of data requirements when creating Users, notably for sellers. + /// + public interface IUserRepository + { + /// + /// Retrieve an ordered and paginated list of existing Users. + /// + /// + /// + /// + /// + Task> ListUsersAsync(int limit = 10, int offset = 0, string search=null); + /// + /// Show details of a specific User using a given id + /// + /// + /// + Task GetUserByIdAsync(string userId); + /// + /// Create a User. Users can be associated with Items either as a buyer or a seller. + /// Users can’t be both the buyer and seller for the same Item. + /// + /// + /// + Task CreateUserAsync(User user); + /// + /// Show details of a specific User using a given id + /// + /// + /// + Task UpdateUserAsync(User user); + /// + /// + /// + /// + /// + Task DeleteUserAsync(string userId); + /// + /// Retrieve an ordered and paginated list of existing Items the User is associated with using a given id. + /// + /// + /// + Task> ListItemsForUserAsync(string userId); + /// + /// Show a User’s PayPal Account using a given :id. + /// + /// + /// + Task> ListPayPalAccountsForUserAsync(string userId); + /// + /// Show the User’s Bank Account using a given :id. + /// + /// + /// + Task> ListCardAccountsForUserAsync(string userId); + /// + /// Show the User’s Bank Account using a given :id. + /// + /// + /// + Task> ListBankAccountsForUserAsync(string userId); + /// + /// Set the User’s Disbursement Account using a given User :id and one of either a Bank Account :account_id or a PayPal Account :account_id + /// + /// + /// + /// + Task SetDisbursementAccountAsync(string userId, string accountId); + } + + public static class UserRepositoryExtensions + { + public static IEnumerable ListUsers(this IUserRepository repo, int limit = 10, int offset = 0)=> + repo.ListUsersAsync(offset: offset, limit: limit).WrapResult(); + + public static User GetUserById(this IUserRepository repo, string userId)=> + repo.GetUserByIdAsync(userId).WrapResult(); + + public static User CreateUser(this IUserRepository repo, User user)=> + repo.CreateUserAsync(user).WrapResult(); + + public static User UpdateUser(this IUserRepository repo, User user)=> + repo.UpdateUserAsync(user).WrapResult(); + + public static bool DeleteUser(this IUserRepository repo, string userId)=> + repo.DeleteUserAsync(userId).WrapResult(); + + public static IEnumerable ListItemsForUser(this IUserRepository repo, string userId)=> + repo.ListItemsForUserAsync(userId).WrapResult(); + + public static IEnumerable ListPayPalAccountsForUser(this IUserRepository repo, string userId)=> + repo.ListPayPalAccountsForUserAsync(userId).WrapResult(); + + public static IEnumerable ListCardAccountsForUser(this IUserRepository repo, string userId)=> + repo.ListCardAccountsForUserAsync(userId).WrapResult(); + + public static IEnumerable ListBankAccountsForUser(this IUserRepository repo, string userId)=> + repo.ListBankAccountsForUserAsync(userId).WrapResult(); + + public static DisbursementAccount SetDisbursementAccount(this IUserRepository repo, string userId, string accountId)=> + repo.SetDisbursementAccountAsync(accountId: accountId, userId: userId).WrapResult(); + + + public static BankAccount GetBankAccountForUser(this IUserRepository repo, string userId)=> + repo.ListBankAccountsForUser(userId)?.FirstOrDefault(); + + public static CardAccount GetCardAccountForUser(this IUserRepository repo, string userId)=> + repo.ListCardAccountsForUser(userId)?.FirstOrDefault(); + + public static PayPalAccount GetPayPalAccountForUser(this IUserRepository repo, string userId)=> + repo.ListPayPalAccountsForUser(userId)?.FirstOrDefault(); + /// + /// Show the User’s Bank Account using a given :id. + /// + public static async Task GetBankAccountForUserAsync(this IUserRepository repo, string userId) + { + var r = await repo.ListBankAccountsForUserAsync(userId); + return r?.FirstOrDefault(); + } + /// + /// Show the User’s Bank Account using a given :id. + /// + public static async Task GetCardAccountForUserAsync(this IUserRepository repo, string userId) + { + var r = await repo.ListCardAccountsForUserAsync(userId); + return r?.FirstOrDefault(); + } + /// + /// Show a User’s PayPal Account using a given :id. + /// + public static async Task GetPayPalAccountForUserAsync(this IUserRepository repo, string userId) + { + var r = await repo.ListPayPalAccountsForUserAsync(userId); + return r?.FirstOrDefault(); + } + } +} diff --git a/PromisePayDotNet/DI/InitUnityContainer.cs b/PromisePayDotNet/DI/InitUnityContainer.cs deleted file mode 100644 index e9732a7..0000000 --- a/PromisePayDotNet/DI/InitUnityContainer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Microsoft.Practices.Unity; -using PromisePayDotNet.Implementations; -using PromisePayDotNet.Interfaces; -using RestSharp; - -namespace PromisePayDotNet.DI -{ - public class InitUnityContainer - { - public static void Init(IUnityContainer container) - { - container.RegisterType(new InjectionConstructor()); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - - - } - } -} diff --git a/PromisePayDotNet/DI/ServiceCollectionExtensions.cs b/PromisePayDotNet/DI/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..cf5c3c3 --- /dev/null +++ b/PromisePayDotNet/DI/ServiceCollectionExtensions.cs @@ -0,0 +1,41 @@ +using PromisePayDotNet.Implementations; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; +using PromisePayDotNet.Settings; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extensions to add promise pay repositories + /// + public static class ServiceCollectionExtensions + { + /// + /// Add promise pay repositories + /// + public static IServiceCollection AddPromisePay(this IServiceCollection container) + { + return AddPromisePay(container, null); + } + /// + /// Add promise pay repositories + /// + public static IServiceCollection AddPromisePay(this IServiceCollection container, PromisePaySettings options) + { + if (options != null) container.AddSingleton(Options.Options.Create(options)); + container.AddTransient(c => new RestClient()); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + container.AddTransient(); + return container; + } + } +} diff --git a/PromisePayDotNet/DTO/AbstractAccount.cs b/PromisePayDotNet/DTO/AbstractAccount.cs index 4da4b2f..861cc99 100644 --- a/PromisePayDotNet/DTO/AbstractAccount.cs +++ b/PromisePayDotNet/DTO/AbstractAccount.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public abstract class AbstractAccount : AbstractDTO { diff --git a/PromisePayDotNet/DTO/AbstractDTO.cs b/PromisePayDotNet/DTO/AbstractDTO.cs index 3fb3c8b..99d0500 100644 --- a/PromisePayDotNet/DTO/AbstractDTO.cs +++ b/PromisePayDotNet/DTO/AbstractDTO.cs @@ -2,22 +2,33 @@ using System; using System.Collections.Generic; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public abstract class AbstractDTO { + /// + /// Gets or sets the additional data. + /// [JsonExtensionData] public IDictionary AdditionalData { get; set; } - + /// + /// Gets or sets the links. + /// [JsonProperty(PropertyName = "links")] public IDictionary Links { get; set; } - + /// + /// Gets or sets the identifier. + /// [JsonProperty(PropertyName = "id")] public string Id { get; set; } - + /// + /// Gets or sets the created at time. + /// [JsonProperty(PropertyName = "created_at")] public DateTime? CreatedAt { get; set; } - + /// + /// Gets or sets the updated at time. + /// [JsonProperty(PropertyName = "updated_at")] public DateTime? UpdatedAt { get; set; } diff --git a/PromisePayDotNet/DTO/Address.cs b/PromisePayDotNet/DTO/Address.cs index 797e3ce..def47d5 100644 --- a/PromisePayDotNet/DTO/Address.cs +++ b/PromisePayDotNet/DTO/Address.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Address : AbstractDTO { diff --git a/PromisePayDotNet/DTO/BPayDetails.cs b/PromisePayDotNet/DTO/BPayDetails.cs index bafd3f6..06cbb18 100644 --- a/PromisePayDotNet/DTO/BPayDetails.cs +++ b/PromisePayDotNet/DTO/BPayDetails.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class BPayDetails { diff --git a/PromisePayDotNet/DTO/Bank.cs b/PromisePayDotNet/DTO/Bank.cs index df5aaa9..2a09e4b 100644 --- a/PromisePayDotNet/DTO/Bank.cs +++ b/PromisePayDotNet/DTO/Bank.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Bank { diff --git a/PromisePayDotNet/DTO/BankAccount.cs b/PromisePayDotNet/DTO/BankAccount.cs index 15331c5..f8595a2 100644 --- a/PromisePayDotNet/DTO/BankAccount.cs +++ b/PromisePayDotNet/DTO/BankAccount.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class BankAccount : AbstractAccount { diff --git a/PromisePayDotNet/DTO/Card.cs b/PromisePayDotNet/DTO/Card.cs index 161e041..e17bb41 100644 --- a/PromisePayDotNet/DTO/Card.cs +++ b/PromisePayDotNet/DTO/Card.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Card { diff --git a/PromisePayDotNet/DTO/CardAccount.cs b/PromisePayDotNet/DTO/CardAccount.cs index f8744ad..5e26e27 100644 --- a/PromisePayDotNet/DTO/CardAccount.cs +++ b/PromisePayDotNet/DTO/CardAccount.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class CardAccount : AbstractAccount { diff --git a/PromisePayDotNet/DTO/CardToken.cs b/PromisePayDotNet/DTO/CardToken.cs new file mode 100644 index 0000000..66a5271 --- /dev/null +++ b/PromisePayDotNet/DTO/CardToken.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace PromisePayDotNet.Dto +{ + public class CardToken + { + [JsonProperty(PropertyName = "token_type")] + public string TokenType { get; set; } + [JsonProperty(PropertyName = "token")] + public string Token { get; set; } + [JsonProperty(PropertyName = "user_id")] + public string UserId { get; set; } + } +} diff --git a/PromisePayDotNet/DTO/Company.cs b/PromisePayDotNet/DTO/Company.cs index 9d340e1..7b8d273 100644 --- a/PromisePayDotNet/DTO/Company.cs +++ b/PromisePayDotNet/DTO/Company.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Company : AbstractDTO { diff --git a/PromisePayDotNet/DTO/DetailsContainer.cs b/PromisePayDotNet/DTO/DetailsContainer.cs index 91840e6..191d0f4 100644 --- a/PromisePayDotNet/DTO/DetailsContainer.cs +++ b/PromisePayDotNet/DTO/DetailsContainer.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { internal class DetailsContainer { diff --git a/PromisePayDotNet/DTO/DisbursementAccount.cs b/PromisePayDotNet/DTO/DisbursementAccount.cs index d750a91..fd42903 100644 --- a/PromisePayDotNet/DTO/DisbursementAccount.cs +++ b/PromisePayDotNet/DTO/DisbursementAccount.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class DisbursementAccount : AbstractDTO { diff --git a/PromisePayDotNet/DTO/ErrorsDAO.cs b/PromisePayDotNet/DTO/ErrorsDAO.cs index f60906a..c608328 100644 --- a/PromisePayDotNet/DTO/ErrorsDAO.cs +++ b/PromisePayDotNet/DTO/ErrorsDAO.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class ErrorsDAO { diff --git a/PromisePayDotNet/DTO/Fee.cs b/PromisePayDotNet/DTO/Fee.cs index 3cbb920..7ebfe9b 100644 --- a/PromisePayDotNet/DTO/Fee.cs +++ b/PromisePayDotNet/DTO/Fee.cs @@ -1,29 +1,47 @@ using Newtonsoft.Json; using PromisePayDotNet.Enums; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { + /// + /// Fee is associated with an Item + /// public class Fee : AbstractDTO { + /// + /// Name + /// [JsonProperty(PropertyName = "name")] public string Name { get; set; } - + /// + /// + /// [JsonProperty(PropertyName = "fee_type_id")] public FeeType FeeType { get; set; } - + /// + /// Amount in cents + /// [JsonProperty(PropertyName = "amount")] public int Amount { get; set; } - + /// + /// Cap the Fee + /// [JsonProperty(PropertyName = "cap")] public string Cap { get; set; } - + /// + /// Minimum Fee + /// [JsonProperty(PropertyName = "min")] public string Min { get; set; } - + /// + /// Maximum Fee + /// [JsonProperty(PropertyName = "max")] public string Max { get; set; } - + /// + /// Who pays the fee (buyer, seller, cc, int_wire) + /// [JsonProperty(PropertyName = "to")] - public string To { get; set; } + public FeeToType To { get; set; } } } diff --git a/PromisePayDotNet/DTO/Item.cs b/PromisePayDotNet/DTO/Item.cs index 05dc5ee..f6646c3 100644 --- a/PromisePayDotNet/DTO/Item.cs +++ b/PromisePayDotNet/DTO/Item.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Item : AbstractDTO { @@ -25,7 +25,9 @@ public class Item : AbstractDTO [JsonProperty(PropertyName = "status")] public int Status { get; set; } - + /// + /// The cost in cents + /// [JsonProperty(PropertyName = "amount")] public int Amount { get; set; } diff --git a/PromisePayDotNet/DTO/ItemStatus.cs b/PromisePayDotNet/DTO/ItemStatus.cs index 84819ad..5443f92 100644 --- a/PromisePayDotNet/DTO/ItemStatus.cs +++ b/PromisePayDotNet/DTO/ItemStatus.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class ItemStatus { diff --git a/PromisePayDotNet/DTO/Marketplace.cs b/PromisePayDotNet/DTO/Marketplace.cs index 6721881..d2ca159 100644 --- a/PromisePayDotNet/DTO/Marketplace.cs +++ b/PromisePayDotNet/DTO/Marketplace.cs @@ -1,4 +1,4 @@ -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Marketplace { diff --git a/PromisePayDotNet/DTO/PayPal.cs b/PromisePayDotNet/DTO/PayPal.cs index 095d147..dca62a0 100644 --- a/PromisePayDotNet/DTO/PayPal.cs +++ b/PromisePayDotNet/DTO/PayPal.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class PayPal { diff --git a/PromisePayDotNet/DTO/PayPalAccount.cs b/PromisePayDotNet/DTO/PayPalAccount.cs index ef29c61..e226c4f 100644 --- a/PromisePayDotNet/DTO/PayPalAccount.cs +++ b/PromisePayDotNet/DTO/PayPalAccount.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class PayPalAccount : AbstractAccount { diff --git a/PromisePayDotNet/DTO/Token.cs b/PromisePayDotNet/DTO/Token.cs index 3cf0c16..b12ca63 100644 --- a/PromisePayDotNet/DTO/Token.cs +++ b/PromisePayDotNet/DTO/Token.cs @@ -1,9 +1,9 @@ using Newtonsoft.Json; using PromisePayDotNet.Enums; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { - public class Token + public class Token //NOTE: Why is this called token? { [JsonProperty(PropertyName = "current_user_id")] public string CurrentUserId { get; set; } diff --git a/PromisePayDotNet/DTO/Transaction.cs b/PromisePayDotNet/DTO/Transaction.cs index b1d969a..2b3d09b 100644 --- a/PromisePayDotNet/DTO/Transaction.cs +++ b/PromisePayDotNet/DTO/Transaction.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Transaction : AbstractDTO { diff --git a/PromisePayDotNet/DTO/Upload.cs b/PromisePayDotNet/DTO/Upload.cs index 9d7088c..dc2c1ab 100644 --- a/PromisePayDotNet/DTO/Upload.cs +++ b/PromisePayDotNet/DTO/Upload.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Upload : AbstractDTO { diff --git a/PromisePayDotNet/DTO/User.cs b/PromisePayDotNet/DTO/User.cs index 85ad7e7..78c5ed1 100644 --- a/PromisePayDotNet/DTO/User.cs +++ b/PromisePayDotNet/DTO/User.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class User : AbstractDTO { diff --git a/PromisePayDotNet/DTO/Widget.cs b/PromisePayDotNet/DTO/Widget.cs index d4694c0..594fac5 100644 --- a/PromisePayDotNet/DTO/Widget.cs +++ b/PromisePayDotNet/DTO/Widget.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class Widget { diff --git a/PromisePayDotNet/DTO/WireDetails.cs b/PromisePayDotNet/DTO/WireDetails.cs index 6bab9c6..352c25b 100644 --- a/PromisePayDotNet/DTO/WireDetails.cs +++ b/PromisePayDotNet/DTO/WireDetails.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PromisePayDotNet.DTO +namespace PromisePayDotNet.Dto { public class WireDetails { @@ -39,5 +39,8 @@ public class WireDetails [JsonProperty(PropertyName = "currency")] public string Currency { get; set; } + + [JsonProperty(PropertyName = "country")] + public string Country { get; set; } } } diff --git a/PromisePayDotNet/Dynamic.Implementations/AddressRepository.cs b/PromisePayDotNet/Dynamic.Implementations/AddressRepository.cs deleted file mode 100644 index 3e0fa70..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/AddressRepository.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class AddressRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IAddressRepository - { - public AddressRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IDictionary GetAddressById(string addressId) - { - AssertIdNotNull(addressId); - var request = new RestRequest("/addresses/{id}", Method.GET); - request.AddUrlSegment("id", addressId); - var response = SendRequest(Client, request); - var address = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(address)); - } - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/BankAccountRepository.cs b/PromisePayDotNet/Dynamic.Implementations/BankAccountRepository.cs deleted file mode 100644 index 65b2b22..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/BankAccountRepository.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class BankAccountRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IBankAccountRepository - { - public BankAccountRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IDictionary GetBankAccountById(string bankAccountId) - { - AssertIdNotNull(bankAccountId); - var request = new RestRequest("/bank_accounts/{id}", Method.GET); - request.AddUrlSegment("id", bankAccountId); - var response = SendRequest(Client, request); - var first = JsonConvert.DeserializeObject>(response.Content).Values.First(); - var firstJson = JsonConvert.SerializeObject(first); - return JsonConvert.DeserializeObject>(firstJson); - } - - public IDictionary CreateBankAccount(IDictionary bankAccount) - { - var request = new RestRequest("/bank_accounts", Method.POST); - request.AddParameter("user_id", (string)bankAccount["user_id"]); - var bank = (IDictionary)(bankAccount["bank"]); - - foreach (var key in bank.Keys) { - request.AddParameter(key, (string)bank[key]); - } - - var response = SendRequest(Client, request); - return JsonConvert.DeserializeObject>>(response.Content).Values.First(); - } - - public bool DeleteBankAccount(string bankAccountId) - { - AssertIdNotNull(bankAccountId); - var request = new RestRequest("/bank_accounts/{id}", Method.DELETE); - request.AddUrlSegment("id", bankAccountId); - var response = SendRequest(Client, request); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - return true; - } - - public IDictionary GetUserForBankAccount(string bankAccountId) - { - AssertIdNotNull(bankAccountId); - var request = new RestRequest("/bank_accounts/{id}/users", Method.GET); - request.AddUrlSegment("id", bankAccountId); - IRestResponse response = SendRequest(Client, request); - - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var item = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(item)); - } - return null; - } - } - -} diff --git a/PromisePayDotNet/Dynamic.Implementations/CardAccountRepository.cs b/PromisePayDotNet/Dynamic.Implementations/CardAccountRepository.cs deleted file mode 100644 index 8f593fa..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/CardAccountRepository.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class CardAccountRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.ICardAccountRepository - { - public CardAccountRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IDictionary GetCardAccountById(string cardAccountId) - { - AssertIdNotNull(cardAccountId); - var request = new RestRequest("/card_accounts/{id}", Method.GET); - request.AddUrlSegment("id", cardAccountId); - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public IDictionary CreateCardAccount(IDictionary cardAccount) - { - var request = new RestRequest("/card_accounts", Method.POST); - request.AddParameter("user_id", (string)cardAccount["user_id"]); - - var card = (IDictionary)(cardAccount["card"]); - - foreach (var key in card.Keys) { - request.AddParameter(key, (string)card[key]); - } - - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public bool DeleteCardAccount(string cardAccountId) - { - AssertIdNotNull(cardAccountId); - var request = new RestRequest("/card_accounts/{id}", Method.DELETE); - request.AddUrlSegment("id", cardAccountId); - var response = SendRequest(Client, request); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - return true; - } - - public IDictionary GetUserForCardAccount(string cardAccountId) - { - AssertIdNotNull(cardAccountId); - var request = new RestRequest("/card_accounts/{id}/users", Method.GET); - request.AddUrlSegment("id", cardAccountId); - IRestResponse response = SendRequest(Client, request); - - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var item = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(item)); - } - return null; - } - - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/CompanyRepository.cs b/PromisePayDotNet/Dynamic.Implementations/CompanyRepository.cs deleted file mode 100644 index f2d1929..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/CompanyRepository.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class CompanyRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.ICompanyRepository - { - public CompanyRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable> ListCompanies() - { - var request = new RestRequest("/companies", Method.GET); - - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("companies")) - { - var uploadCollection = dict["companies"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(uploadCollection)); - } - return new List>(); - } - - public IDictionary GetCompanyById(string companyId) - { - AssertIdNotNull(companyId); - var request = new RestRequest("/companies/{id}", Method.GET); - request.AddUrlSegment("id", companyId); - var response = SendRequest(Client, request); - var company = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(company)); - } - - public IDictionary CreateCompany(IDictionary company) - { - var request = new RestRequest("/companies", Method.POST); - - foreach (var key in company.Keys) { - request.AddParameter(key, (string)company[key]); - } - var response = SendRequest(Client, request); - var returnedCompany = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedCompany)); - } - - public IDictionary EditCompany(IDictionary company) - { - var request = new RestRequest("/companies", Method.POST); - - foreach (var key in company.Keys) { - request.AddParameter(key, (string)company[key]); - } - - var response = SendRequest(Client, request); - var returnedCompany = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedCompany)); - } - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/FeeRepository.cs b/PromisePayDotNet/Dynamic.Implementations/FeeRepository.cs deleted file mode 100644 index ab8b86f..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/FeeRepository.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Newtonsoft.Json; -using PromisePayDotNet.Exceptions; -using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class FeeRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IFeeRepository - { - public FeeRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable> ListFees() - { - var request = new RestRequest("/fees", Method.GET); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("fees")) - { - var userCollection = dict["fees"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(userCollection)); - } - return new List>(); - } - - public IDictionary GetFeeById(string feeId) - { - AssertIdNotNull(feeId); - var request = new RestRequest("/fees/{id}", Method.GET); - request.AddUrlSegment("id", feeId); - var response = SendRequest(Client, request); - var fee = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(fee)); - } - - public IDictionary CreateFee(IDictionary fee) - { - VailidateFee(fee); - var request = new RestRequest("/fees", Method.POST); - - foreach (var key in fee.Keys) { - request.AddParameter(key, (string)fee[key]); - } - - var response = SendRequest(Client, request); - var returnedFee = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedFee)); - } - - private void VailidateFee(IDictionary fee) - { - if (fee == null) throw new ArgumentNullException("fee"); - if (!_possibleTos.Contains((string)fee["to"])) - { - throw new ValidationException( - "To should have value of \"buyer\", \"seller\", \"cc\", \"int_wire\", \"paypal_payout\""); - } - } - - private readonly List _possibleTos = new List { "buyer", "seller", "cc", "int_wire", "paypal_payout" }; - - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/ItemRepository.cs b/PromisePayDotNet/Dynamic.Implementations/ItemRepository.cs deleted file mode 100644 index 78b509d..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/ItemRepository.cs +++ /dev/null @@ -1,377 +0,0 @@ -using Newtonsoft.Json; -using PromisePayDotNet.Exceptions; -using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class ItemRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IItemRepository - { - public ItemRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable> ListItems(int limit = 10, int offset = 0) - { - AssertListParamsCorrect(limit, offset); - var request = new RestRequest("/items", Method.GET); - request.AddParameter("limit", limit); - request.AddParameter("offset", offset); - - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var userCollection = dict["items"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(userCollection)); - } - return new List>(); - } - - public IDictionary GetItemById(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}", Method.GET); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public IDictionary CreateItem(IDictionary item) - { - var request = new RestRequest("/items", Method.POST); - - foreach (var key in item.Keys) { - request.AddParameter(key, item[key]); - } - - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public bool DeleteItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}", Method.DELETE); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - return true; - } - - public IDictionary UpdateItem(IDictionary item) - { - var request = new RestRequest("/items/{id}", Method.PATCH); - request.AddUrlSegment("id", (string)item["id"]); - - foreach (var key in item.Keys) - { - request.AddParameter(key, item[key]); - } - - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - - } - - public IEnumerable> ListTransactionsForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/transactions", Method.GET); - request.AddUrlSegment("id", itemId); - IRestResponse response; - try - { - response = SendRequest(Client, request); - } - catch (ApiErrorsException e) - { - if (e.Errors.Count == 1 && e.Errors.Values.First().First() == "no transaction found") - { - return new List>(); - } - throw; - } - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("transactions")) - { - var itemCollection = dict["transactions"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(itemCollection)); - } - return new List>(); - } - - public IDictionary GetStatusForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/status", Method.GET); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IEnumerable> ListFeesForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/fees", Method.GET); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("fees")) - { - var itemCollection = dict["fees"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(itemCollection)); - } - return new List>(); - } - - public IDictionary GetBuyerForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/buyers", Method.GET); - request.AddUrlSegment("id", itemId); - IRestResponse response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var itemCollection = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary GetSellerForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/sellers", Method.GET); - request.AddUrlSegment("id", itemId); - IRestResponse response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var itemCollection = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary GetWireDetailsForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/wire_details", Method.GET); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var details = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(details["wire_details"])); - } - return null; - } - - public IDictionary GetBPayDetailsForItem(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/{id}/bpay_details", Method.GET); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var details = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(details["bpay_details"])); - } - return null; - } - - public IDictionary MakePayment(string itemId, string accountId) - { - AssertIdNotNull(itemId); - AssertIdNotNull(accountId); - var request = new RestRequest("/items/:id/make_payment", Method.PATCH); - request.AddUrlSegment("id", itemId); - request.AddParameter("account_id", accountId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary RequestPayment(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/request_payment", Method.PATCH); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary ReleasePayment(string itemId, int releaseAmount) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/release_payment", Method.PATCH); - request.AddUrlSegment("id", itemId); - request.AddParameter("release_amount", releaseAmount); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary RequestRelease(string itemId, int releaseAmount) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/request_release", Method.PATCH); - request.AddUrlSegment("id", itemId); - request.AddParameter("release_amount", releaseAmount); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary Cancel(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/cancel", Method.PATCH); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary AcknowledgeWire(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/acknowledge_wire", Method.PATCH); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary AcknowledgePayPal(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/acknowledge_paypal", Method.PATCH); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary RevertWire(string itemId) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/revert_wire", Method.PATCH); - request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary RequestRefund(string itemId, string refundAmount, string refundMessage) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/request_refund", Method.PATCH); - request.AddUrlSegment("id", itemId); - request.AddParameter("refund_amount", refundAmount); - request.AddParameter("refund_message", refundMessage); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - - public IDictionary Refund(string itemId, string refundAmount, string refundMessage) - { - AssertIdNotNull(itemId); - var request = new RestRequest("/items/:id/refund", Method.PATCH); - request.AddUrlSegment("id", itemId); - request.AddParameter("refund_amount", refundAmount); - request.AddParameter("refund_message", refundMessage); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - var item = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - return item; - } - return null; - } - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/PayPalAccountRepository.cs b/PromisePayDotNet/Dynamic.Implementations/PayPalAccountRepository.cs deleted file mode 100644 index dd7b393..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/PayPalAccountRepository.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class PayPalAccountRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IPayPalAccountRepository - { - public PayPalAccountRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IDictionary GetPayPalAccountById(string paypalAccountId) - { - AssertIdNotNull(paypalAccountId); - var request = new RestRequest("/paypal_accounts/{id}", Method.GET); - request.AddUrlSegment("id", paypalAccountId); - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public IDictionary CreatePayPalAccount(IDictionary paypalAccount) - { - var request = new RestRequest("/paypal_accounts", Method.POST); - request.AddParameter("user_id", (string)paypalAccount["user_id"]); - var paypal = (IDictionary)(paypalAccount["paypal"]); - - foreach (var key in paypal.Keys) { - request.AddParameter(key, paypal[key]); - } - - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public bool DeletePayPalAccount(string paypalAccountId) - { - AssertIdNotNull(paypalAccountId); - var request = new RestRequest("/paypal_accounts/{id}", Method.DELETE); - request.AddUrlSegment("id", paypalAccountId); - var response = SendRequest(Client, request); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - return true; - } - - public IDictionary GetUserForPayPalAccount(string paypalAccountId) - { - AssertIdNotNull(paypalAccountId); - var request = new RestRequest("/paypal_accounts/{id}/users", Method.GET); - request.AddUrlSegment("id", paypalAccountId); - var response = SendRequest(Client, request); - - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var item = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(item)); - } - return null; - } - - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/TokenRepository.cs b/PromisePayDotNet/Dynamic.Implementations/TokenRepository.cs deleted file mode 100644 index a789d08..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/TokenRepository.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class TokenRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.ITokenRepository - { - public TokenRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public string RequestToken() - { - var request = new RestRequest("/request_token", Method.GET); - var response = SendRequest(Client, request); - return JsonConvert.DeserializeObject>(response.Content).Values.First(); - } - - public IDictionary RequestSessionToken(IDictionary token) - { - var request = new RestRequest("/request_session_token", Method.GET); - - foreach (var key in token.Keys) { - request.AddParameter(key, token[key]); - } - - var response = SendRequest(Client, request); - return JsonConvert.DeserializeObject>(response.Content); - } - - public IDictionary GetWidget(string sessionToken) - { - var request = new RestRequest("/widget", Method.GET); - request.AddParameter("session_token", sessionToken); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("widget")) - { - var itemCollection = dict["widget"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary GenerateCardToken(string tokenType, string userId) - { - var request = new RestRequest("/token_auths", Method.POST); - request.AddParameter("token_type", tokenType); - request.AddParameter("user_id", userId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("token_auth")) - { - var itemCollection = dict["token_auth"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/TransactionRepository.cs b/PromisePayDotNet/Dynamic.Implementations/TransactionRepository.cs deleted file mode 100644 index fa45e35..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/TransactionRepository.cs +++ /dev/null @@ -1,77 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System.Collections.Generic; -using System.Linq; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class TransactionRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.ITransactionRepository - { - public TransactionRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable> ListTransactions(int limit = 10, int offset = 0) - { - AssertListParamsCorrect(limit, offset); - - var request = new RestRequest("/transactions", Method.GET); - request.AddParameter("limit", limit); - request.AddParameter("offset", offset); - - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("transactions")) - { - var transactionCollection = dict["transactions"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(transactionCollection)); - } - return new List>(); - } - - public IDictionary GetTransaction(string transactionId) - { - AssertIdNotNull(transactionId); - var request = new RestRequest("/transactions/{id}", Method.GET); - request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public IDictionary GetUserForTransaction(string transactionId) - { - AssertIdNotNull(transactionId); - var request = new RestRequest("/transactions/{id}/users", Method.GET); - request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var itemCollection = dict["users"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary GetFeeForTransaction(string transactionId) - { - AssertIdNotNull(transactionId); - var request = new RestRequest("/transactions/{id}/fees", Method.GET); - request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("fees")) - { - var itemCollection = dict["fees"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/UploadRepository.cs b/PromisePayDotNet/Dynamic.Implementations/UploadRepository.cs deleted file mode 100644 index 36de605..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/UploadRepository.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Newtonsoft.Json; -using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class UploadRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IUploadRepository - { - public UploadRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IList> ListUploads() - { - var request = new RestRequest("/uploads", Method.GET); - - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("uploads")) - { - var uploadCollection = dict["uploads"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(uploadCollection)); - } - return new List>(); - } - - public IDictionary GetUploadById(string uploadId) - { - AssertIdNotNull(uploadId); - var request = new RestRequest("/uploads/{id}", Method.GET); - request.AddUrlSegment("id", uploadId); - var response = SendRequest(Client, request); - var result = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(result)); - } - - public IDictionary CreateUpload(string csvData) - { - if (String.IsNullOrEmpty(csvData)) - { - throw new ArgumentException("csvData cannot be empty"); - } - - var request = new RestRequest("/uploads", Method.POST); - request.AddParameter("import", csvData); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("uploads")) - { - var itemCollection = dict["uploads"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary GetStatus(string uploadId) - { - AssertIdNotNull(uploadId); - var request = new RestRequest("/uploads/{id}/import", Method.GET); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("uploads")) - { - var itemCollection = dict["uploads"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - public IDictionary StartImport(string uploadId) - { - AssertIdNotNull(uploadId); - var request = new RestRequest("/uploads/{id}/import", Method.PATCH); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("uploads")) - { - var itemCollection = dict["uploads"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return null; - } - - } -} diff --git a/PromisePayDotNet/Dynamic.Implementations/UserRepository.cs b/PromisePayDotNet/Dynamic.Implementations/UserRepository.cs deleted file mode 100644 index c36311f..0000000 --- a/PromisePayDotNet/Dynamic.Implementations/UserRepository.cs +++ /dev/null @@ -1,249 +0,0 @@ -using Newtonsoft.Json; -using PromisePayDotNet.Exceptions; -using RestSharp; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; - -namespace PromisePayDotNet.Dynamic.Implementations -{ - public class UserRepository : PromisePayDotNet.Implementations.AbstractRepository, - PromisePayDotNet.Dynamic.Interfaces.IUserRepository - { - public UserRepository(IRestClient client) - : base(client) - { - } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - #region public methods - - public IEnumerable> ListUsers(int limit = 10, int offset = 0) - { - AssertListParamsCorrect(limit, offset); - var request = new RestRequest("/users", Method.GET); - request.AddParameter("limit", limit); - request.AddParameter("offset", offset); - - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("users")) - { - var userCollection = dict["users"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(userCollection)); - } - return new List>(); - } - - public IDictionary GetUserById(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}", Method.GET); - request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); - var returnedUser = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedUser)); - } - - public IDictionary CreateUser(IDictionary user) - { - ValidateUser(user); - var request = new RestRequest("/users", Method.POST); - - foreach (var key in user.Keys) { - request.AddParameter(key, (string)user[key]); - } - - var response = SendRequest(Client, request); - var returnedUser = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedUser)); - } - - public bool DeleteUser(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}", Method.DELETE); - request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); - if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - return true; - } - - public IEnumerable> ListItemsForUser(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}/items", Method.GET); - request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("items")) - { - var itemCollection = dict["items"]; - return JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(itemCollection)); - } - return new List>(); - } - - public IDictionary GetPayPalAccountForUser(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}/paypal_accounts", Method.GET); - request.AddUrlSegment("id", userId); - IRestResponse response; - try - { - response = SendRequest(Client, request); - } - catch (ApiErrorsException e) - { - if (e.Errors.Count == 1 && e.Errors.Values.First().First() == "no account found") - { - return new Dictionary(); - } - throw; - } - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("paypal_accounts")) - { - var itemCollection = dict["paypal_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return new Dictionary(); - } - - public IDictionary GetCardAccountForUser(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}/card_accounts", Method.GET); - request.AddUrlSegment("id", userId); - IRestResponse response; - try - { - response = SendRequest(Client, request); - } - catch (ApiErrorsException e) - { - if (e.Errors.Count == 1 && e.Errors.Values.First().First() == "no account found") - { - return new Dictionary(); - } - throw; - } - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("card_accounts")) - { - var itemCollection = dict["card_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - return new Dictionary(); - } - - public IDictionary GetBankAccountForUser(string userId) - { - AssertIdNotNull(userId); - var request = new RestRequest("/users/{id}/bank_accounts", Method.GET); - request.AddUrlSegment("id", userId); - IRestResponse response; - try - { - response = SendRequest(Client, request); - } - catch (ApiErrorsException e) - { - if (e.Errors.Count == 1 && e.Errors.Values.First().First() == "no account found") - { - return new Dictionary(); - } - throw e; - } - var dict = JsonConvert.DeserializeObject>(response.Content); - if (dict.ContainsKey("bank_accounts")) - { - var itemCollection = dict["bank_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); - } - - return new Dictionary(); - } - - public bool SetDisbursementAccount(string userId, string accountId) - { - //ToDo find out DisbursementAccount fields and implement this method - throw new NotImplementedException(); - // AssertIdNotNull(userId); - // - // var request = new RestRequest("/users/{id}/disbursement_account", Method.POST); - // request.AddUrlSegment("id", userId); - // request.AddUrlSegment("account_id", accountId); - // try - // { - // SendRequest(Client, request); - // } - // catch (ApiErrorsException e) - // { - // throw; - // } - - } - - public IDictionary UpdateUser(IDictionary user) - { - ValidateUser(user); - var request = new RestRequest("/users/{id}", Method.PATCH); - request.AddUrlSegment("id", (string)user["id"]); - - foreach (var key in user.Keys) - { - request.AddParameter(key, (string)user[key]); - } - var response = SendRequest(Client, request); - var returnedUser = JsonConvert.DeserializeObject>(response.Content).Values.First(); - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(returnedUser)); - } - - #endregion - - #region private methods - - private void ValidateUser(IDictionary user) - { - if ((!user.ContainsKey("id")) || String.IsNullOrEmpty((string)user["id"])) - { - throw new ValidationException("Field User.ID should not be empty!"); - } - if ((!user.ContainsKey("first_name")) || String.IsNullOrEmpty((string)user["first_name"])) - { - throw new ValidationException("Field User.FirstName should not be empty!"); - } - if ((!user.ContainsKey("country")) || !IsCorrectCountryCode((string)user["country"])) - { - throw new ValidationException("Field User.Country should contain 3-letter ISO country code!"); - } - if ((!user.ContainsKey("email")) || !IsCorrectEmail((string)user["email"])) - { - throw new ValidationException("Field User.Email should contain correct email address!"); - } - } - - private bool IsCorrectEmail(string email) - { - try - { - var addr = new System.Net.Mail.MailAddress(email); - return addr.Address == email; - } - catch - { - return false; - } - } - - #endregion - - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IAddressRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IAddressRepository.cs deleted file mode 100644 index e7a9059..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IAddressRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IAddressRepository - { - IDictionary GetAddressById(string addressId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IBankAccountRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IBankAccountRepository.cs deleted file mode 100644 index 6fde988..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IBankAccountRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IBankAccountRepository - { - IDictionary GetBankAccountById(string bankAccountId); - - IDictionary CreateBankAccount(IDictionary bankAccount); - - bool DeleteBankAccount(string bankAccountId); - - IDictionary GetUserForBankAccount(string bankAccountId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/ICardAccountRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/ICardAccountRepository.cs deleted file mode 100644 index 3bb2e42..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/ICardAccountRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface ICardAccountRepository - { - IDictionary GetCardAccountById(string cardAccountId); - - IDictionary CreateCardAccount(IDictionary cardAccount); - - bool DeleteCardAccount(string cardAccountId); - - IDictionary GetUserForCardAccount(string cardAccountId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/ICompanyRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/ICompanyRepository.cs deleted file mode 100644 index 4f4bace..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/ICompanyRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface ICompanyRepository - { - IEnumerable> ListCompanies(); - - IDictionary GetCompanyById(string companyId); - - IDictionary CreateCompany(IDictionary company); - - IDictionary EditCompany(IDictionary company); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IFeeRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IFeeRepository.cs deleted file mode 100644 index 9e5f99b..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IFeeRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IFeeRepository - { - - IEnumerable> ListFees(); - - IDictionary GetFeeById(string feeId); - - IDictionary CreateFee(IDictionary fee); - - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IItemRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IItemRepository.cs deleted file mode 100644 index 93837e6..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IItemRepository.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IItemRepository - { - - IEnumerable> ListItems(int limit = 10, int offset = 0); - - IDictionary GetItemById(string itemId); - - IDictionary CreateItem(IDictionary item); - - bool DeleteItem(string itemId); - - IDictionary UpdateItem(IDictionary item); - - IEnumerable> ListTransactionsForItem(string itemId); - - IDictionary GetStatusForItem(string itemId); - - IEnumerable> ListFeesForItem(string itemId); - - IDictionary GetBuyerForItem(string itemId); - - IDictionary GetSellerForItem(string itemId); - - IDictionary GetWireDetailsForItem(string itemId); - - IDictionary GetBPayDetailsForItem(string itemId); - - //actions methods start here - - IDictionary MakePayment(string itemId, string accountId); - - IDictionary RequestPayment(string itemId); - - IDictionary ReleasePayment(string itemId, int releaseAmount); - - IDictionary RequestRelease(string itemId, int releaseAmount); - - IDictionary Cancel(string itemId); - - IDictionary AcknowledgeWire(string itemId); - - IDictionary AcknowledgePayPal(string itemId); - - IDictionary RevertWire(string itemId); - - IDictionary RequestRefund(string itemId, string refundAmount, string refundMessage); - - IDictionary Refund(string itemId, string refundAmount, string refundMessage); - - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IPayPalAccountRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IPayPalAccountRepository.cs deleted file mode 100644 index 5c4000a..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IPayPalAccountRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IPayPalAccountRepository - { - IDictionary GetPayPalAccountById(string paypalAccountId); - - IDictionary CreatePayPalAccount(IDictionary paypalAccount); - - bool DeletePayPalAccount(string paypalAccountId); - - IDictionary GetUserForPayPalAccount(string paypalAccountId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/ITokenRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/ITokenRepository.cs deleted file mode 100644 index 2ea44e0..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/ITokenRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface ITokenRepository - { - string RequestToken(); - - IDictionary RequestSessionToken(IDictionary token); - - IDictionary GetWidget(string sessionToken); - - IDictionary GenerateCardToken(string tokenType, string userId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/ITransactionRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/ITransactionRepository.cs deleted file mode 100644 index f1419c9..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/ITransactionRepository.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface ITransactionRepository - { - IEnumerable> ListTransactions(int limit = 10, int offset = 0); - - IDictionary GetTransaction(string transactionId); - - IDictionary GetUserForTransaction(string transactionId); - - IDictionary GetFeeForTransaction(string transactionId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IUploadRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IUploadRepository.cs deleted file mode 100644 index f03491e..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IUploadRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IUploadRepository - { - IList> ListUploads(); - - IDictionary GetUploadById(string uploadId); - - IDictionary CreateUpload(string csvData); - - IDictionary GetStatus(string uploadId); - - IDictionary StartImport(string uploadId); - } -} diff --git a/PromisePayDotNet/Dynamic.Interfaces/IUserRepository.cs b/PromisePayDotNet/Dynamic.Interfaces/IUserRepository.cs deleted file mode 100644 index 1dbd96d..0000000 --- a/PromisePayDotNet/Dynamic.Interfaces/IUserRepository.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; - -namespace PromisePayDotNet.Dynamic.Interfaces -{ - public interface IUserRepository - { - IEnumerable> ListUsers(int limit = 10, int offset = 0); - - IDictionary GetUserById(string userId); - - IDictionary CreateUser(IDictionary user); - - IDictionary UpdateUser(IDictionary user); - - bool DeleteUser(string userId); - - IEnumerable> ListItemsForUser(string userId); - - IDictionary GetPayPalAccountForUser(string userId); - - IDictionary GetCardAccountForUser(string userId); - - IDictionary GetBankAccountForUser(string userId); - - bool SetDisbursementAccount(string userId, string accountId); - } -} diff --git a/PromisePayDotNet/Enums/FeeToType.cs b/PromisePayDotNet/Enums/FeeToType.cs new file mode 100644 index 0000000..55e10fa --- /dev/null +++ b/PromisePayDotNet/Enums/FeeToType.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; +using PromisePayDotNet.Internals; + +namespace PromisePayDotNet.Enums +{ + /// + /// Who pays the fee (buyer, seller, cc, int_wire) + /// + [JsonConverter(typeof(FeeToJsonConverter))] + public enum FeeToType + { + /// + /// Default value + /// + None, + /// + /// The fee is paid by the buyer + /// + Buyer, + /// + /// The fee is paid by the seller + /// + Seller, + CC, + IntWire, + PaypalPayout // + } +} \ No newline at end of file diff --git a/PromisePayDotNet/Enums/FeeType.cs b/PromisePayDotNet/Enums/FeeType.cs index 0a4bf09..e6982e7 100644 --- a/PromisePayDotNet/Enums/FeeType.cs +++ b/PromisePayDotNet/Enums/FeeType.cs @@ -1,14 +1,25 @@ namespace PromisePayDotNet.Enums { + /// + /// Fee type. + /// public enum FeeType { - + /// + /// Fixed fee type == 1. + /// Fixed = 1, - + /// + /// Percentage type == 2. + /// Percentage = 2, - + /// + /// Percentage with cap == 3. + /// PercentageWithCap = 3, - + /// + /// Percentage with minimum == 4. + /// PercentageWithMin = 4 } } diff --git a/PromisePayDotNet/Implementations/AbstractRepository.cs b/PromisePayDotNet/Implementations/AbstractRepository.cs index 5cd92be..6472436 100644 --- a/PromisePayDotNet/Implementations/AbstractRepository.cs +++ b/PromisePayDotNet/Implementations/AbstractRepository.cs @@ -1,53 +1,44 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; -using RestSharp; -using RestSharp.Authenticators; +using PromisePayDotNet.Settings; +using PromisePayDotNet.Internals; using System; -using System.Collections; using System.Collections.Generic; -using System.Configuration; using System.Net; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class AbstractRepository + internal abstract class AbstractRepository { - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + protected readonly ILogger log; protected const int EntityListLimit = 200; protected IRestClient Client; - - public AbstractRepository(IRestClient client) + public AbstractRepository(IRestClient client, ILogger logger, IOptions options) { + Configurataion = options.Value; + if (options.Value == null) throw new NullReferenceException(nameof(options.Value)); + log = logger; this.Client = client; client.BaseUrl = new Uri(BaseUrl); client.Authenticator = new HttpBasicAuthenticator(Login, Password); } - protected Hashtable Configurataion - { - get - { - var ht = ConfigurationManager.GetSection("PromisePay/Settings") as Hashtable; - if (ht == null) - { - log.Fatal("Unable to get PromisePay settings section from config file"); - throw new MisconfigurationException("Unable to get PromisePay settings section from config file"); - } - return ht; - } - } - + protected PromisePaySettings Configurataion { get; } + protected string BaseUrl { get { - var baseUrl = Configurataion["ApiUrl"] as String; + var baseUrl = Configurataion.ApiUrl; if (baseUrl == null) { - log.Fatal("Unable to get URL info from config file"); + log.LogError("Unable to get URL info from config file"); throw new MisconfigurationException("Unable to get URL info from config file"); } return baseUrl; @@ -58,10 +49,10 @@ protected string Login { get { - var baseUrl = Configurataion["Login"] as String; + var baseUrl = Configurataion.Login; if (baseUrl == null) { - log.Fatal("Unable to get Login info from config file"); + log.LogError("Unable to get Login info from config file"); throw new MisconfigurationException("Unable to get Login info from config file"); } return baseUrl; @@ -73,40 +64,45 @@ public string Password { get { - var baseUrl = Configurataion["Password"] as String; + var baseUrl = Configurataion.Password; if (baseUrl == null) { - log.Fatal("Unable to get Password info from config file"); + log.LogError("Unable to get Password info from config file"); throw new MisconfigurationException("Unable to get Password info from config file"); } return baseUrl; } } + [Obsolete("Use async!")] + protected RestResponse SendRequest(IRestClient client, RestRequest request) + { + return SendRequestAsync(client, request).WrapResult(); + } - protected IRestResponse SendRequest(IRestClient client, IRestRequest request) + protected async Task SendRequestAsync(IRestClient client, RestRequest request) { - var response = client.Execute(request); + var response = await client.ExecuteAsync(request); - log.Debug(String.Format( + log.LogDebug(String.Format( "Executed request to {0} with method {1}, got the following status: {2} and the body is {3}", response.ResponseUri, request.Method, response.StatusDescription, response.Content)); if (response.StatusCode == HttpStatusCode.Unauthorized) { - log.Error("Your login/password are unknown to server"); + log.LogError("Your login/password are unknown to server"); throw new UnauthorizedException("Your login/password are unknown to server"); } if (((int)response.StatusCode) == 422) { var errors = JsonConvert.DeserializeObject(response.Content).Errors; - log.Error(String.Format("API returned following errors: {0}", JsonConvert.SerializeObject(errors))); + log.LogError(String.Format("API returned following errors: {0}", JsonConvert.SerializeObject(errors))); throw new ApiErrorsException("API returned errors, see Errors property", errors); } if (response.StatusCode == HttpStatusCode.BadRequest) { var message = JsonConvert.DeserializeObject>(response.Content)["message"]; - log.Error(String.Format("Bad request: {0}", message)); + log.LogError(String.Format("Bad request: {0}", message)); throw new ApiErrorsException(message, null); } return response; @@ -116,7 +112,7 @@ protected void AssertIdNotNull(string itemId) { if (string.IsNullOrEmpty(itemId)) { - log.Error("id cannot be empty!"); + log.LogError("id cannot be empty!"); throw new ArgumentException("id cannot be empty!"); } } @@ -125,14 +121,14 @@ protected void AssertListParamsCorrect(int limit, int offset) { if (limit < 0 || offset < 0) { - log.Error("limit and offset values should be nonnegative!"); + log.LogError("limit and offset values should be nonnegative!"); throw new ArgumentException("limit and offset values should be nonnegative!"); } if (limit > EntityListLimit) { var message = String.Format("Max value for limit parameter is {0}!", EntityListLimit); - log.Error(message); + log.LogError(message); throw new ArgumentException(message); } } diff --git a/PromisePayDotNet/Implementations/AddressRepository.cs b/PromisePayDotNet/Implementations/AddressRepository.cs index b172f73..64520ad 100644 --- a/PromisePayDotNet/Implementations/AddressRepository.cs +++ b/PromisePayDotNet/Implementations/AddressRepository.cs @@ -1,26 +1,28 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class AddressRepository : AbstractRepository, IAddressRepository + internal class AddressRepository : AbstractRepository, IAddressRepository { - public AddressRepository(IRestClient client) : base(client) + public AddressRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public Address GetAddressById(string addressId) + public async Task
GetAddressByIdAsync(string addressId) { AssertIdNotNull(addressId); var request = new RestRequest("/addresses/{id}", Method.GET); request.AddUrlSegment("id", addressId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } } diff --git a/PromisePayDotNet/Implementations/BankAccountRepository.cs b/PromisePayDotNet/Implementations/BankAccountRepository.cs index 3f1ac2a..81c53d4 100644 --- a/PromisePayDotNet/Implementations/BankAccountRepository.cs +++ b/PromisePayDotNet/Implementations/BankAccountRepository.cs @@ -1,31 +1,34 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; using System.Net; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class BankAccountRepository : AbstractRepository, IBankAccountRepository + internal class BankAccountRepository : AbstractRepository, IBankAccountRepository { - public BankAccountRepository(IRestClient client) : base(client) + public BankAccountRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public BankAccount GetBankAccountById(string bankAccountId) + public async Task GetBankAccountByIdAsync(string bankAccountId) { AssertIdNotNull(bankAccountId); - var request = new RestRequest("/bank_accounts/{id}", Method.GET); + var request = new + RestRequest("/bank_accounts/{id}", Method.GET); request.AddUrlSegment("id", bankAccountId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public BankAccount CreateBankAccount(BankAccount bankAccount) + public async Task CreateBankAccountAsync(BankAccount bankAccount) { var request = new RestRequest("/bank_accounts", Method.POST); request.AddParameter("user_id", bankAccount.UserId); @@ -37,16 +40,16 @@ public BankAccount CreateBankAccount(BankAccount bankAccount) request.AddParameter("holder_type", bankAccount.Bank.HolderType); request.AddParameter("country", bankAccount.Bank.Country); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public bool DeleteBankAccount(string bankAccountId) + public async Task DeleteBankAccountAsync(string bankAccountId) { AssertIdNotNull(bankAccountId); var request = new RestRequest("/bank_accounts/{id}", Method.DELETE); request.AddUrlSegment("id", bankAccountId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); if (response.StatusCode == HttpStatusCode.NotFound) { return false; @@ -54,12 +57,12 @@ public bool DeleteBankAccount(string bankAccountId) return true; } - public User GetUserForBankAccount(string bankAccountId) + public async Task GetUserForBankAccountAsync(string bankAccountId) { AssertIdNotNull(bankAccountId); var request = new RestRequest("/bank_accounts/{id}/users", Method.GET); request.AddUrlSegment("id", bankAccountId); - IRestResponse response = SendRequest(Client, request); + RestResponse response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) diff --git a/PromisePayDotNet/Implementations/CardAccountRepository.cs b/PromisePayDotNet/Implementations/CardAccountRepository.cs index 018fbfc..17143ad 100644 --- a/PromisePayDotNet/Implementations/CardAccountRepository.cs +++ b/PromisePayDotNet/Implementations/CardAccountRepository.cs @@ -1,21 +1,21 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; using System.Net; +using Microsoft.Extensions.Options; namespace PromisePayDotNet.Implementations { - public class CardAccountRepository : AbstractRepository, ICardAccountRepository + internal class CardAccountRepository : AbstractRepository, ICardAccountRepository { - public CardAccountRepository(IRestClient client) : base(client) + public CardAccountRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public CardAccount GetCardAccountById(string cardAccountId) { AssertIdNotNull(cardAccountId); @@ -57,7 +57,7 @@ public User GetUserForCardAccount(string cardAccountId) AssertIdNotNull(cardAccountId); var request = new RestRequest("/card_accounts/{id}/users", Method.GET); request.AddUrlSegment("id", cardAccountId); - IRestResponse response = SendRequest(Client, request); + RestResponse response = SendRequest(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) diff --git a/PromisePayDotNet/Implementations/CompanyRepository.cs b/PromisePayDotNet/Implementations/CompanyRepository.cs index d2540b2..97f785b 100644 --- a/PromisePayDotNet/Implementations/CompanyRepository.cs +++ b/PromisePayDotNet/Implementations/CompanyRepository.cs @@ -1,21 +1,23 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; + namespace PromisePayDotNet.Implementations { - public class CompanyRepository : AbstractRepository, ICompanyRepository + internal class CompanyRepository : AbstractRepository, ICompanyRepository { - public CompanyRepository(IRestClient client) : base(client) + public CompanyRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public IEnumerable ListCompanies() { var request = new RestRequest("/companies", Method.GET); diff --git a/PromisePayDotNet/Implementations/FeeRepository.cs b/PromisePayDotNet/Implementations/FeeRepository.cs index 1c9e0af..01cb0b2 100644 --- a/PromisePayDotNet/Implementations/FeeRepository.cs +++ b/PromisePayDotNet/Implementations/FeeRepository.cs @@ -1,26 +1,29 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; +using PromisePayDotNet.Enums; namespace PromisePayDotNet.Implementations { - public class FeeRepository : AbstractRepository, IFeeRepository + internal class FeeRepository : AbstractRepository, IFeeRepository { - public FeeRepository(IRestClient client) : base(client) + public FeeRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable ListFees() + public async Task> ListFeesAsync() { var request = new RestRequest("/fees", Method.GET); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("fees")) { @@ -30,41 +33,68 @@ public IEnumerable ListFees() return new List(); } - public Fee GetFeeById(string feeId) + public async Task GetFeeByIdAsync(string feeId) { AssertIdNotNull(feeId); var request = new RestRequest("/fees/{id}", Method.GET); request.AddUrlSegment("id", feeId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public Fee CreateFee(Fee fee) + class CreateFeeRequest + { + [JsonProperty(PropertyName = "name")] + public string Name { get; set; } + + [JsonProperty(PropertyName = "fee_type_id")] + public int FeeType { get; set; } + + [JsonProperty(PropertyName = "amount")] + public int Amount { get; set; } + + [JsonProperty(PropertyName = "cap")] + public string Cap { get; set; } + + [JsonProperty(PropertyName = "min")] + public string Min { get; set; } + + [JsonProperty(PropertyName = "max")] + public string Max { get; set; } + + [JsonProperty(PropertyName = "to")] + public FeeToType To { get; set; } + } + + public async Task CreateFeeAsync(Fee fee) { VailidateFee(fee); - var request = new RestRequest("/fees", Method.POST); - request.AddParameter("name", fee.Name); - request.AddParameter("fee_type_id", (int)fee.FeeType); - request.AddParameter("amount", fee.Amount); - request.AddParameter("cap", fee.Cap); - request.AddParameter("min", fee.Min); - request.AddParameter("max", fee.Max); - request.AddParameter("to", fee.To); + var request = new RestRequest("/fees", Method.POST, new CreateFeeRequest { + Name = fee.Name, + Amount = fee.Amount, + Cap = fee.Cap, + FeeType = (int)fee.FeeType, + Max =fee.Max, + Min = fee.Min, + To = fee.To + }); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } private void VailidateFee(Fee fee) { - if (fee == null) throw new ArgumentNullException("fee"); + if (fee == null) throw new ArgumentNullException(nameof(fee)); if (!_possibleTos.Contains(fee.To)) { throw new ValidationException( - "To should have value of \"buyer\", \"seller\", \"cc\", \"int_wire\", \"paypal_payout\""); + "To should have value of "+string.Join(", ", _possibleTos.Select(to=> $"\"{FeeToJsonConverter.ToString(to)}\""))); } } - private readonly List _possibleTos = new List {"buyer", "seller", "cc", "int_wire", "paypal_payout"}; + private readonly List _possibleTos = new List { + FeeToType.Buyer, FeeToType.Seller, FeeToType.CC, FeeToType.IntWire, FeeToType.PaypalPayout + }; } } diff --git a/PromisePayDotNet/Implementations/ItemRepository.cs b/PromisePayDotNet/Implementations/ItemRepository.cs index b8e46c8..ce32525 100644 --- a/PromisePayDotNet/Implementations/ItemRepository.cs +++ b/PromisePayDotNet/Implementations/ItemRepository.cs @@ -1,30 +1,33 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; using System.Net; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class ItemRepository : AbstractRepository, IItemRepository + internal class ItemRepository : AbstractRepository, IItemRepository { - public ItemRepository(IRestClient client) : base(client) + public ItemRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public IEnumerable ListItems(int limit = 10, int offset = 0) + public async Task> ListItemsAsync(int limit = 10, int offset = 0) { AssertListParamsCorrect(limit, offset); var request = new RestRequest("/items", Method.GET); request.AddParameter("limit", limit); request.AddParameter("offset", offset); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -34,16 +37,16 @@ public IEnumerable ListItems(int limit = 10, int offset = 0) return new List(); } - public Item GetItemById(string itemId) + public async Task GetItemByIdAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}", Method.GET); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public Item CreateItem(Item item) + public async Task CreateItemAsync(Item item) { var request = new RestRequest("/items", Method.POST); request.AddParameter("id", item.Id); @@ -54,16 +57,16 @@ public Item CreateItem(Item item) request.AddParameter("seller_id", item.SellerId); request.AddParameter("fee_ids", item.FeeIds); request.AddParameter("description", item.Description); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public bool DeleteItem(string itemId) + public async Task DeleteItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}", Method.DELETE); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); if (response.StatusCode == HttpStatusCode.NotFound) { return false; @@ -71,7 +74,7 @@ public bool DeleteItem(string itemId) return true; } - public Item UpdateItem(Item item) + public async Task UpdateItemAsync(Item item) { var request = new RestRequest("/items/{id}", Method.PATCH); request.AddUrlSegment("id", item.Id); @@ -83,19 +86,19 @@ public Item UpdateItem(Item item) request.AddParameter("seller_id", item.SellerId); request.AddParameter("fee_ids", item.FeeIds); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public IEnumerable ListTransactionsForItem(string itemId) + public async Task> ListTransactionsForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/transactions", Method.GET); request.AddUrlSegment("id", itemId); - IRestResponse response; + RestResponse response; try { - response = SendRequest(Client, request); + response = await SendRequestAsync(Client, request); } catch (ApiErrorsException e) { @@ -114,12 +117,12 @@ public IEnumerable ListTransactionsForItem(string itemId) return new List(); } - public ItemStatus GetStatusForItem(string itemId) + public async Task GetStatusForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/status", Method.GET); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -129,12 +132,12 @@ public ItemStatus GetStatusForItem(string itemId) return null; } - public IEnumerable ListFeesForItem(string itemId) + public async Task> ListFeesForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/fees", Method.GET); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("fees")) { @@ -144,12 +147,12 @@ public IEnumerable ListFeesForItem(string itemId) return new List(); } - public User GetBuyerForItem(string itemId) + public async Task GetBuyerForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/buyers", Method.GET); request.AddUrlSegment("id", itemId); - IRestResponse response = SendRequest(Client, request); + RestResponse response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) { @@ -159,12 +162,12 @@ public User GetBuyerForItem(string itemId) return null; } - public User GetSellerForItem(string itemId) + public async Task GetSellerForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/sellers", Method.GET); request.AddUrlSegment("id", itemId); - IRestResponse response = SendRequest(Client, request); + RestResponse response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) { @@ -174,12 +177,12 @@ public User GetSellerForItem(string itemId) return null; } - public WireDetails GetWireDetailsForItem(string itemId) + public async Task GetWireDetailsForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/wire_details", Method.GET); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -190,12 +193,12 @@ public WireDetails GetWireDetailsForItem(string itemId) return null; } - public BPayDetails GetBPayDetailsForItem(string itemId) + public async Task GetBPayDetailsForItemAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/{id}/bpay_details", Method.GET); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -206,14 +209,14 @@ public BPayDetails GetBPayDetailsForItem(string itemId) return null; } - public Item MakePayment(string itemId, string accountId) + public async Task MakePaymentAsync(string itemId, string accountId) { AssertIdNotNull(itemId); AssertIdNotNull(accountId); var request = new RestRequest("/items/:id/make_payment", Method.PATCH); request.AddUrlSegment("id", itemId); request.AddParameter("account_id", accountId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -224,12 +227,12 @@ public Item MakePayment(string itemId, string accountId) return null; } - public Item RequestPayment(string itemId) + public async Task RequestPaymentAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/request_payment", Method.PATCH); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -240,13 +243,13 @@ public Item RequestPayment(string itemId) return null; } - public Item ReleasePayment(string itemId, int releaseAmount) + public async Task ReleasePaymentAsync(string itemId, int releaseAmount) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/release_payment", Method.PATCH); request.AddUrlSegment("id", itemId); request.AddParameter("release_amount", releaseAmount); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -257,13 +260,13 @@ public Item ReleasePayment(string itemId, int releaseAmount) return null; } - public Item RequestRelease(string itemId, int releaseAmount) + public async Task RequestReleaseAsync(string itemId, int releaseAmount) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/request_release", Method.PATCH); request.AddUrlSegment("id", itemId); request.AddParameter("release_amount", releaseAmount); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -274,12 +277,12 @@ public Item RequestRelease(string itemId, int releaseAmount) return null; } - public Item Cancel(string itemId) + public async Task CancelAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/cancel", Method.PATCH); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -290,12 +293,12 @@ public Item Cancel(string itemId) return null; } - public Item AcknowledgeWire(string itemId) + public async Task AcknowledgeWireAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/acknowledge_wire", Method.PATCH); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -306,12 +309,13 @@ public Item AcknowledgeWire(string itemId) return null; } - public Item AcknowledgePayPal(string itemId) + public async Task AcknowledgePayPalAsync(string itemId) { + //NOTE: Not documented! AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/acknowledge_paypal", Method.PATCH); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -322,12 +326,12 @@ public Item AcknowledgePayPal(string itemId) return null; } - public Item RevertWire(string itemId) + public async Task RevertWireAsync(string itemId) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/revert_wire", Method.PATCH); request.AddUrlSegment("id", itemId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -338,14 +342,14 @@ public Item RevertWire(string itemId) return null; } - public Item RequestRefund(string itemId, string refundAmount, string refundMessage) + public async Task RequestRefundAsync(string itemId, string refundAmount, string refundMessage) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/request_refund", Method.PATCH); request.AddUrlSegment("id", itemId); request.AddParameter("refund_amount", refundAmount); request.AddParameter("refund_message", refundMessage); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -356,14 +360,14 @@ public Item RequestRefund(string itemId, string refundAmount, string refundMessa return null; } - public Item Refund(string itemId, string refundAmount, string refundMessage) + public async Task RefundAsync(string itemId, string refundAmount, string refundMessage) { AssertIdNotNull(itemId); var request = new RestRequest("/items/:id/refund", Method.PATCH); request.AddUrlSegment("id", itemId); request.AddParameter("refund_amount", refundAmount); request.AddParameter("refund_message", refundMessage); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { diff --git a/PromisePayDotNet/Implementations/PayPalAccountRepository.cs b/PromisePayDotNet/Implementations/PayPalAccountRepository.cs index b13668c..91b8270 100644 --- a/PromisePayDotNet/Implementations/PayPalAccountRepository.cs +++ b/PromisePayDotNet/Implementations/PayPalAccountRepository.cs @@ -1,21 +1,22 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System.Collections.Generic; using System.Linq; using System.Net; +using Microsoft.Extensions.Options; namespace PromisePayDotNet.Implementations { - public class PayPalAccountRepository : AbstractRepository, IPayPalAccountRepository + internal class PayPalAccountRepository : AbstractRepository, IPayPalAccountRepository { - public PayPalAccountRepository(IRestClient client) : base(client) + public PayPalAccountRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public PayPalAccount GetPayPalAccountById(string paypalAccountId) { AssertIdNotNull(paypalAccountId); diff --git a/PromisePayDotNet/Implementations/TokenRepository.cs b/PromisePayDotNet/Implementations/TokenRepository.cs index 8385043..6ba3da6 100644 --- a/PromisePayDotNet/Implementations/TokenRepository.cs +++ b/PromisePayDotNet/Implementations/TokenRepository.cs @@ -1,29 +1,35 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; +using System; namespace PromisePayDotNet.Implementations { - public class TokenRepository : AbstractRepository, ITokenRepository + internal class TokenRepository : AbstractRepository, ITokenRepository { - public TokenRepository(IRestClient client) : base(client) + public TokenRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public string RequestToken() + public async Task RequestTokenAsync() { + // NOTE: there is no doc related to this! var request = new RestRequest("/request_token", Method.GET); - var response = SendRequest(Client, request); - return JsonConvert.DeserializeObject>(response.Content).Values.First(); + var response = await SendRequestAsync(Client, request); + return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public IDictionary RequestSessionToken(Token token) + public async Task> RequestSessionTokenAsync(Token token) { + // NOTE: there is no doc related to this! var request = new RestRequest("/request_session_token", Method.GET); request.AddParameter("current_user_id", token.CurrentUserId); request.AddParameter("current_user", token.CurrentUser); @@ -42,14 +48,16 @@ public IDictionary RequestSessionToken(Token token) request.AddParameter("external_buyer_id", token.ExternalBuyerId); request.AddParameter("fee_ids", token.FeeIds); request.AddParameter("payment_type_id", (int)token.PaymentType); - var response = SendRequest(Client, request); - return JsonConvert.DeserializeObject>(response.Content); + var response = await SendRequestAsync(Client, request); + return JsonConvert.DeserializeObject>(response.Content); } - public Widget GetWidget(string sessionToken) + + public async Task GetWidgetAsync(string sessionToken) { + // NOTE: there is no doc related to this! var request = new RestRequest("/widget", Method.GET); request.AddParameter("session_token", sessionToken); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("widget")) { @@ -58,5 +66,20 @@ public Widget GetWidget(string sessionToken) } return null; } + + public async Task GenerateCardTokenAsync(string tokenType, string userId) + { + var request = new RestRequest("/token_auths", Method.POST); + request.AddParameter("token_type", tokenType); + request.AddParameter("user_id", userId); + var response = await SendRequestAsync(Client, request); + var dict = JsonConvert.DeserializeObject>(response.Content); + if (dict.ContainsKey("token_auth")) + { + var itemCollection = dict["token_auth"]; + return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)); + } + return null; + } } } diff --git a/PromisePayDotNet/Implementations/TransactionRepository.cs b/PromisePayDotNet/Implementations/TransactionRepository.cs index 740970b..2d6e5d1 100644 --- a/PromisePayDotNet/Implementations/TransactionRepository.cs +++ b/PromisePayDotNet/Implementations/TransactionRepository.cs @@ -1,21 +1,22 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class TransactionRepository : AbstractRepository, ITransactionRepository + internal class TransactionRepository : AbstractRepository, ITransactionRepository { - public TransactionRepository(IRestClient client) : base(client) + public TransactionRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - - public IEnumerable ListTransactions(int limit = 10, int offset = 0) + public async Task> ListTransactionsAsync(int limit = 10, int offset = 0) { AssertListParamsCorrect(limit, offset); @@ -23,7 +24,7 @@ public IEnumerable ListTransactions(int limit = 10, int offset = 0) request.AddParameter("limit", limit); request.AddParameter("offset", offset); - var response = SendRequest(Client, request); + var response =await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("transactions")) { @@ -33,40 +34,40 @@ public IEnumerable ListTransactions(int limit = 10, int offset = 0) return new List(); } - public Transaction GetTransaction(string transactionId) + public async Task GetTransactionAsync(string transactionId) { AssertIdNotNull(transactionId); var request = new RestRequest("/transactions/{id}", Method.GET); request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public User GetUserForTransaction(string transactionId) + public async Task GetUserForTransactionAsync(string transactionId) { AssertIdNotNull(transactionId); var request = new RestRequest("/transactions/{id}/users", Method.GET); request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) { - var itemCollection = dict["users"]; + var itemCollection = dict["users"];//NOTE: Can be many users! return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)); } return null; } - public Fee GetFeeForTransaction(string transactionId) + public async Task GetFeeForTransactionAsync(string transactionId) { AssertIdNotNull(transactionId); var request = new RestRequest("/transactions/{id}/fees", Method.GET); request.AddUrlSegment("id", transactionId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("fees")) { - var itemCollection = dict["fees"]; + var itemCollection = dict["fees"];//NOTE: Can be many fees! return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)); } return null; diff --git a/PromisePayDotNet/Implementations/UploadRepository.cs b/PromisePayDotNet/Implementations/UploadRepository.cs index 8b80a93..11b59c0 100644 --- a/PromisePayDotNet/Implementations/UploadRepository.cs +++ b/PromisePayDotNet/Implementations/UploadRepository.cs @@ -1,21 +1,22 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; -using PromisePayDotNet.Interfaces; -using RestSharp; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; namespace PromisePayDotNet.Implementations { - public class UploadRepository : AbstractRepository, IUploadRepository + internal class UploadRepository : AbstractRepository, IUploadRepository { - public UploadRepository(IRestClient client) : base(client) + public UploadRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public IList ListUploads() { var request = new RestRequest("/uploads", Method.GET); diff --git a/PromisePayDotNet/Implementations/UserRepository.cs b/PromisePayDotNet/Implementations/UserRepository.cs index 0a54eda..4a0b240 100644 --- a/PromisePayDotNet/Implementations/UserRepository.cs +++ b/PromisePayDotNet/Implementations/UserRepository.cs @@ -1,33 +1,36 @@ -using Newtonsoft.Json; -using PromisePayDotNet.DTO; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using PromisePayDotNet.Dto; using PromisePayDotNet.Exceptions; -using PromisePayDotNet.Interfaces; -using RestSharp; +using PromisePayDotNet.Abstractions; +using PromisePayDotNet.Internals; using System; using System.Collections.Generic; using System.Linq; using System.Net; +using Microsoft.Extensions.Options; +using System.Threading.Tasks; namespace PromisePayDotNet.Implementations { - public class UserRepository : AbstractRepository, IUserRepository + internal class UserRepository : AbstractRepository, IUserRepository { - public UserRepository(IRestClient client) : base(client) + public UserRepository(IRestClient client, ILoggerFactory loggerFactory, IOptions options) + : base(client, loggerFactory.CreateLogger(), options) { } - private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #region public methods - public IEnumerable ListUsers(int limit = 10, int offset = 0) + public async Task> ListUsersAsync(int limit = 10, int offset = 0, string search = null) { AssertListParamsCorrect(limit, offset); var request = new RestRequest("/users", Method.GET); request.AddParameter("limit", limit); request.AddParameter("offset", offset); + request.AddParameter("search", search); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("users")) { @@ -37,16 +40,16 @@ public IEnumerable ListUsers(int limit = 10, int offset = 0) return new List(); } - public User GetUserById(string userId) + public async Task GetUserByIdAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}", Method.GET); request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public User CreateUser(User user) + public async Task CreateUserAsync(User user) { ValidateUser(user); var request = new RestRequest("/users", Method.POST); @@ -62,16 +65,16 @@ public User CreateUser(User user) request.AddParameter("zip", user.Zip); request.AddParameter("country", user.Country); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } - public bool DeleteUser(string userId) + public async Task DeleteUserAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}", Method.DELETE); request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); if (response.StatusCode == HttpStatusCode.NotFound) { return false; @@ -79,12 +82,12 @@ public bool DeleteUser(string userId) return true; } - public IEnumerable ListItemsForUser(string userId) + public async Task> ListItemsForUserAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}/items", Method.GET); request.AddUrlSegment("id", userId); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); var dict = JsonConvert.DeserializeObject>(response.Content); if (dict.ContainsKey("items")) { @@ -94,15 +97,15 @@ public IEnumerable ListItemsForUser(string userId) return new List(); } - public IEnumerable ListPayPalAccountsForUser(string userId) + public async Task> ListPayPalAccountsForUserAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}/paypal_accounts", Method.GET); request.AddUrlSegment("id", userId); - IRestResponse response; + RestResponse response; try { - response = SendRequest(Client, request); + response = await SendRequestAsync(Client, request); } catch (ApiErrorsException e) { @@ -116,20 +119,28 @@ public IEnumerable ListPayPalAccountsForUser(string userId) if (dict.ContainsKey("paypal_accounts")) { var itemCollection = dict["paypal_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + try + { + return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + } + catch (JsonSerializationException) + { + return new[] { JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)) }; + } + } return new List(); } - public IEnumerable ListCardAccountsForUser(string userId) + public async Task> ListCardAccountsForUserAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}/card_accounts", Method.GET); request.AddUrlSegment("id", userId); - IRestResponse response; + RestResponse response; try { - response = SendRequest(Client, request); + response = await SendRequestAsync(Client, request); } catch (ApiErrorsException e) { @@ -143,20 +154,28 @@ public IEnumerable ListCardAccountsForUser(string userId) if (dict.ContainsKey("card_accounts")) { var itemCollection = dict["card_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + try + { + return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + } + catch (JsonSerializationException) + { + return new[] { JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)) }; + } + } return new List(); } - public IEnumerable ListBankAccountsForUser(string userId) + public async Task> ListBankAccountsForUserAsync(string userId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}/bank_accounts", Method.GET); request.AddUrlSegment("id", userId); - IRestResponse response; + RestResponse response; try { - response = SendRequest(Client, request); + response = await SendRequestAsync(Client, request); } catch (ApiErrorsException e) { @@ -170,23 +189,30 @@ public IEnumerable ListBankAccountsForUser(string userId) if (dict.ContainsKey("bank_accounts")) { var itemCollection = dict["bank_accounts"]; - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + try + { + return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(itemCollection)); + } + catch (JsonSerializationException) + { + return new[] { JsonConvert.DeserializeObject(JsonConvert.SerializeObject(itemCollection)) }; + } } return new List(); } - public DisbursementAccount SetDisbursementAccount(string userId, string accountId) + public async Task SetDisbursementAccountAsync(string userId, string accountId) { AssertIdNotNull(userId); var request = new RestRequest("/users/{id}/disbursement_account?account_id={account_id}", Method.POST); request.AddUrlSegment("id", userId); request.AddUrlSegment("account_id", accountId); - IRestResponse response; + RestResponse response; try { - response = SendRequest(Client, request); + response = await SendRequestAsync(Client, request); } catch (ApiErrorsException) { @@ -202,7 +228,7 @@ public DisbursementAccount SetDisbursementAccount(string userId, string accountI return null; } - public User UpdateUser(User user) + public async Task UpdateUserAsync(User user) { ValidateUser(user); var request = new RestRequest("/users/{id}", Method.PATCH); @@ -219,7 +245,7 @@ public User UpdateUser(User user) request.AddParameter("zip", user.Zip); request.AddParameter("country", user.Country); - var response = SendRequest(Client, request); + var response = await SendRequestAsync(Client, request); return JsonConvert.DeserializeObject>(response.Content).Values.First(); } #endregion @@ -240,25 +266,12 @@ private void ValidateUser(User user) { throw new ValidationException("Field User.Country should contain 3-letter ISO country code!"); } - if (!IsCorrectEmail(user.Email)) + if (!Email.IsCorrect(user.Email)) { throw new ValidationException("Field User.Email should contain correct email address!"); } } - private bool IsCorrectEmail(string email) - { - try - { - var addr = new System.Net.Mail.MailAddress(email); - return addr.Address == email; - } - catch - { - return false; - } - } - #endregion } } diff --git a/PromisePayDotNet/Interfaces/IAddressRepository.cs b/PromisePayDotNet/Interfaces/IAddressRepository.cs deleted file mode 100644 index d3b44a7..0000000 --- a/PromisePayDotNet/Interfaces/IAddressRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using PromisePayDotNet.DTO; - -namespace PromisePayDotNet.Interfaces -{ - public interface IAddressRepository - { - Address GetAddressById(string addressId); - } -} diff --git a/PromisePayDotNet/Interfaces/IBankAccountRepository.cs b/PromisePayDotNet/Interfaces/IBankAccountRepository.cs deleted file mode 100644 index d24bf3b..0000000 --- a/PromisePayDotNet/Interfaces/IBankAccountRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PromisePayDotNet.DTO; - -namespace PromisePayDotNet.Interfaces -{ - public interface IBankAccountRepository - { - BankAccount GetBankAccountById(string bankAccountId); - - BankAccount CreateBankAccount(BankAccount bankAccount); - - bool DeleteBankAccount(string bankAccountId); - - User GetUserForBankAccount(string bankAccountId); - } -} diff --git a/PromisePayDotNet/Interfaces/IFeeRepository.cs b/PromisePayDotNet/Interfaces/IFeeRepository.cs deleted file mode 100644 index 54fddce..0000000 --- a/PromisePayDotNet/Interfaces/IFeeRepository.cs +++ /dev/null @@ -1,16 +0,0 @@ -using PromisePayDotNet.DTO; -using System.Collections.Generic; - -namespace PromisePayDotNet.Interfaces -{ - public interface IFeeRepository - { - - IEnumerable ListFees(); - - Fee GetFeeById(string feeId); - - Fee CreateFee(Fee fee); - - } -} diff --git a/PromisePayDotNet/Interfaces/IItemRepository.cs b/PromisePayDotNet/Interfaces/IItemRepository.cs deleted file mode 100644 index 78c58f7..0000000 --- a/PromisePayDotNet/Interfaces/IItemRepository.cs +++ /dev/null @@ -1,56 +0,0 @@ -using PromisePayDotNet.DTO; -using System.Collections.Generic; - -namespace PromisePayDotNet.Interfaces -{ - public interface IItemRepository - { - - IEnumerable ListItems(int limit = 10, int offset = 0); - - Item GetItemById(string itemId); - - Item CreateItem(Item item); - - bool DeleteItem(string itemId); - - Item UpdateItem(Item item); - - IEnumerable ListTransactionsForItem(string itemId); - - ItemStatus GetStatusForItem(string itemId); - - IEnumerable ListFeesForItem(string itemId); - - User GetBuyerForItem(string itemId); - - User GetSellerForItem(string itemId); - - WireDetails GetWireDetailsForItem(string itemId); - - BPayDetails GetBPayDetailsForItem(string itemId); - - //actions methods start here - - Item MakePayment(string itemId, string accountId); - - Item RequestPayment(string itemId); - - Item ReleasePayment(string itemId, int releaseAmount); - - Item RequestRelease(string itemId, int releaseAmount); - - Item Cancel(string itemId); - - Item AcknowledgeWire(string itemId); - - Item AcknowledgePayPal(string itemId); - - Item RevertWire(string itemId); - - Item RequestRefund(string itemId, string refundAmount, string refundMessage); - - Item Refund(string itemId, string refundAmount, string refundMessage); - - } -} diff --git a/PromisePayDotNet/Interfaces/ITokenRepository.cs b/PromisePayDotNet/Interfaces/ITokenRepository.cs deleted file mode 100644 index 5656a9a..0000000 --- a/PromisePayDotNet/Interfaces/ITokenRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using PromisePayDotNet.DTO; -using System.Collections.Generic; - -namespace PromisePayDotNet.Interfaces -{ - public interface ITokenRepository - { - string RequestToken(); - - IDictionary RequestSessionToken(Token token); - - Widget GetWidget(string sessionToken); - } -} diff --git a/PromisePayDotNet/Interfaces/ITransactionRepository.cs b/PromisePayDotNet/Interfaces/ITransactionRepository.cs deleted file mode 100644 index fdc5ebe..0000000 --- a/PromisePayDotNet/Interfaces/ITransactionRepository.cs +++ /dev/null @@ -1,16 +0,0 @@ -using PromisePayDotNet.DTO; -using System.Collections.Generic; - -namespace PromisePayDotNet.Interfaces -{ - public interface ITransactionRepository - { - IEnumerable ListTransactions(int limit = 10, int offset = 0); - - Transaction GetTransaction(string transactionId); - - User GetUserForTransaction(string transactionId); - - Fee GetFeeForTransaction(string transactionId); - } -} diff --git a/PromisePayDotNet/Interfaces/IUserRepository.cs b/PromisePayDotNet/Interfaces/IUserRepository.cs deleted file mode 100644 index 6b1c99e..0000000 --- a/PromisePayDotNet/Interfaces/IUserRepository.cs +++ /dev/null @@ -1,28 +0,0 @@ -using PromisePayDotNet.DTO; -using System.Collections.Generic; - -namespace PromisePayDotNet.Interfaces -{ - public interface IUserRepository - { - IEnumerable ListUsers(int limit = 10, int offset = 0); - - User GetUserById(string userId); - - User CreateUser(User user); - - User UpdateUser(User user); - - bool DeleteUser(string userId); - - IEnumerable ListItemsForUser(string userId); - - IEnumerable ListPayPalAccountsForUser(string userId); - - IEnumerable ListCardAccountsForUser(string userId); - - IEnumerable ListBankAccountsForUser(string userId); - - DisbursementAccount SetDisbursementAccount(string userId, string accountId); - } -} diff --git a/PromisePayDotNet/Internals/Email.cs b/PromisePayDotNet/Internals/Email.cs new file mode 100644 index 0000000..4d0f2b2 --- /dev/null +++ b/PromisePayDotNet/Internals/Email.cs @@ -0,0 +1,21 @@ +using System.Text.RegularExpressions; + +namespace PromisePayDotNet.Internals +{ + internal class Email + { + private static Regex emailRegex = new Regex(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); + public static bool IsCorrect(string email) + { + try + { + return emailRegex.IsMatch(email); + } + catch + { + return false; + } + } + + } +} diff --git a/PromisePayDotNet/Internals/FeeToJsonConverter.cs b/PromisePayDotNet/Internals/FeeToJsonConverter.cs new file mode 100644 index 0000000..4032306 --- /dev/null +++ b/PromisePayDotNet/Internals/FeeToJsonConverter.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using PromisePayDotNet.Enums; + +namespace PromisePayDotNet.Internals +{ + public class FeeToJsonConverter : JsonConverter + { + private static readonly IDictionary stringToEnum; + private static readonly Dictionary enumToString; + + static FeeToJsonConverter() + { + stringToEnum = new Dictionary() { + {"buyer", FeeToType.Buyer}, + {"seller", FeeToType.Seller}, + {"cc", FeeToType.CC}, + {"int_wire", FeeToType.IntWire}, + {"paypal_payout", FeeToType.PaypalPayout}, + {"", FeeToType.None}, + }; + enumToString = stringToEnum.ToDictionary(kv => kv.Value, kv => kv.Key); + } + + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(FeeToType); + } + + public static FeeToType Parse(string str) + { + if (stringToEnum.TryGetValue(str, out var receiver)) return receiver; + throw new Exception($"Unknown value {str}"); + } + + public static string ToString(FeeToType receiver) + { + if (enumToString.TryGetValue(receiver, out var str)) + { + return str; + } + else + { + throw new Exception($"Unknown value {receiver}"); + } + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return Parse((string)serializer.Deserialize(reader, typeof(string)) ?? string.Empty); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + writer.WriteValue(ToString((FeeToType)value)); + } + } +} diff --git a/PromisePayDotNet/Internals/HttpBasicAuthenticator.cs b/PromisePayDotNet/Internals/HttpBasicAuthenticator.cs new file mode 100644 index 0000000..cf66a66 --- /dev/null +++ b/PromisePayDotNet/Internals/HttpBasicAuthenticator.cs @@ -0,0 +1,24 @@ +using System; +using System.Net.Http; +using System.Text; + +namespace PromisePayDotNet.Internals +{ + public class HttpBasicAuthenticator : IAuthenticator + { + private string login; + private string password; + + public HttpBasicAuthenticator(string login, string password) + { + this.login = login; + this.password = password; + } + + public void Add(HttpRequestMessage req) + { + var byteArray = Encoding.ASCII.GetBytes($"{login}:{password}"); + req.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); + } + } +} diff --git a/PromisePayDotNet/Internals/IAuthenticator.cs b/PromisePayDotNet/Internals/IAuthenticator.cs new file mode 100644 index 0000000..4096764 --- /dev/null +++ b/PromisePayDotNet/Internals/IAuthenticator.cs @@ -0,0 +1,11 @@ +using System; +using System.Net; +using System.Net.Http; + +namespace PromisePayDotNet.Internals +{ + public interface IAuthenticator + { + void Add(HttpRequestMessage req); + } +} diff --git a/PromisePayDotNet/Internals/IRestClient.cs b/PromisePayDotNet/Internals/IRestClient.cs new file mode 100644 index 0000000..6311b21 --- /dev/null +++ b/PromisePayDotNet/Internals/IRestClient.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Internals +{ + public interface IRestClient + { + Uri BaseUrl { get; set; } + IAuthenticator Authenticator { get; set; } + + Task ExecuteAsync(RestRequest request); + } +} diff --git a/PromisePayDotNet/Internals/Method.cs b/PromisePayDotNet/Internals/Method.cs new file mode 100644 index 0000000..78aa504 --- /dev/null +++ b/PromisePayDotNet/Internals/Method.cs @@ -0,0 +1,15 @@ +using System; +using System.Net; +using System.Net.Http; + +namespace PromisePayDotNet.Internals +{ + internal class Method + { + public static HttpMethod GET = HttpMethod.Get; + public static HttpMethod POST = HttpMethod.Post; + public static HttpMethod PUT = HttpMethod.Put; + public static HttpMethod PATCH = new HttpMethod("PATCH"); + public static HttpMethod DELETE = HttpMethod.Delete; + } +} diff --git a/PromisePayDotNet/Internals/RestClient.cs b/PromisePayDotNet/Internals/RestClient.cs new file mode 100644 index 0000000..37a7a57 --- /dev/null +++ b/PromisePayDotNet/Internals/RestClient.cs @@ -0,0 +1,51 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace PromisePayDotNet.Internals +{ + + internal class RestClient : IRestClient + { + private HttpClient _client; + public RestClient() + { + _client = new HttpClient(); + } + public Uri BaseUrl { get => _client.BaseAddress; set => _client.BaseAddress = value; } + public IAuthenticator Authenticator { get; set; } + + public async Task ExecuteAsync(RestRequest request) + { + var rel = new Uri(request.url, UriKind.Relative); + var req = new HttpRequestMessage + { + Method = request.Method, + RequestUri = rel, + }; + req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + if (request.Body != null) + { + req.Content = new StringContent(JsonConvert.SerializeObject(request.Body), Encoding.UTF8, "application/json"); + } + else + { + req.Headers.Add("Content-Type", "application/json"); + } + Authenticator?.Add(req); + + var result = await _client.SendAsync(req); + + return new RestResponse + { + Content = await result.Content.ReadAsStringAsync(), + ResponseUri = new Uri(BaseUrl, rel), + StatusCode = result.StatusCode, + StatusDescription = result.ReasonPhrase + }; + } + } +} diff --git a/PromisePayDotNet/Internals/RestRequest.cs b/PromisePayDotNet/Internals/RestRequest.cs new file mode 100644 index 0000000..4065bde --- /dev/null +++ b/PromisePayDotNet/Internals/RestRequest.cs @@ -0,0 +1,48 @@ +using System; +using System.Net; +using System.Net.Http; + +namespace PromisePayDotNet.Internals +{ + public class RestRequest + { + internal string url; + public RestRequest(string url, HttpMethod method) + : this(url, method, null) + { + } + + public RestRequest(string url, HttpMethod method, object body) + { + this.url = url; + this.Method = method; + this.Body = body; + } + /// + /// Gets the method. + /// + public HttpMethod Method { get; } + /// + /// Gets the body of the request. + /// + public object Body { get; } + + internal void AddUrlSegment(string name, string value) + { + this.url = this.url.Replace($"{{{name}}}", Uri.EscapeDataString(value)); + } + + internal void AddParameter(string name, object value) + { + if (ReferenceEquals(null, value)) return; + if (this.url.Contains("?")) + { + this.url = $"{this.url}&{Uri.EscapeDataString(name)}={Uri.EscapeDataString(value.ToString())}"; + } + else + { + this.url = $"{this.url}?{Uri.EscapeDataString(name)}={Uri.EscapeDataString(value.ToString())}"; + } + } + } +} diff --git a/PromisePayDotNet/Internals/RestResponse.cs b/PromisePayDotNet/Internals/RestResponse.cs new file mode 100644 index 0000000..212e6f0 --- /dev/null +++ b/PromisePayDotNet/Internals/RestResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Net; + +namespace PromisePayDotNet.Internals +{ + public class RestResponse + { + public virtual Uri ResponseUri { get; set; } + public virtual string StatusDescription { get; set; } + public virtual string Content { get; set; } + public virtual HttpStatusCode StatusCode { get; set; } + } +} diff --git a/PromisePayDotNet/Internals/Tasks.cs b/PromisePayDotNet/Internals/Tasks.cs new file mode 100644 index 0000000..39c49b2 --- /dev/null +++ b/PromisePayDotNet/Internals/Tasks.cs @@ -0,0 +1,27 @@ +using PromisePayDotNet.Exceptions; +using System; +using System.Threading.Tasks; + +namespace PromisePayDotNet.Internals +{ + internal static class TasksExtensions + { + public static T WrapResult(this Task task) + { + try + { + return task.Result; + } + catch (AggregateException ex) + { + if (ex.InnerException != null && ( + ex.InnerException is ApiErrorsException + || ex.InnerException is UnauthorizedException + || ex.InnerException is ArgumentException + || ex.InnerException is ValidationException)) + throw ex.InnerException; + throw; + } + } + } +} diff --git a/PromisePayDotNet/PromisePayDotNet.csproj b/PromisePayDotNet/PromisePayDotNet.csproj index 0a9f2bf..8e69bb1 100644 --- a/PromisePayDotNet/PromisePayDotNet.csproj +++ b/PromisePayDotNet/PromisePayDotNet.csproj @@ -1,159 +1,39 @@ - - - + + - Debug - AnyCPU - {D7EC61A8-A481-49DA-85AE-280B0A3D08B0} - Library - Properties - PromisePayDotNet + netstandard1.3 + PromisePay.API.NET + Igor Sidorov, Carable developers + PromisePay + PromisePayDotNet + This package provides an easy way to use PromisePay API PromisePayDotNet - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + PromisePayDotNet + + 2.0.0 + alpha-3 + + $(VersionPrefix)-$(VersionSuffix) + $(VersionPrefix) + $(VersionPrefix).0 + $(VersionPrefix).0 + + true + https://github.com/PromisePay/promisepay-dotnet + https://github.com/carable/promisepay-dotnet + .net Core version and .net 45 version of PromisePay client + + + - - ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll - - - ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll - - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - \ No newline at end of file + + + + diff --git a/PromisePayDotNet/PromisePayDotNet.nuspec b/PromisePayDotNet/PromisePayDotNet.nuspec deleted file mode 100644 index 49a6b4c..0000000 --- a/PromisePayDotNet/PromisePayDotNet.nuspec +++ /dev/null @@ -1,21 +0,0 @@ - - - - PromisePay.API.NET - 0.1.0 - Promise Pay API - Igor Sidorov - Andrew McIntosh - https://github.com/PromisePay/promisepay-dotnet - false - This package provides an easy way to use PromisePay API - Initial release of the package - Copyright 2015 - - - - - - - - \ No newline at end of file diff --git a/PromisePayDotNet/Properties/AssemblyInfo.cs b/PromisePayDotNet/Properties/AssemblyInfo.cs deleted file mode 100644 index 8097df6..0000000 --- a/PromisePayDotNet/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("PromisePayDotNet")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("PromisePayDotNet")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: log4net.Config.XmlConfigurator(Watch = true)] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4289e1b2-225a-4932-be38-8f21b3c22517")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PromisePayDotNet/Settings/PromisePaySettings.cs b/PromisePayDotNet/Settings/PromisePaySettings.cs index 6fbd914..0a8fcdf 100644 --- a/PromisePayDotNet/Settings/PromisePaySettings.cs +++ b/PromisePayDotNet/Settings/PromisePaySettings.cs @@ -1,8 +1,9 @@ -using System.Configuration; - -namespace PromisePayDotNet.Settings +namespace PromisePayDotNet.Settings { - public class SettingsHandler : DictionarySectionHandler + public class PromisePaySettings { + public string ApiUrl { get; set; } + public string Login { get; set; } + public string Password { get; set; } } } diff --git a/PromisePayDotNet/packages.config b/PromisePayDotNet/packages.config deleted file mode 100644 index 5648ad3..0000000 --- a/PromisePayDotNet/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/packages/repositories.config b/packages/repositories.config deleted file mode 100644 index 0d22712..0000000 --- a/packages/repositories.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file