Refactor payment request handling to support role change top-ups
- Updated the `PaymentRequest` model to include a new `Kind` property, distinguishing between `Subscription` and `RoleChangeTopUp` requests. - Modified the `TelegramNotifier` to accommodate the new request type, ensuring accurate notifications for role change top-ups. - Enhanced the `ConfirmPaymentRequestCommandHandler` to handle role change top-ups without extending the billing period, reflecting the new payment logic. - Updated various application components and tests to support the new payment request structure and ensure proper functionality. - Revised API documentation to clarify the behavior of role change top-ups and their impact on billing.
This commit is contained in:
+42
@@ -205,6 +205,48 @@ public class ConfirmPaymentRequestCommandHandlerTests
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenRoleChangeTopUp_ConfirmsWithoutExtendingPaidUntil()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var adminId = Guid.NewGuid();
|
||||
var userId = Guid.NewGuid();
|
||||
var existingPaidUntil = DateTimeOffset.UtcNow.AddDays(20);
|
||||
var request = PaymentRequest.CreateRoleChangeTopUp(userId, 1200);
|
||||
request.MarkPaymentSent();
|
||||
dbContext.PaymentRequests.Add(request);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
_identityService
|
||||
.GetProfileAsync(userId, Arg.Any<CancellationToken>())
|
||||
.Returns(Profile(userId, paidUntil: existingPaidUntil));
|
||||
|
||||
var handler = new ConfirmPaymentRequestCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
_gateway,
|
||||
_notifier,
|
||||
_telegramNotifier,
|
||||
FakeCurrentUser.Authenticated(adminId, "admin"),
|
||||
_logger
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
new ConfirmPaymentRequestCommand(request.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(PaymentRequestStatus.Confirmed, request.Status);
|
||||
await _identityService
|
||||
.DidNotReceive()
|
||||
.ExtendBillingPaidUntilAsync(
|
||||
Arg.Any<Guid>(),
|
||||
Arg.Any<DateTimeOffset>(),
|
||||
Arg.Any<CancellationToken>()
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenRequestAlreadyDecided_ReturnsNotDecidable()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user