Skip to content

Commit

Permalink
feat: separate payment domain
Browse files Browse the repository at this point in the history
  • Loading branch information
italopessoa committed Nov 17, 2024
1 parent a1fb9e6 commit 32b895a
Show file tree
Hide file tree
Showing 55 changed files with 200 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Bmb Payment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmb.Orders.Gateway.Test", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmb.Payment.DynamoDb.Test", "tests\Bmb.Payment.DynamoDb.Test\Bmb.Payment.DynamoDb.Test.csproj", "{C5464D10-B602-4B01-A14C-560536BB9563}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmb.Payment.Core", "src\Bmb.Payment.Core\Bmb.Payment.Core.csproj", "{C616857B-CB67-4904-9787-4FC78963CE50}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmb.Payment.Domain", "src\Bmb.Payment.Domain\Bmb.Payment.Domain.csproj", "{C616857B-CB67-4904-9787-4FC78963CE50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmb.Payment.Masstransit", "src\Bmb.Payment.Masstransit\Bmb.Payment.Masstransit.csproj", "{FA002C5A-0B24-4986-BA44-A9E09A8BA553}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Orders.Gateway/Bmb.Orders.Gateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bmb.Payment.Core\Bmb.Payment.Core.csproj" />
<ProjectReference Include="..\Bmb.Payment.Domain\Bmb.Payment.Domain.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Orders.Gateway/Presenter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using Amazon.DynamoDBv2.Model;
using Bmb.Domain.Core.Entities;
using Bmb.Payment.Core;
using Bmb.Payment.Domain;

namespace Bmb.Orders.Gateway;

Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Orders.Gateway/Repository/InMemoryOrdersGateway.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Core;
using Bmb.Payment.Domain;

namespace Bmb.Orders.Gateway.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Amazon.DynamoDBv2.Model;
using Bmb.Domain.Core.Base;
using Bmb.Domain.Core.Entities;
using Bmb.Payment.Core;
using Bmb.Payment.Domain;

namespace Bmb.Orders.Gateway.Repository;

Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Orders.Gateway/ServiceCollectionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Bmb.Orders.Gateway.Repository;
using Bmb.Payment.Core;
using Bmb.Payment.Domain;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Payment.Api/Controllers/NotificationsController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Api.Auth;
using Bmb.Payment.Controllers.Contracts;
using Bmb.Payment.Domain.ValueObjects;
using Bmb.Payment.MercadoPago.Gateway.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Payment.Api/Mappers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bmb.Payment.Api.Model;
using Bmb.Payment.Controllers.Dto;
using PaymentType = Bmb.Domain.Core.ValueObjects.PaymentType;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Api;

Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Payment.Application/Bmb.Payment.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bmb.Payment.Core\Bmb.Payment.Core.csproj" />
<ProjectReference Include="..\Bmb.Payment.Domain\Bmb.Payment.Domain.csproj" />
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions src/Bmb.Payment.Application/UseCases/CreatePaymentUseCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using Bmb.Domain.Core.Events;
using Bmb.Domain.Core.Events.Notifications;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Core;
using Bmb.Payment.Core.Contracts;
using Bmb.Payment.Domain;
using Bmb.Payment.Domain.Contracts;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Application.UseCases;

Expand All @@ -22,7 +23,7 @@ public CreatePaymentUseCase(IPaymentGatewayFactoryMethod paymentGatewayFactory,
_dispatcher = dispatcher;
}

public async Task<Bmb.Domain.Core.Entities.Payment?> Execute(Guid orderId, PaymentType paymentType)
public async Task<Domain.Entities.Payment?> Execute(Guid orderId, PaymentType paymentType)
{
var order = await _ordersGateway.GetCopyAsync(orderId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Bmb.Domain.Core.ValueObjects;

namespace Bmb.Payment.Application.UseCases;

public interface ICreatePaymentUseCase
{
Task<Bmb.Domain.Core.Entities.Payment?> Execute(Guid orderId, PaymentType paymentType);
Task<Domain.Entities.Payment?> Execute(Guid orderId, Domain.ValueObjects.PaymentType paymentType);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Application.UseCases;

public interface IUpdatePaymentStatusUseCase
{
Task<bool> Execute(Bmb.Domain.Core.Entities.Payment? payment, PaymentStatus status);
Task<bool> Execute(Domain.Entities.Payment? payment, PaymentStatus status);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bmb.Domain.Core.Events;
using Bmb.Domain.Core.Events.Notifications;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Core.Contracts;
using Bmb.Payment.Domain.Contracts;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Application.UseCases;

Expand All @@ -16,7 +16,7 @@ public UpdatePaymentStatusUseCase(IPaymentRepository paymentRepository, IDispatc
_dispatcher = dispatcher;
}

public async Task<bool> Execute(Bmb.Domain.Core.Entities.Payment? payment, PaymentStatus status)
public async Task<bool> Execute(Domain.Entities.Payment? payment, PaymentStatus status)
{
if (payment is not null && payment.Status
is not PaymentStatus.Approved
Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Payment.Controllers/Contracts/IPaymentService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Controllers.Dto;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Controllers.Contracts;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Controllers.Dto;

Expand Down
4 changes: 2 additions & 2 deletions src/Bmb.Payment.Controllers/PaymentGatewayFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bmb.Domain.Core.Base;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Core.Contracts;
using Bmb.Payment.Domain.Contracts;
using Bmb.Payment.Domain.ValueObjects;
using Microsoft.Extensions.DependencyInjection;

namespace Bmb.Payment.Controllers;
Expand Down
3 changes: 2 additions & 1 deletion src/Bmb.Payment.Controllers/PaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using Bmb.Payment.Application.UseCases;
using Bmb.Payment.Controllers.Contracts;
using Bmb.Payment.Controllers.Dto;
using Bmb.Payment.Core.Contracts;
using Bmb.Payment.Domain.Contracts;
using Bmb.Payment.Domain.ValueObjects;

namespace Bmb.Payment.Controllers;

Expand Down
88 changes: 2 additions & 86 deletions src/Bmb.Payment.Controllers/Presenter.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
using Bmb.Domain.Core.Entities;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Payment.Controllers.Dto;
using Bmb.Payment.Controllers.Dto;

namespace Bmb.Payment.Controllers;

public static class Presenter
{
// public static CustomerDto FromEntityToDto(this Customer customer)
// {
// if (customer is null) return null;
//
// return new CustomerDto
// {
// Id = customer.Id,
// Cpf = customer.Cpf,
// Name = customer.Name,
// Email = customer.Email
// };
// }

// public static ProductDto FromEntityToDto(this Product product)
// {
// return new ProductDto
// {
// Id = product.Id,
// Name = product.Name,
// Description = product.Description,
// Category = product.Category.FromEntityToDto(),
// Price = product.Price,
// Images = product.Images.ToArray()
// };
// }

// public static IReadOnlyCollection<ProductDto> FromEntityToDto(this IEnumerable<Product> products)
// {
// return products.Select(p => p.FromEntityToDto()).ToList();
// }

// public static ProductCategoryDto FromEntityToDto(this ProductCategory category)
// {
// return (ProductCategoryDto)category;
// }

public static PaymentDto FromEntityToDto(this Domain.Core.Entities.Payment payment)
public static PaymentDto FromEntityToDto(this Domain.Entities.Payment payment)
{
return new PaymentDto
{
Expand All @@ -55,50 +17,4 @@ public static PaymentDto FromEntityToDto(this Domain.Core.Entities.Payment payme
QrCode = payment.QrCode
};
}

// public static OrderListItemDto FromEntityToListDto(this Order order)
// {
// return new OrderListItemDto(order.Id, order.TrackingCode.Value, order.Total,
// (OrderStatusDto)order.Status,
// order.Created,
// order.Updated);
// }

// public static IReadOnlyCollection<OrderListItemDto> FromDomainToDto(this IEnumerable<Order> orders)
// {
// return orders.Select(o => o.FromEntityToListDto()).ToList();
// }

// public static OrderDetailDto? FromEntityToDto(this Order? order)
// {
// if (order is null) return null;
// return new OrderDetailDto
// {
// Id = order.Id,
// TrackingCode = order.TrackingCode.Value,
// Total = order.Total,
// Status = (OrderStatusDto)order.Status,
// CreationDate = order.Created,
// LastUpdate = order.Updated,
// OrderItems = order.OrderItems.Select(o => o.FromEntityToDto()).ToList(),
// Customer = order.Customer is null ? null : order.Customer!.FromEntityToDto()
// };
// }

// public static OrderItemDto FromEntityToDto(this OrderItem orderItem)
// {
// return new OrderItemDto()
// {
// OrderId = orderItem.OrderId,
// ProductId = orderItem.ProductId,
// Quantity = orderItem.Quantity,
// UnitPrice = orderItem.UnitPrice,
// ProductName = orderItem.ProductName
// };
// }

// public static NewOrderDto FromEntityToCreatedDto(this Order order)
// {
// return new NewOrderDto(order.Id, order.TrackingCode.Value);
// }
}
10 changes: 0 additions & 10 deletions src/Bmb.Payment.Core/Contracts/IPaymentGateway.cs

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions src/Bmb.Payment.Core/Contracts/IPaymentRepository.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Bmb.Payment.DI/ServiceCollectionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Bmb.Orders.Gateway;
using Bmb.Payment.Application;
using Bmb.Payment.Controllers;
using Bmb.Payment.Core.Contracts;
using Bmb.Payment.Domain.Contracts;
using Bmb.Payment.DI.HealthChecks;
using Bmb.Payment.FakePayment.Gateway;
using Bmb.Payment.MercadoPago.Gateway;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bmb.Domain.Core" Version="0.0.9" />
<PackageReference Include="Bmb.Domain.Core" Version="0.0.14" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions src/Bmb.Payment.Domain/Contracts/IPaymentGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Bmb.Domain.Core.ValueObjects;
using PaymentStatus = Bmb.Payment.Domain.ValueObjects.PaymentStatus;
using ValueObjects_PaymentStatus = Bmb.Payment.Domain.ValueObjects.PaymentStatus;

namespace Bmb.Payment.Domain.Contracts;

public interface IPaymentGateway
{
Task<Entities.Payment> CreatePaymentAsync(OrderDto order);

Task<ValueObjects_PaymentStatus?> GetPaymentStatusAsync(string paymentId);
}
10 changes: 10 additions & 0 deletions src/Bmb.Payment.Domain/Contracts/IPaymentGatewayFactoryMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Bmb.Domain.Core.ValueObjects;
using PaymentType = Bmb.Payment.Domain.ValueObjects.PaymentType;
using ValueObjects_PaymentType = Bmb.Payment.Domain.ValueObjects.PaymentType;

namespace Bmb.Payment.Domain.Contracts;

public interface IPaymentGatewayFactoryMethod
{
IPaymentGateway Create(ValueObjects_PaymentType paymentType);
}
16 changes: 16 additions & 0 deletions src/Bmb.Payment.Domain/Contracts/IPaymentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Bmb.Domain.Core.ValueObjects;
using PaymentType = Bmb.Payment.Domain.ValueObjects.PaymentType;
using ValueObjects_PaymentType = Bmb.Payment.Domain.ValueObjects.PaymentType;

namespace Bmb.Payment.Domain.Contracts;

public interface IPaymentRepository
{
Task<Entities.Payment> SaveAsync(Entities.Payment payment);

Task<Entities.Payment?> GetPaymentAsync(PaymentId paymentId);

Task<Entities.Payment?> GetPaymentAsync(string externalReference, ValueObjects_PaymentType paymentType);

Task<bool> UpdatePaymentStatusAsync(Entities.Payment payment);
}
Loading

0 comments on commit 32b895a

Please sign in to comment.