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

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Controllers;
using Tiku.Application.Assets;
using Tiku.Application.Auth;
using Tiku.Application.Commerce;
using Tiku.Application.Content;
using Tiku.Application.Storage;
using Tiku.Infrastructure.Content;
@@ -172,6 +173,26 @@ public sealed class ExceptionHandlingMiddleware(
return;
}
if (exception is CommerceException commerceException)
{
await WriteProblemAsync(
context,
commerceException.Message,
CommerceStatusCode(commerceException.Code),
commerceException.Code);
return;
}
if (exception is PaymentProviderException paymentProviderException)
{
await WriteProblemAsync(
context,
paymentProviderException.Message,
CommerceStatusCode(paymentProviderException.Code),
paymentProviderException.Code);
return;
}
if (exception is ObjectStorageException storageException)
{
await WriteProblemAsync(
@@ -308,4 +329,16 @@ public sealed class ExceptionHandlingMiddleware(
_ => StatusCodes.Status400BadRequest
};
}
private static int CommerceStatusCode(string code)
{
return code switch
{
"commerce_access_denied" or "tenant_access_denied" => StatusCodes.Status403Forbidden,
"order_not_found" or "svip_plan_not_found" or "region_not_found" => StatusCodes.Status404NotFound,
"payment_provider_not_configured" or "payment_secret_not_configured" => StatusCodes.Status503ServiceUnavailable,
"order_status_invalid" => StatusCodes.Status409Conflict,
_ => StatusCodes.Status400BadRequest
};
}
}