🐛 Fix some issues in sepration of the Pass and Wallet service

This commit is contained in:
2026-02-04 00:04:54 +08:00
parent 9a1f36ee26
commit 148117c54a
18 changed files with 5157 additions and 158 deletions

View File

@@ -12,11 +12,9 @@ namespace DysonNetwork.Wallet.Payment;
public class OrderController(
PaymentService payment,
AppDatabase db,
IGrpcClientFactory<CustomAppService.CustomAppServiceClient> customAppsFactory
CustomAppService.CustomAppServiceClient customApps
) : ControllerBase
{
private readonly CustomAppService.CustomAppServiceClient _customApps = customAppsFactory.CreateClient();
public class CreateOrderRequest
{
public string Currency { get; set; } = null!;
@@ -33,11 +31,11 @@ public class OrderController(
[HttpPost]
public async Task<ActionResult<SnWalletOrder>> CreateOrder([FromBody] CreateOrderRequest request)
{
var clientResp = await _customApps.GetCustomAppAsync(new GetCustomAppRequest { Slug = request.ClientId });
var clientResp = await customApps.GetCustomAppAsync(new GetCustomAppRequest { Slug = request.ClientId });
if (clientResp.App is null) return BadRequest("Client not found");
var client = SnCustomApp.FromProtoValue(clientResp.App);
var secret = await _customApps.CheckCustomAppSecretAsync(new CheckCustomAppSecretRequest
var secret = await customApps.CheckCustomAppSecretAsync(new CheckCustomAppSecretRequest
{
AppId = client.Id.ToString(),
Secret = request.ClientSecret,
@@ -107,11 +105,11 @@ public class OrderController(
[HttpPatch("{id:guid}/status")]
public async Task<ActionResult<SnWalletOrder>> UpdateOrderStatus(Guid id, [FromBody] UpdateOrderStatusRequest request)
{
var clientResp = await _customApps.GetCustomAppAsync(new GetCustomAppRequest { Slug = request.ClientId });
var clientResp = await customApps.GetCustomAppAsync(new GetCustomAppRequest { Slug = request.ClientId });
if (clientResp.App is null) return BadRequest("Client not found");
var client = SnCustomApp.FromProtoValue(clientResp.App);
var secret = await _customApps.CheckCustomAppSecretAsync(new CheckCustomAppSecretRequest
var secret = await customApps.CheckCustomAppSecretAsync(new CheckCustomAppSecretRequest
{
AppId = client.Id.ToString(),
Secret = request.ClientSecret,

View File

@@ -16,13 +16,11 @@ namespace DysonNetwork.Wallet.Payment;
public class PaymentService(
AppDatabase db,
WalletService wat,
IGrpcClientFactory<RingService.RingServiceClient> pusherFactory,
RingService.RingServiceClient pusher,
IStringLocalizer<NotificationResource> localizer,
INatsConnection nats
)
{
private readonly RingService.RingServiceClient _pusher = pusherFactory.CreateClient();
public async Task<SnWalletOrder> CreateOrderAsync(
Guid? payeeWalletId,
string currency,
@@ -184,7 +182,7 @@ public class PaymentService(
var readableTransactionId = transaction.Id.ToString().Replace("-", "")[..8];
var readableTransactionRemark = transaction.Remarks ?? $"#{readableTransactionId}";
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = payerWallet.AccountId.ToString(),
@@ -211,7 +209,7 @@ public class PaymentService(
var readableTransactionId = transaction.Id.ToString().Replace("-", "")[..8];
var readableTransactionRemark = transaction.Remarks ?? $"#{readableTransactionId}";
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = payeeWallet.AccountId.ToString(),
@@ -315,7 +313,7 @@ public class PaymentService(
var readableOrderRemark = order.Remarks ?? $"#{readableOrderId}";
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = payerWallet.AccountId.ToString(),
@@ -338,7 +336,7 @@ public class PaymentService(
var readableOrderId = order.Id.ToString().Replace("-", "")[..8];
var readableOrderRemark = order.Remarks ?? $"#{readableOrderId}";
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = payeeWallet.AccountId.ToString(),

View File

@@ -17,17 +17,14 @@ namespace DysonNetwork.Wallet.Payment;
public class SubscriptionService(
AppDatabase db,
PaymentService payment,
IGrpcClientFactory<AccountService.AccountServiceClient> accountsFactory,
IGrpcClientFactory<RingService.RingServiceClient> pusherFactory,
AccountService.AccountServiceClient accounts,
RingService.RingServiceClient pusher,
IStringLocalizer<NotificationResource> localizer,
IConfiguration configuration,
ICacheService cache,
ILogger<SubscriptionService> logger
)
{
private readonly AccountService.AccountServiceClient _accounts = accountsFactory.CreateClient();
private readonly RingService.RingServiceClient _pusher = pusherFactory.CreateClient();
public async Task<SnWalletSubscription> CreateSubscriptionAsync(
SnAccount account,
string identifier,
@@ -141,14 +138,14 @@ public class SubscriptionService(
// Use GetAccount instead of LookupAccountByConnection since that method may not exist
if (Guid.TryParse(order.AccountId, out var accountId))
{
var accountProto = await _accounts.GetAccountAsync(new GetAccountRequest { Id = accountId.ToString() });
var accountProto = await accounts.GetAccountAsync(new GetAccountRequest { Id = accountId.ToString() });
if (accountProto != null)
account = SnAccount.FromProtoValue(accountProto);
}
}
else if (Guid.TryParse(order.AccountId, out var accountId))
{
var accountProto = await _accounts.GetAccountAsync(new GetAccountRequest { Id = accountId.ToString() });
var accountProto = await accounts.GetAccountAsync(new GetAccountRequest { Id = accountId.ToString() });
if (accountProto != null)
account = SnAccount.FromProtoValue(accountProto);
}
@@ -433,7 +430,7 @@ public class SubscriptionService(
}),
IsSavable = true
};
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = subscription.AccountId.ToString(),
@@ -598,7 +595,7 @@ public class SubscriptionService(
SnAccount? recipient = null;
if (recipientId.HasValue)
{
var accountProto = await _accounts.GetAccountAsync(new GetAccountRequest { Id = recipientId.Value.ToString() });
var accountProto = await accounts.GetAccountAsync(new GetAccountRequest { Id = recipientId.Value.ToString() });
if (accountProto != null)
recipient = SnAccount.FromProtoValue(accountProto);
if (recipient is null)
@@ -934,7 +931,7 @@ public class SubscriptionService(
IsSavable = true
};
await _pusher.SendPushNotificationToUserAsync(
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{
UserId = gifterId.ToString(),