fix: proper DeliveryStatus mapping + cancel delivery on failed payment
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m22s

- Added MapDeliveryStatus() to correctly map Domain→Proto enum values
- Domain Pending(1) was incorrectly cast to Proto PROCESSING(1) instead of PROCESSING
- Set DeliveryStatus=Cancelled when payment fails (CompleteOrderPaymentCommandHandler)
- Set DeliveryStatus=Cancelled when order expires (ExpirePendingOrdersService)
This commit is contained in:
masoodafar-web
2026-02-17 00:41:48 +03:30
parent c2ccd32f39
commit ef1716e243
3 changed files with 15 additions and 2 deletions
@@ -105,6 +105,7 @@ public class CompleteOrderPaymentCommandHandler : IRequestHandler<CompleteOrderP
transaction.PaymentStatus = PaymentStatus.Reject; transaction.PaymentStatus = PaymentStatus.Reject;
order.PaymentStatus = PaymentStatus.Reject; order.PaymentStatus = PaymentStatus.Reject;
order.DeliveryStatus = DeliveryStatus.Cancelled;
await _context.SaveChangesAsync(cancellationToken); await _context.SaveChangesAsync(cancellationToken);
@@ -89,6 +89,7 @@ public class ExpirePendingOrdersService : BackgroundService
// تغییر وضعیت به Reject // تغییر وضعیت به Reject
order.PaymentStatus = PaymentStatus.Reject; order.PaymentStatus = PaymentStatus.Reject;
order.DeliveryStatus = DeliveryStatus.Cancelled;
// آپدیت تراکنش مربوطه // آپدیت تراکنش مربوطه
if (order.TransactionId.HasValue) if (order.TransactionId.HasValue)
@@ -93,7 +93,7 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
GatewayAmount = result.GatewayAmountPaid, GatewayAmount = result.GatewayAmountPaid,
PaymentCompleted = result.PaymentStatus == DomainEnums.PaymentStatus.Success, PaymentCompleted = result.PaymentStatus == DomainEnums.PaymentStatus.Success,
PaymentStatus = MapPaymentStatus(result.PaymentStatus), PaymentStatus = MapPaymentStatus(result.PaymentStatus),
DeliveryStatus = (DeliveryStatus)(int)result.DeliveryStatus, DeliveryStatus = MapDeliveryStatus(result.DeliveryStatus),
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(result.Created, DateTimeKind.Utc)), Created = Timestamp.FromDateTime(DateTime.SpecifyKind(result.Created, DateTimeKind.Utc)),
}; };
@@ -153,7 +153,7 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
GatewayAmount = o.GatewayAmountPaid, GatewayAmount = o.GatewayAmountPaid,
PaymentCompleted = o.PaymentStatus == DomainEnums.PaymentStatus.Success, PaymentCompleted = o.PaymentStatus == DomainEnums.PaymentStatus.Success,
PaymentStatus = MapPaymentStatus(o.PaymentStatus), PaymentStatus = MapPaymentStatus(o.PaymentStatus),
DeliveryStatus = (DeliveryStatus)(int)o.DeliveryStatus, DeliveryStatus = MapDeliveryStatus(o.DeliveryStatus),
ItemsCount = o.ItemsCount, ItemsCount = o.ItemsCount,
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(o.Created, DateTimeKind.Utc)), Created = Timestamp.FromDateTime(DateTime.SpecifyKind(o.Created, DateTimeKind.Utc)),
}; };
@@ -181,4 +181,15 @@ public class DiscountOrderService : DiscountOrderContract.DiscountOrderContractB
DomainEnums.PaymentStatus.Pending => CMSMicroservice.Protobuf.Protos.DiscountOrder.PaymentStatus.PaymentPending, DomainEnums.PaymentStatus.Pending => CMSMicroservice.Protobuf.Protos.DiscountOrder.PaymentStatus.PaymentPending,
_ => CMSMicroservice.Protobuf.Protos.DiscountOrder.PaymentStatus.PaymentPending _ => CMSMicroservice.Protobuf.Protos.DiscountOrder.PaymentStatus.PaymentPending
}; };
private static DeliveryStatus MapDeliveryStatus(DomainEnums.DeliveryStatus status) => status switch
{
DomainEnums.DeliveryStatus.None => DeliveryStatus.DeliveryPending,
DomainEnums.DeliveryStatus.Pending => DeliveryStatus.DeliveryProcessing,
DomainEnums.DeliveryStatus.InTransit => DeliveryStatus.DeliveryShipped,
DomainEnums.DeliveryStatus.Delivered => DeliveryStatus.DeliveryDelivered,
DomainEnums.DeliveryStatus.Returned => DeliveryStatus.DeliveryCancelled,
DomainEnums.DeliveryStatus.Cancelled => DeliveryStatus.DeliveryCancelled,
_ => DeliveryStatus.DeliveryPending
};
} }