feat(wallet): add manual credit wallet charge functionality and update Protobuf definitions
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Introduced ManualCreditWalletCharge enum value to TransactionType for clarity. - Added AdminManualCreditCharge and GetManualCreditCharges RPC methods in UserWalletService for handling manual credit charges by admin. - Created corresponding request and response messages for manual credit charge operations in Protobuf. - Updated Protobuf project version to reflect the addition of new features.
This commit is contained in:
@@ -9,6 +9,9 @@ using CMSMicroservice.Application.WalletCQ.Commands.ChargeCreditWallet;
|
||||
using CMSMicroservice.Application.WalletCQ.Commands.VerifyMagicWalletCharge;
|
||||
using CMSMicroservice.Application.WalletCQ.Commands.VerifyDiscountWalletCharge;
|
||||
using CMSMicroservice.Application.WalletCQ.Commands.VerifyCreditWalletCharge;
|
||||
using CMSMicroservice.Application.WalletCQ.Commands.AdminManualCreditCharge;
|
||||
using CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges;
|
||||
using AppManualChargeFilter = CMSMicroservice.Application.WalletCQ.Queries.GetManualCreditCharges.GetManualCreditChargesFilter;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetUserWallet;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetAllUserWalletByFilter;
|
||||
using CMSMicroservice.Application.UserWalletCQ.Queries.GetCustomerWalletHistory;
|
||||
@@ -518,4 +521,116 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
MinWithdrawalAmount = settings.MinWithdrawalAmount
|
||||
};
|
||||
}
|
||||
|
||||
// ============= Admin Manual Credit Charge =============
|
||||
|
||||
public override async Task<AdminManualCreditChargeResponse> AdminManualCreditCharge(
|
||||
AdminManualCreditChargeRequest request, ServerCallContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _sender.Send(new AdminManualCreditChargeCommand
|
||||
{
|
||||
UserId = request.UserId,
|
||||
Amount = request.Amount,
|
||||
Note = request.Note,
|
||||
PerformedByAdminId = _currentUserService.GetPerformedBy()
|
||||
}, context.CancellationToken);
|
||||
|
||||
return new AdminManualCreditChargeResponse
|
||||
{
|
||||
Success = result.Success,
|
||||
Message = result.Message ?? string.Empty,
|
||||
TransactionId = result.TransactionId,
|
||||
NewBalance = result.NewBalance
|
||||
};
|
||||
}
|
||||
catch (PaymentInProgressException ex)
|
||||
{
|
||||
return new AdminManualCreditChargeResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
return new AdminManualCreditChargeResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "AdminManualCreditCharge failed for UserId={UserId}", request.UserId);
|
||||
return new AdminManualCreditChargeResponse
|
||||
{
|
||||
Success = false,
|
||||
Message = ex.Message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task<GetManualCreditChargesResponse> GetManualCreditCharges(
|
||||
GetManualCreditChargesRequest request, ServerCallContext context)
|
||||
{
|
||||
var result = await _sender.Send(new GetManualCreditChargesQuery
|
||||
{
|
||||
SortBy = request.SortBy,
|
||||
PaginationState = request.PaginationState != null
|
||||
? new Application.Common.Models.PaginationState
|
||||
{
|
||||
PageNumber = request.PaginationState.PageNumber,
|
||||
PageSize = request.PaginationState.PageSize
|
||||
}
|
||||
: new Application.Common.Models.PaginationState { PageNumber = 1, PageSize = 20 },
|
||||
Filter = new AppManualChargeFilter
|
||||
{
|
||||
UserId = request.Filter?.UserId,
|
||||
TransactionId = request.Filter?.TransactionId,
|
||||
RefId = request.Filter?.RefId,
|
||||
CreatedFrom = request.Filter?.CreatedFrom?.ToDateTime(),
|
||||
CreatedTo = request.Filter?.CreatedTo?.ToDateTime()
|
||||
}
|
||||
}, context.CancellationToken);
|
||||
|
||||
var response = new GetManualCreditChargesResponse
|
||||
{
|
||||
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
|
||||
{
|
||||
CurrentPage = result.MetaData.CurrentPage,
|
||||
TotalPage = result.MetaData.TotalPage,
|
||||
PageSize = result.MetaData.PageSize,
|
||||
TotalCount = result.MetaData.TotalCount,
|
||||
HasPrevious = result.MetaData.HasPrevious,
|
||||
HasNext = result.MetaData.HasNext
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var m in result.Models)
|
||||
{
|
||||
var model = new ManualCreditChargeModel
|
||||
{
|
||||
TransactionId = m.TransactionId,
|
||||
UserId = m.UserId,
|
||||
UserName = m.UserName ?? string.Empty,
|
||||
Amount = m.Amount,
|
||||
Description = m.Description ?? string.Empty,
|
||||
RefId = m.RefId ?? string.Empty,
|
||||
NewBalance = m.NewBalance,
|
||||
Created = Timestamp.FromDateTime(DateTime.SpecifyKind(m.Created, DateTimeKind.Utc))
|
||||
};
|
||||
|
||||
if (m.PaymentDate.HasValue)
|
||||
{
|
||||
model.PaymentDate = Timestamp.FromDateTime(
|
||||
DateTime.SpecifyKind(m.PaymentDate.Value, DateTimeKind.Utc));
|
||||
}
|
||||
|
||||
response.Models.Add(model);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user