♻️ Move in-app wallet buy stellar program order confirm logic
This commit is contained in:
@@ -15,19 +15,40 @@ public class BroadcastEventHandler(
|
|||||||
{
|
{
|
||||||
await foreach (var msg in nats.SubscribeAsync<byte[]>(PaymentOrderEvent.Type, cancellationToken: stoppingToken))
|
await foreach (var msg in nats.SubscribeAsync<byte[]>(PaymentOrderEvent.Type, cancellationToken: stoppingToken))
|
||||||
{
|
{
|
||||||
|
PaymentOrderEvent? evt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var evt = JsonSerializer.Deserialize<PaymentOrderEvent>(msg.Data);
|
evt = JsonSerializer.Deserialize<PaymentOrderEvent>(msg.Data);
|
||||||
|
|
||||||
if (evt?.ProductIdentifier is null || !evt.ProductIdentifier.StartsWith(SubscriptionType.StellarProgram))
|
if (evt?.ProductIdentifier is null ||
|
||||||
|
!evt.ProductIdentifier.StartsWith(SubscriptionType.StellarProgram))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
logger.LogInformation("Stellar program order paid: {OrderId}", evt.OrderId);
|
logger.LogInformation("Handling stellar program order: {OrderId}", evt.OrderId);
|
||||||
|
|
||||||
|
await using var scope = serviceProvider.CreateAsyncScope();
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<AppDatabase>();
|
||||||
|
var subscriptions = scope.ServiceProvider.GetRequiredService<SubscriptionService>();
|
||||||
|
|
||||||
|
var order = await db.PaymentOrders.FindAsync(
|
||||||
|
[evt.OrderId],
|
||||||
|
cancellationToken: stoppingToken
|
||||||
|
);
|
||||||
|
if (order is null)
|
||||||
|
{
|
||||||
|
logger.LogWarning("Order with ID {OrderId} not found.", evt.OrderId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await subscriptions.HandleSubscriptionOrder(order);
|
||||||
|
|
||||||
|
logger.LogInformation("Subscription for order {OrderId} handled successfully.", evt.OrderId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "Error processing AccountDeleted");
|
logger.LogError(ex, "Error processing payment order event for order {OrderId}", evt?.OrderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -150,29 +150,6 @@ public class SubscriptionController(SubscriptionService subscriptions, AfdianPay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubscriptionOrderRequest
|
|
||||||
{
|
|
||||||
[Required] public Guid OrderId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("order/handle")]
|
|
||||||
[Authorize]
|
|
||||||
public async Task<ActionResult<Subscription>> HandleSubscriptionOrder([FromBody] SubscriptionOrderRequest request)
|
|
||||||
{
|
|
||||||
var order = await db.PaymentOrders.FindAsync(request.OrderId);
|
|
||||||
if (order is null) return NotFound($"Order with ID {request.OrderId} was not found.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var subscription = await subscriptions.HandleSubscriptionOrder(order);
|
|
||||||
return subscription;
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException ex)
|
|
||||||
{
|
|
||||||
return BadRequest(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RestorePurchaseRequest
|
public class RestorePurchaseRequest
|
||||||
{
|
{
|
||||||
[Required] public string OrderId { get; set; } = null!;
|
[Required] public string OrderId { get; set; } = null!;
|
||||||
|
Reference in New Issue
Block a user