Skip to content

Commit 0c7d763

Browse files
chore: this commit migrates the repository and organization of the comanda contracts project
1 parent afc9409 commit 0c7d763

107 files changed

Lines changed: 3454 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{B8EFCA5F-814F-285C-A8CB-F00F14650265}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Internal.Contracts", "Source\Comanda.Internal.Contracts.csproj", "{5CF30A8D-3C01-499A-9D20-922F29E67300}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|x64 = Debug|x64
14+
Debug|x86 = Debug|x86
15+
Release|Any CPU = Release|Any CPU
16+
Release|x64 = Release|x64
17+
Release|x86 = Release|x86
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|x64.ActiveCfg = Debug|Any CPU
23+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|x64.Build.0 = Debug|Any CPU
24+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|x86.ActiveCfg = Debug|Any CPU
25+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Debug|x86.Build.0 = Debug|Any CPU
26+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|x64.ActiveCfg = Release|Any CPU
29+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|x64.Build.0 = Release|Any CPU
30+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|x86.ActiveCfg = Release|Any CPU
31+
{5CF30A8D-3C01-499A-9D20-922F29E67300}.Release|x86.Build.0 = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(SolutionProperties) = preSolution
34+
HideSolutionNode = FALSE
35+
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{5CF30A8D-3C01-499A-9D20-922F29E67300} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
38+
EndGlobalSection
39+
EndGlobal
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Comanda.Internal.Contracts.Clients;
2+
3+
public sealed class AbacatePayClient(HttpClient httpClient) : IAbacatePayClient
4+
{
5+
private readonly JsonSerializerOptions serializerOptions = new()
6+
{
7+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
8+
PropertyNameCaseInsensitive = true
9+
};
10+
11+
public async Task<Result<PixChargeSessionScheme>> CreateChargeSessionAsync(
12+
PixChargeScheme parameters, CancellationToken cancellation = default)
13+
{
14+
var response = await httpClient.PostAsJsonAsync("pixQrCode/create", parameters, cancellation);
15+
var content = await response.Content.ReadAsStringAsync(cancellation);
16+
17+
if (!response.IsSuccessStatusCode)
18+
{
19+
return Result<PixChargeSessionScheme>.Failure(AbacatePayErrors.OperationFailed);
20+
}
21+
22+
var session = JsonSerializer.Deserialize<Response<PixChargeSessionScheme>>(content, serializerOptions);
23+
if (session is null)
24+
{
25+
return Result<PixChargeSessionScheme>.Failure(AbacatePayErrors.InvalidContent);
26+
}
27+
28+
return Result<PixChargeSessionScheme>.Success(session.Data);
29+
}
30+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
namespace Comanda.Internal.Contracts.Clients;
2+
3+
public sealed class CredentialsClient(HttpClient httpClient) : ICredentialsClient
4+
{
5+
private readonly JsonSerializerOptions serializerOptions = new()
6+
{
7+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
8+
PropertyNameCaseInsensitive = true
9+
};
10+
11+
public async Task<Result<IReadOnlyCollection<CredentialScheme>>> GetCredentialsAsync(
12+
CredentialsFetchParameters parameters, CancellationToken cancellation = default)
13+
{
14+
var response = await httpClient.GetAsync($"establishments/{parameters.EstablishmentId}/integrations/credentials", cancellation);
15+
var content = await response.Content.ReadAsStringAsync(cancellation);
16+
17+
var error = response.StatusCode switch
18+
{
19+
HttpStatusCode.NotFound => EstablishmentErrors.EstablishmentDoesNotExist,
20+
HttpStatusCode.Unauthorized => CommonErrors.UnauthorizedAccess,
21+
HttpStatusCode.Forbidden => CommonErrors.UnauthorizedAccess,
22+
HttpStatusCode.InternalServerError => CommonErrors.OperationFailed,
23+
24+
_ => null
25+
};
26+
27+
if (error is not null)
28+
{
29+
return Result<IReadOnlyCollection<CredentialScheme>>.Failure(error);
30+
}
31+
32+
var credentials = JsonSerializer.Deserialize<IReadOnlyCollection<CredentialScheme>>(content, serializerOptions);
33+
if (credentials is null)
34+
{
35+
return Result<IReadOnlyCollection<CredentialScheme>>.Failure(CommonErrors.InvalidContent);
36+
}
37+
38+
return Result<IReadOnlyCollection<CredentialScheme>>.Success(credentials);
39+
}
40+
41+
public async Task<Result<CredentialScheme>> AssignIntegrationCredentialAsync(
42+
CredentialCreationScheme parameters, CancellationToken cancellation = default)
43+
{
44+
var response = await httpClient.PostAsJsonAsync($"establishments/{parameters.EstablishmentId}/integrations/credentials", parameters, cancellation);
45+
var content = await response.Content.ReadAsStringAsync(cancellation);
46+
47+
var error = response.StatusCode switch
48+
{
49+
HttpStatusCode.NotFound => EstablishmentErrors.EstablishmentDoesNotExist,
50+
HttpStatusCode.Unauthorized => CommonErrors.UnauthorizedAccess,
51+
HttpStatusCode.Forbidden => CommonErrors.UnauthorizedAccess,
52+
HttpStatusCode.InternalServerError => CommonErrors.OperationFailed,
53+
54+
_ => null
55+
};
56+
57+
if (error is not null)
58+
{
59+
return Result<CredentialScheme>.Failure(error);
60+
}
61+
62+
var credential = JsonSerializer.Deserialize<CredentialScheme>(content, serializerOptions);
63+
if (credential is null)
64+
{
65+
return Result<CredentialScheme>.Failure(CommonErrors.InvalidContent);
66+
}
67+
68+
return Result<CredentialScheme>.Success(credential);
69+
}
70+
71+
public async Task<Result<CredentialScheme>> UpdateCredentialAsync(
72+
CredentialModificationScheme parameters, CancellationToken cancellation = default)
73+
{
74+
var response = await httpClient.PutAsJsonAsync($"establishments/{parameters.EstablishmentId}/integrations/credentials/{parameters.CredentialId}", parameters, cancellation);
75+
var content = await response.Content.ReadAsStringAsync(cancellation);
76+
77+
if (!response.IsSuccessStatusCode)
78+
{
79+
var error = JsonSerializer.Deserialize<Error>(content, serializerOptions);
80+
if (error is not null)
81+
return Result<CredentialScheme>.Failure(error);
82+
83+
return Result<CredentialScheme>.Failure(CommonErrors.OperationFailed);
84+
}
85+
86+
var credential = JsonSerializer.Deserialize<CredentialScheme>(content, serializerOptions);
87+
if (credential is null)
88+
{
89+
return Result<CredentialScheme>.Failure(CommonErrors.InvalidContent);
90+
}
91+
92+
return Result<CredentialScheme>.Success(credential);
93+
}
94+
}

0 commit comments

Comments
 (0)