Skip to content

Commit 833fe69

Browse files
feature: this commit introduces the payment solution, migrating the organization and repository from boundary
1 parent 1d0ca5e commit 833fe69

100 files changed

Lines changed: 2031 additions & 21 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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
**/.vs
2+
**/.git
3+
4+
**/bin
5+
**/obj
6+
**/.vscode
7+
**/TestResults
8+
9+
*.user
10+
*.suo
11+
*.userosscache
12+
*.sln.docstates
13+
14+
**/appsettings.json
15+
**/appsettings.*.json
16+
17+
Dockerfile
18+
README.md
19+
LICENSE
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MONGO_INITDB_ROOT_USERNAME=admin
2+
MONGO_INITDB_ROOT_PASSWORD=admin
3+
4+
SEQ_FIRSTRUN_ADMINPASSWORD=admin
5+
6+
MONGO_CONNECTIONSTRING=mongodb://admin:admin@mongo:27017
7+
MONGO_DATABASENAME=comanda_payments
8+
9+
ADMIN_USERNAME=admin
10+
ADMIN_PASSWORD=admin
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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.Payments.Domain", "Source\Comanda.Payments.Domain\Comanda.Payments.Domain.csproj", "{C7293B3C-E854-443D-8BB8-D79A81380162}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.Application", "Source\Comanda.Payments.Application\Comanda.Payments.Application.csproj", "{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.Infrastructure", "Source\Comanda.Payments.Infrastructure\Comanda.Payments.Infrastructure.csproj", "{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.Infrastructure.IoC", "Source\Comanda.Payments.Infrastructure.IoC\Comanda.Payments.Infrastructure.IoC.csproj", "{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.WebApi", "Source\Comanda.Payments.WebApi\Comanda.Payments.WebApi.csproj", "{37A746D8-CD9D-449A-AB1B-2C02F5366694}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.CrossCutting", "Source\Comanda.Payments.CrossCutting\Comanda.Payments.CrossCutting.csproj", "{F218FF09-497E-4E48-A960-2BE2A0FD38F1}"
19+
EndProject
20+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Comanda.Payments.TestSuite", "Tests\Comanda.Payments.TestSuite.csproj", "{8434AF6E-FEDA-4692-A448-720429C00800}"
23+
EndProject
24+
Global
25+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
26+
Debug|Any CPU = Debug|Any CPU
27+
Debug|x64 = Debug|x64
28+
Debug|x86 = Debug|x86
29+
Release|Any CPU = Release|Any CPU
30+
Release|x64 = Release|x64
31+
Release|x86 = Release|x86
32+
EndGlobalSection
33+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
34+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|x64.ActiveCfg = Debug|Any CPU
37+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|x64.Build.0 = Debug|Any CPU
38+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|x86.ActiveCfg = Debug|Any CPU
39+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Debug|x86.Build.0 = Debug|Any CPU
40+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|x64.ActiveCfg = Release|Any CPU
43+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|x64.Build.0 = Release|Any CPU
44+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|x86.ActiveCfg = Release|Any CPU
45+
{C7293B3C-E854-443D-8BB8-D79A81380162}.Release|x86.Build.0 = Release|Any CPU
46+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|x64.ActiveCfg = Debug|Any CPU
49+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|x64.Build.0 = Debug|Any CPU
50+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|x86.ActiveCfg = Debug|Any CPU
51+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Debug|x86.Build.0 = Debug|Any CPU
52+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|x64.ActiveCfg = Release|Any CPU
55+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|x64.Build.0 = Release|Any CPU
56+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|x86.ActiveCfg = Release|Any CPU
57+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF}.Release|x86.Build.0 = Release|Any CPU
58+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|x64.ActiveCfg = Debug|Any CPU
61+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|x64.Build.0 = Debug|Any CPU
62+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|x86.ActiveCfg = Debug|Any CPU
63+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Debug|x86.Build.0 = Debug|Any CPU
64+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|x64.ActiveCfg = Release|Any CPU
67+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|x64.Build.0 = Release|Any CPU
68+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|x86.ActiveCfg = Release|Any CPU
69+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3}.Release|x86.Build.0 = Release|Any CPU
70+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|Any CPU.Build.0 = Debug|Any CPU
72+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|x64.ActiveCfg = Debug|Any CPU
73+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|x64.Build.0 = Debug|Any CPU
74+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|x86.ActiveCfg = Debug|Any CPU
75+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Debug|x86.Build.0 = Debug|Any CPU
76+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|Any CPU.ActiveCfg = Release|Any CPU
77+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|Any CPU.Build.0 = Release|Any CPU
78+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|x64.ActiveCfg = Release|Any CPU
79+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|x64.Build.0 = Release|Any CPU
80+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|x86.ActiveCfg = Release|Any CPU
81+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14}.Release|x86.Build.0 = Release|Any CPU
82+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
83+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|Any CPU.Build.0 = Debug|Any CPU
84+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|x64.ActiveCfg = Debug|Any CPU
85+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|x64.Build.0 = Debug|Any CPU
86+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|x86.ActiveCfg = Debug|Any CPU
87+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Debug|x86.Build.0 = Debug|Any CPU
88+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|Any CPU.Build.0 = Release|Any CPU
90+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|x64.ActiveCfg = Release|Any CPU
91+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|x64.Build.0 = Release|Any CPU
92+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|x86.ActiveCfg = Release|Any CPU
93+
{37A746D8-CD9D-449A-AB1B-2C02F5366694}.Release|x86.Build.0 = Release|Any CPU
94+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
95+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
96+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|x64.ActiveCfg = Debug|Any CPU
97+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|x64.Build.0 = Debug|Any CPU
98+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|x86.ActiveCfg = Debug|Any CPU
99+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Debug|x86.Build.0 = Debug|Any CPU
100+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|Any CPU.Build.0 = Release|Any CPU
102+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|x64.ActiveCfg = Release|Any CPU
103+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|x64.Build.0 = Release|Any CPU
104+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|x86.ActiveCfg = Release|Any CPU
105+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1}.Release|x86.Build.0 = Release|Any CPU
106+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
107+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|Any CPU.Build.0 = Debug|Any CPU
108+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|x64.ActiveCfg = Debug|Any CPU
109+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|x64.Build.0 = Debug|Any CPU
110+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|x86.ActiveCfg = Debug|Any CPU
111+
{8434AF6E-FEDA-4692-A448-720429C00800}.Debug|x86.Build.0 = Debug|Any CPU
112+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|Any CPU.ActiveCfg = Release|Any CPU
113+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|Any CPU.Build.0 = Release|Any CPU
114+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|x64.ActiveCfg = Release|Any CPU
115+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|x64.Build.0 = Release|Any CPU
116+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|x86.ActiveCfg = Release|Any CPU
117+
{8434AF6E-FEDA-4692-A448-720429C00800}.Release|x86.Build.0 = Release|Any CPU
118+
EndGlobalSection
119+
GlobalSection(SolutionProperties) = preSolution
120+
HideSolutionNode = FALSE
121+
EndGlobalSection
122+
GlobalSection(NestedProjects) = preSolution
123+
{C7293B3C-E854-443D-8BB8-D79A81380162} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
124+
{5B4760C0-F3BD-4837-8D1B-19E59A13BDDF} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
125+
{31C332BD-1EA3-4A7B-B737-BCB46C78AFF3} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
126+
{329A734D-2607-40FD-9ED2-3BF7ABEC2A14} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
127+
{37A746D8-CD9D-449A-AB1B-2C02F5366694} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
128+
{F218FF09-497E-4E48-A960-2BE2A0FD38F1} = {B8EFCA5F-814F-285C-A8CB-F00F14650265}
129+
{8434AF6E-FEDA-4692-A448-720429C00800} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
130+
EndGlobalSection
131+
EndGlobal
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# use ASP.NET Core 9.0 runtime image as base
2+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
3+
WORKDIR /app
4+
EXPOSE 8085
5+
6+
# use SDK image for build
7+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
8+
WORKDIR /src
9+
10+
# copy project files to restore dependencies
11+
COPY ["Source/Comanda.Payments.WebApi/Comanda.Payments.WebApi.csproj", "Comanda.Payments.WebApi/"]
12+
13+
# copy the entire solution 'n related projects
14+
COPY ["Comanda.Payments.sln", "./"]
15+
16+
# restore dependencies for the project
17+
RUN dotnet restore "Comanda.Payments.WebApi/Comanda.Payments.WebApi.csproj"
18+
19+
# copy all source code into the container
20+
COPY Source/ ./Source/
21+
22+
# set working directory to the web project
23+
WORKDIR "/src/Source/Comanda.Payments.WebApi"
24+
25+
# build in Release mode
26+
RUN dotnet build "Comanda.Payments.WebApi.csproj" -c Release -o /app/build
27+
28+
# publish the project for production
29+
FROM build AS publish
30+
RUN dotnet publish "Comanda.Payments.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
31+
32+
# final image to run the app
33+
FROM base AS final
34+
WORKDIR /app
35+
36+
# copy published files from the publish stage
37+
COPY --from=publish /app/publish .
38+
39+
# set the command to start the application
40+
ENTRYPOINT ["dotnet", "Comanda.Payments.WebApi.dll"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="FluentValidation" Version="12.0.0" />
11+
<PackageReference Include="Comanda.Internal.Contracts" Version="1.0.1" />
12+
<PackageReference Include="HttpsRichardy.Dispatcher" Version="1.0.2" />
13+
<PackageReference Include="HttpsRichardy.Federation.Sdk.Contracts" Version="1.0.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="../Comanda.Payments.Domain/Comanda.Payments.Domain.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Comanda.Payments.Application.Gateways;
2+
3+
public interface IPaymentGateway
4+
{
5+
public Task<Result<CheckoutSession>> CreateCheckoutSessionAsync(
6+
CheckoutSessionCreationScheme parameters,
7+
Payment payment,
8+
CancellationToken cancellation = default
9+
);
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma warning disable S3626
2+
3+
namespace Comanda.Payments.Application.Handlers.Billing;
4+
5+
public sealed class BillingPaidHandler(IPaymentCollection paymentCollection, IActivityCollection activityCollection) :
6+
IEventHandler<BillingPaidNotificationScheme>
7+
{
8+
public async Task HandleAsync(BillingPaidNotificationScheme parameters, CancellationToken cancellation = default)
9+
{
10+
var metadata = parameters.Data.PixQrCode.Metadata;
11+
var paymentId = metadata.GetValueOrDefault("payment.identifier");
12+
13+
var filters = PaymentFilters.WithSpecifications()
14+
.WithIdentifier(paymentId)
15+
.Build();
16+
17+
var payments = await paymentCollection.FilterPaymentsAsync(filters, cancellation);
18+
var payment = payments.FirstOrDefault();
19+
20+
if (payment is null)
21+
{
22+
return;
23+
}
24+
25+
payment.MarkAsPaid();
26+
payment.Metadata = new PaymentMetadata(
27+
Identifier: parameters.Data.PixQrCode.Id,
28+
Reference: payment.Metadata.Reference
29+
);
30+
31+
var activity = new Activity
32+
{
33+
Action = "comanda.actions.payment.paid",
34+
Description = $"customer '{payment.Payer.Username}' completed a payment successfully.",
35+
Resource = Resource.From(payment.Id, nameof(Payment)),
36+
User = new User(payment.Payer.Identifier, payment.Payer.Username),
37+
Metadata = new Dictionary<string, string>
38+
{
39+
{ "payer.identifier", payment.Payer.Identifier },
40+
{ "payment.method", payment.Method.ToString() },
41+
{ "payment.amount", payment.Amount.ToString("F2") }
42+
}
43+
};
44+
45+
await paymentCollection.UpdateAsync(payment, cancellation: cancellation);
46+
await activityCollection.InsertAsync(activity, cancellation: cancellation);
47+
}
48+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Comanda.Payments.Application.Handlers.Payment;
2+
3+
public sealed class CreateCheckoutSessionHandler(
4+
IPaymentGateway paymentGateway,
5+
IPaymentCollection paymentCollection,
6+
IActivityCollection activityCollection
7+
) : IDispatchHandler<CheckoutSessionCreationScheme, Result<CheckoutSession>>
8+
{
9+
public async Task<Result<CheckoutSession>> HandleAsync(
10+
CheckoutSessionCreationScheme parameters, CancellationToken cancellation = default)
11+
{
12+
var payment = await paymentCollection.InsertAsync(parameters.AsPayment(), cancellation: cancellation);
13+
var activity = new Activity
14+
{
15+
Action = "comanda.actions.payment.creation",
16+
Description = $"customer '{parameters.Payer.Username}' started a new payment process.",
17+
Resource = Resource.From(payment.Id, nameof(Payment)),
18+
User = new User(parameters.Payer.Identifier, parameters.Payer.Username),
19+
Metadata = new Dictionary<string, string>
20+
{
21+
{ "payer.identifier", payment.Payer.Identifier },
22+
{ "payment.method", payment.Method.ToString() },
23+
{ "payment.amount", payment.Amount.ToString() }
24+
}
25+
};
26+
27+
await activityCollection.InsertAsync(activity, cancellation: cancellation);
28+
29+
return await paymentGateway.CreateCheckoutSessionAsync(parameters, payment, cancellation);
30+
}
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Comanda.Payments.Application.Handlers.Payment;
2+
3+
public sealed class OfflinePaymentChargeHandler(IPaymentCollection paymentCollection) :
4+
IDispatchHandler<OfflinePaymentChargeScheme, Result<PaymentScheme>>
5+
{
6+
public async Task<Result<PaymentScheme>> HandleAsync(
7+
OfflinePaymentChargeScheme parameters, CancellationToken cancellation = default)
8+
{
9+
if (parameters.Method == Method.Pix)
10+
{
11+
/* for tracking purposes: raise error #COMANDA-ERROR-947B5 */
12+
return Result<PaymentScheme>.Failure(PaymentErrors.MethodNotAllowed);
13+
}
14+
15+
var payment = await paymentCollection.InsertAsync(parameters.AsPayment(), cancellation: cancellation);
16+
17+
return Result<PaymentScheme>.Success(payment.AsResponse());
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Comanda.Payments.Application.Handlers.Payment;
2+
3+
public sealed class PaymentStatusUpdateHandler(IPaymentCollection paymentCollection) :
4+
IDispatchHandler<PaymentStatusUpdateScheme, Result<PaymentScheme>>
5+
{
6+
public async Task<Result<PaymentScheme>> HandleAsync(
7+
PaymentStatusUpdateScheme parameters, CancellationToken cancellation = default)
8+
{
9+
var filters = PaymentFilters.WithSpecifications()
10+
.WithIdentifier(parameters.Identifier)
11+
.Build();
12+
13+
var payments = await paymentCollection.FilterPaymentsAsync(filters, cancellation);
14+
var payment = payments.FirstOrDefault();
15+
16+
if (payment is null)
17+
{
18+
return Result<PaymentScheme>.Failure(PaymentErrors.PaymentDoesNotExist);
19+
}
20+
21+
payment.Status = parameters.Status;
22+
23+
await paymentCollection.UpdateAsync(payment, cancellation);
24+
25+
return Result<PaymentScheme>.Success(payment.AsResponse());
26+
}
27+
}

0 commit comments

Comments
 (0)