forked from xiongyuxing/tiku-backend.net
feat(saas): implement marketplace and tenant onboarding
This commit is contained in:
45
Tiku.Api/Controllers/PlatformBillingCallbackController.cs
Normal file
45
Tiku.Api/Controllers/PlatformBillingCallbackController.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Tiku.Application.PlatformBilling;
|
||||
|
||||
namespace Tiku.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/platform-billing/callbacks")]
|
||||
public sealed class PlatformBillingCallbackController(
|
||||
IPlatformBillingNotificationService notificationService) : ControllerBase
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[HttpPost("{provider}")]
|
||||
public async Task<IActionResult> Notify(string provider, CancellationToken cancellationToken)
|
||||
{
|
||||
Request.EnableBuffering();
|
||||
using var reader = new StreamReader(Request.Body, Encoding.UTF8, leaveOpen: true);
|
||||
var rawBody = await reader.ReadToEndAsync(cancellationToken);
|
||||
Request.Body.Position = 0;
|
||||
JsonElement body;
|
||||
try
|
||||
{
|
||||
body = string.IsNullOrWhiteSpace(rawBody)
|
||||
? JsonDocument.Parse("{}").RootElement.Clone()
|
||||
: JsonDocument.Parse(rawBody).RootElement.Clone();
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
body = JsonDocument.Parse("{}").RootElement.Clone();
|
||||
}
|
||||
var normalizedProvider = provider.Trim().ToLowerInvariant().Replace('-', '_');
|
||||
await notificationService.ProcessAsync(new PlatformBillingNotification(
|
||||
normalizedProvider,
|
||||
Request.Headers.ToDictionary(value => value.Key, value => value.Value.ToString(), StringComparer.OrdinalIgnoreCase),
|
||||
rawBody,
|
||||
body), cancellationToken);
|
||||
if (normalizedProvider is "alipay" or "ali_pay")
|
||||
{
|
||||
return Content("success", "text/plain", Encoding.UTF8);
|
||||
}
|
||||
return Ok(new { code = "SUCCESS", message = "成功" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user