♻️ Splitted wallet service
This commit is contained in:
@@ -293,3 +293,41 @@ message TransferRequest {
|
||||
message GetWalletFundRequest {
|
||||
string fund_id = 1;
|
||||
}
|
||||
|
||||
service SubscriptionService {
|
||||
rpc GetSubscription(GetSubscriptionRequest) returns (Subscription);
|
||||
rpc GetPerkSubscription(GetPerkSubscriptionRequest) returns (Subscription);
|
||||
rpc GetPerkSubscriptions(GetPerkSubscriptionsRequest) returns (GetPerkSubscriptionsResponse);
|
||||
rpc CreateSubscription(CreateSubscriptionRequest) returns (Subscription);
|
||||
rpc CancelSubscription(CancelSubscriptionRequest) returns (Subscription);
|
||||
}
|
||||
|
||||
message GetSubscriptionRequest {
|
||||
string account_id = 1;
|
||||
string identifier = 2;
|
||||
}
|
||||
|
||||
message GetPerkSubscriptionRequest {
|
||||
string account_id = 1;
|
||||
}
|
||||
|
||||
message GetPerkSubscriptionsRequest {
|
||||
repeated string account_ids = 1;
|
||||
}
|
||||
|
||||
message GetPerkSubscriptionsResponse {
|
||||
repeated Subscription subscriptions = 1;
|
||||
}
|
||||
|
||||
message CreateSubscriptionRequest {
|
||||
string account_id = 1;
|
||||
string identifier = 2;
|
||||
string payment_method = 3;
|
||||
optional string coupon_code = 4;
|
||||
bool is_free_trial = 5;
|
||||
}
|
||||
|
||||
message CancelSubscriptionRequest {
|
||||
string account_id = 1;
|
||||
string identifier = 2;
|
||||
}
|
||||
|
||||
142
DysonNetwork.Shared/Registry/RemotePaymentService.cs
Normal file
142
DysonNetwork.Shared/Registry/RemotePaymentService.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace DysonNetwork.Shared.Registry;
|
||||
|
||||
public class RemotePaymentService(DysonNetwork.Shared.Proto.PaymentService.PaymentServiceClient payment)
|
||||
{
|
||||
public async Task<DysonNetwork.Shared.Proto.Order> CreateOrder(
|
||||
string currency,
|
||||
string amount,
|
||||
string? payeeWalletId = null,
|
||||
TimeSpan? expiration = null,
|
||||
string? appIdentifier = null,
|
||||
string? productIdentifier = null,
|
||||
byte[]? meta = null,
|
||||
string? remarks = null,
|
||||
bool reuseable = false)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.CreateOrderRequest
|
||||
{
|
||||
Currency = currency,
|
||||
Amount = amount,
|
||||
Reuseable = reuseable
|
||||
};
|
||||
|
||||
if (payeeWalletId != null)
|
||||
request.PayeeWalletId = payeeWalletId;
|
||||
|
||||
if (expiration.HasValue)
|
||||
request.Expiration = Duration.FromTimeSpan(expiration.Value);
|
||||
|
||||
if (appIdentifier != null)
|
||||
request.AppIdentifier = appIdentifier;
|
||||
|
||||
if (productIdentifier != null)
|
||||
request.ProductIdentifier = productIdentifier;
|
||||
|
||||
if (meta != null)
|
||||
request.Meta = ByteString.CopyFrom(meta);
|
||||
|
||||
if (remarks != null)
|
||||
request.Remarks = remarks;
|
||||
|
||||
var response = await payment.CreateOrderAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.Transaction> CreateTransaction(
|
||||
string? payerWalletId,
|
||||
string? payeeWalletId,
|
||||
string currency,
|
||||
string amount,
|
||||
string? remarks = null,
|
||||
DysonNetwork.Shared.Proto.TransactionType type = DysonNetwork.Shared.Proto.TransactionType.Unspecified)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.CreateTransactionRequest
|
||||
{
|
||||
Currency = currency,
|
||||
Amount = amount,
|
||||
Type = type
|
||||
};
|
||||
|
||||
if (payerWalletId != null)
|
||||
request.PayerWalletId = payerWalletId;
|
||||
|
||||
if (payeeWalletId != null)
|
||||
request.PayeeWalletId = payeeWalletId;
|
||||
|
||||
if (remarks != null)
|
||||
request.Remarks = remarks;
|
||||
|
||||
var response = await payment.CreateTransactionAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.Transaction> CreateTransactionWithAccount(
|
||||
string? payerAccountId,
|
||||
string? payeeAccountId,
|
||||
string currency,
|
||||
string amount,
|
||||
string? remarks = null,
|
||||
DysonNetwork.Shared.Proto.TransactionType type = DysonNetwork.Shared.Proto.TransactionType.Unspecified)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.CreateTransactionWithAccountRequest
|
||||
{
|
||||
Currency = currency,
|
||||
Amount = amount,
|
||||
Type = type
|
||||
};
|
||||
|
||||
if (payerAccountId != null)
|
||||
request.PayerAccountId = payerAccountId;
|
||||
|
||||
if (payeeAccountId != null)
|
||||
request.PayeeAccountId = payeeAccountId;
|
||||
|
||||
if (remarks != null)
|
||||
request.Remarks = remarks;
|
||||
|
||||
var response = await payment.CreateTransactionWithAccountAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.Transaction> Transfer(
|
||||
Guid payerAccountId,
|
||||
Guid payeeAccountId,
|
||||
string currency,
|
||||
string amount)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.TransferRequest
|
||||
{
|
||||
PayerAccountId = payerAccountId.ToString(),
|
||||
PayeeAccountId = payeeAccountId.ToString(),
|
||||
Currency = currency,
|
||||
Amount = amount
|
||||
};
|
||||
|
||||
var response = await payment.TransferAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.Order> CancelOrder(string orderId)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.CancelOrderRequest { OrderId = orderId };
|
||||
var response = await payment.CancelOrderAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.RefundOrderResponse> RefundOrder(string orderId)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.RefundOrderRequest { OrderId = orderId };
|
||||
var response = await payment.RefundOrderAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<DysonNetwork.Shared.Proto.WalletFund> GetWalletFund(string fundId)
|
||||
{
|
||||
var request = new DysonNetwork.Shared.Proto.GetWalletFundRequest { FundId = fundId };
|
||||
var response = await payment.GetWalletFundAsync(request);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
65
DysonNetwork.Shared/Registry/RemoteSubscriptionService.cs
Normal file
65
DysonNetwork.Shared/Registry/RemoteSubscriptionService.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using DysonNetwork.Shared.Proto;
|
||||
|
||||
namespace DysonNetwork.Shared.Registry;
|
||||
|
||||
public class RemoteSubscriptionService(SubscriptionService.SubscriptionServiceClient subscription)
|
||||
{
|
||||
public async Task<Subscription> GetSubscription(Guid accountId, string identifier)
|
||||
{
|
||||
var request = new GetSubscriptionRequest
|
||||
{
|
||||
AccountId = accountId.ToString(),
|
||||
Identifier = identifier
|
||||
};
|
||||
var response = await subscription.GetSubscriptionAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<Subscription> GetPerkSubscription(Guid accountId)
|
||||
{
|
||||
var request = new GetPerkSubscriptionRequest { AccountId = accountId.ToString() };
|
||||
var response = await subscription.GetPerkSubscriptionAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<List<Subscription>> GetPerkSubscriptions(List<Guid> accountIds)
|
||||
{
|
||||
var request = new GetPerkSubscriptionsRequest();
|
||||
request.AccountIds.AddRange(accountIds.Select(id => id.ToString()));
|
||||
var response = await subscription.GetPerkSubscriptionsAsync(request);
|
||||
return response.Subscriptions.ToList();
|
||||
}
|
||||
|
||||
public async Task<Subscription> CreateSubscription(
|
||||
Guid accountId,
|
||||
string identifier,
|
||||
string paymentMethod,
|
||||
string? couponCode = null,
|
||||
bool isFreeTrial = false)
|
||||
{
|
||||
var request = new CreateSubscriptionRequest
|
||||
{
|
||||
AccountId = accountId.ToString(),
|
||||
Identifier = identifier,
|
||||
PaymentMethod = paymentMethod,
|
||||
IsFreeTrial = isFreeTrial
|
||||
};
|
||||
|
||||
if (couponCode != null)
|
||||
request.CouponCode = couponCode;
|
||||
|
||||
var response = await subscription.CreateSubscriptionAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<Subscription> CancelSubscription(Guid accountId, string identifier)
|
||||
{
|
||||
var request = new CancelSubscriptionRequest
|
||||
{
|
||||
AccountId = accountId.ToString(),
|
||||
Identifier = identifier
|
||||
};
|
||||
var response = await subscription.CancelSubscriptionAsync(request);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
37
DysonNetwork.Shared/Registry/RemoteWalletService.cs
Normal file
37
DysonNetwork.Shared/Registry/RemoteWalletService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using DysonNetwork.Shared.Proto;
|
||||
|
||||
namespace DysonNetwork.Shared.Registry;
|
||||
|
||||
public class RemoteWalletService(WalletService.WalletServiceClient wallet)
|
||||
{
|
||||
public async Task<Wallet> GetWallet(Guid accountId)
|
||||
{
|
||||
var request = new GetWalletRequest { AccountId = accountId.ToString() };
|
||||
var response = await wallet.GetWalletAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<Wallet> CreateWallet(Guid accountId)
|
||||
{
|
||||
var request = new CreateWalletRequest { AccountId = accountId.ToString() };
|
||||
var response = await wallet.CreateWalletAsync(request);
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<WalletPocket> GetOrCreateWalletPocket(Guid walletId, string currency, decimal? initialAmount = null)
|
||||
{
|
||||
var request = new GetOrCreateWalletPocketRequest
|
||||
{
|
||||
WalletId = walletId.ToString(),
|
||||
Currency = currency
|
||||
};
|
||||
|
||||
if (initialAmount.HasValue)
|
||||
{
|
||||
request.InitialAmount = initialAmount.Value.ToString();
|
||||
}
|
||||
|
||||
var response = await wallet.GetOrCreateWalletPocketAsync(request);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,26 @@ public static class ServiceInjectionHelper
|
||||
return services;
|
||||
}
|
||||
|
||||
public IServiceCollection AddWalletService()
|
||||
{
|
||||
services.AddGrpcClientWithSharedChannel<WalletService.WalletServiceClient>(
|
||||
"https://_grpc.wallet",
|
||||
"WalletService");
|
||||
services.AddSingleton<RemoteWalletService>();
|
||||
|
||||
services.AddGrpcClientWithSharedChannel<PaymentService.PaymentServiceClient>(
|
||||
"https://_grpc.wallet",
|
||||
"PaymentService");
|
||||
services.AddSingleton<RemotePaymentService>();
|
||||
|
||||
services.AddGrpcClientWithSharedChannel<SubscriptionService.SubscriptionServiceClient>(
|
||||
"https://_grpc.wallet",
|
||||
"SubscriptionService");
|
||||
services.AddSingleton<RemoteSubscriptionService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public IServiceCollection AddDriveService()
|
||||
{
|
||||
services.AddGrpcClientWithSharedChannel<FileService.FileServiceClient>(
|
||||
|
||||
Reference in New Issue
Block a user