feat: add commerce order and payment checkout

This commit is contained in:
xiong
2026-07-26 19:34:00 +08:00
parent 5503d7a644
commit 494039973d
8 changed files with 1045 additions and 1 deletions

View File

@@ -0,0 +1,97 @@
using System.Text.Json;
namespace Tiku.Application.Commerce;
public sealed record CommerceActor(Guid TenantId, Guid UserId);
public sealed record CreateCommerceOrderCommand(
Guid PlanId,
int Quantity,
string? PayMethod,
string? PayProvider,
Guid? RegionId,
string? CouponCode);
public sealed record CommerceOrderQuery(int? Limit = null, string? Status = null);
public sealed record CreateCommercePaymentCommand(
string OrderNo,
string Provider,
string Method,
string? OpenId,
string? ReturnUrl,
string? QuitUrl);
public sealed record CommerceOrderItem(
Guid Id,
string OrderNo,
string Status,
Guid? PlanId,
Guid? RegionId,
string? ProductType,
string? ProductName,
int AmountCents,
string Price,
string? PayMethod,
string? PayProvider,
string? TradeNo,
int? Days,
DateTimeOffset? PaidAt,
DateTimeOffset CreatedAt,
JsonElement RawPayload);
public sealed record CommerceOrderList(IReadOnlyCollection<CommerceOrderItem> Items);
public sealed record CommercePaymentItem(
Guid Id,
Guid OrderId,
string OrderNo,
string Provider,
string? Method,
string Status,
int AmountCents,
string Price,
string? ProviderTradeNo,
DateTimeOffset? PaidAt,
JsonElement ClientPayload,
JsonElement RawPayload);
public sealed record CurrentEntitlementItem(
bool IsActive,
string EntitlementType,
DateTimeOffset? StartsAt,
DateTimeOffset? ExpiresAt,
string Status,
int? DaysLeft);
public interface ICommerceService
{
Task<CommerceOrderItem> CreateOrderAsync(
CommerceActor actor,
CreateCommerceOrderCommand command,
CancellationToken cancellationToken = default);
Task<CommerceOrderList> GetOrdersAsync(
CommerceActor actor,
CommerceOrderQuery query,
CancellationToken cancellationToken = default);
Task<CommerceOrderItem> GetOrderAsync(
CommerceActor actor,
string orderNo,
CancellationToken cancellationToken = default);
Task<CommercePaymentItem> CreatePaymentAsync(
CommerceActor actor,
CreateCommercePaymentCommand command,
CancellationToken cancellationToken = default);
Task<CurrentEntitlementItem> GetCurrentEntitlementAsync(
CommerceActor actor,
CancellationToken cancellationToken = default);
}
public sealed class CommerceException(string message, string code) : Exception(message)
{
public string Code { get; } = code;
}