Handle basket deletion failedv1.0.0 · JSON Schema
Reports Finance's failed basket-cleanup outcome so Order API can soft-delete the affected Order.
1. Compensate Order When Basket Cleanup Fails
When Basket API emits BasketDeletedFailedIntegrationEvent (or checkout saga compensation runs), Finance publishes DeleteBasketFailedCommand so Ordering API soft-deletes the order.
Payload details
id: UUIDv7 generated byIntegrationEvent(Guid.CreateVersion7()).creationDate: UTC ISO 8601 timestamp (DateTime.UtcNow).basketId: UUID of the basket whose cleanup failed.email: Customer email (string | null).orderId: UUID of the affected order (Kafka partition key).totalMoney: Order total (decimal).
Example payload
{ "id": "01960a1b-8a02-7b00-8a9b-0c1d2e3f4f02", "creationDate": "2026-11-25T16:15:03Z", "basketId": "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a01", "email": "minh.nguyen@bookworm.dev", "orderId": "01960a1b-3c4d-7e00-8a9b-0c1d2e3f4a99", "totalMoney": 59.98}Using this example
Ordering API idempotently soft-deletes the order in PostgreSQL so the failed checkout does not leave a dangling active order.
using BookWorm.Chassis.EventBus;using BookWorm.Chassis.EventBus.Idempotency;using BookWorm.Contracts;using Wolverine;using Wolverine.Attributes;
// Integration command contract (BookWorm.Contracts)[IntegrationMessageOwner(ServiceName = Services.Finance, TopicName = "delete-basket-failed")][MessageIdentity("BookWorm.Contracts.DeleteBasketFailedCommand")]public sealed record DeleteBasketFailedCommand( Guid BasketId, string? Email, Guid OrderId, decimal TotalMoney) : IntegrationEvent;
// 1. Publishing from Finance Durable Functions compensation activity via Wolverine IMessageBusawait bus.PublishAsync( new DeleteBasketFailedCommand( Guid.Parse("01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a01"), "minh.nguyen@bookworm.dev", Guid.Parse("01960a1b-3c4d-7e00-8a9b-0c1d2e3f4a99"), 59.98m ));
// 2. Consuming in Ordering API with Wolverine + IIntegrationEventIdempotencyGuardinternal sealed class DeleteBasketFailedCommandHandler( IOrderRepository repository, IIntegrationEventIdempotencyGuard idempotencyGuard){ [WolverineHandler] public async Task Handle(DeleteBasketFailedCommand command, CancellationToken cancellationToken) { await idempotencyGuard.ExecuteAsync( command.Id, nameof(DeleteBasketFailedCommandHandler), async ct => { var order = await repository.GetByIdAsync(command.OrderId, ct); if (order is not null) { order.Delete(); await repository.UnitOfWork.SaveEntitiesAsync(ct); } }, cancellationToken: cancellationToken ); }}1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "DeleteBasketFailedCommand",
4 "type": "object",
5 "additionalProperties": false,
6 "required": ["id", "creationDate", "basketId", "email", "orderId", "totalMoney"],
7 "properties": {
8 "id": {
9 "type": "string",
10 "format": "uuid",
11 "description": "Unique identifier assigned to the integration message."
12 },
13 "creationDate": {
14 "type": "string",
15 "format": "date-time",
16 "description": "UTC timestamp when the integration message was created."
17 },
18 "basketId": {
19 "type": "string",
20 "format": "uuid",
21 "description": "Identifier of the basket whose cleanup failed."
22 },
23 "email": {
24 "type": ["string", "null"],
25 "format": "email",
26 "description": "Customer email, when available."
27 },
28 "orderId": {
29 "type": "string",
30 "format": "uuid",
31 "description": "Identifier of the affected Order."
32 },
33 "totalMoney": {
34 "type": "number",
35 "format": "double",
36 "description": "Total purchase amount associated with the Order."
37 }
38 }
39}
40