From d1efcdede83cf08fc5a9aa38e7064713abb2c341 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 5 Oct 2025 15:52:54 +0800 Subject: [PATCH] :sparkles: Transfer fee and pin validate --- DysonNetwork.Pass/Wallet/PaymentService.cs | 13 +++++++++++++ DysonNetwork.Pass/Wallet/WalletController.cs | 19 ++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/DysonNetwork.Pass/Wallet/PaymentService.cs b/DysonNetwork.Pass/Wallet/PaymentService.cs index c7e997a..6b0681f 100644 --- a/DysonNetwork.Pass/Wallet/PaymentService.cs +++ b/DysonNetwork.Pass/Wallet/PaymentService.cs @@ -439,6 +439,19 @@ public class PaymentService( throw new InvalidOperationException($"Payee wallet not found for account {payeeAccountId}"); } + // Calculate transfer fee (5%) + decimal fee = Math.Round(amount * 0.05m, 2); + + // Create fee transaction (to system) + await CreateTransactionAsync( + payerWallet.Id, + null, + currency, + fee, + $"Transfer fee for transfer from account {payerAccountId} to {payeeAccountId}", + Shared.Models.TransactionType.System); + + // Create main transfer transaction return await CreateTransactionAsync( payerWallet.Id, payeeWallet.Id, diff --git a/DysonNetwork.Pass/Wallet/WalletController.cs b/DysonNetwork.Pass/Wallet/WalletController.cs index ff05a4f..cc2246a 100644 --- a/DysonNetwork.Pass/Wallet/WalletController.cs +++ b/DysonNetwork.Pass/Wallet/WalletController.cs @@ -183,6 +183,7 @@ public class WalletController(AppDatabase db, WalletService ws, PaymentService p [Required] public decimal Amount { get; set; } [Required] public string Currency { get; set; } = null!; [Required] public Guid PayeeAccountId { get; set; } + [Required] public string PinCode { get; set; } = null!; } [HttpPost("balance")] @@ -218,23 +219,19 @@ public class WalletController(AppDatabase db, WalletService ws, PaymentService p { if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); - var payerWallet = await ws.GetWalletAsync(currentUser.Id); - if (payerWallet is null) return NotFound("Your wallet was not found, please create one first."); - - var payeeWallet = await ws.GetWalletAsync(request.PayeeAccountId); - if (payeeWallet is null) return NotFound("Payee wallet was not found."); + // Validate PIN code + if (!await auth.ValidatePinCode(currentUser.Id, request.PinCode)) + return StatusCode(403, "Invalid PIN Code"); if (currentUser.Id == request.PayeeAccountId) return BadRequest("Cannot transfer to yourself."); try { - var transaction = await payment.CreateTransactionAsync( - payerWalletId: payerWallet.Id, - payeeWalletId: payeeWallet.Id, + var transaction = await payment.TransferAsync( + payerAccountId: currentUser.Id, + payeeAccountId: request.PayeeAccountId, currency: request.Currency, - amount: request.Amount, - remarks: request.Remark ?? $"Transfer from {currentUser.Id} to {request.PayeeAccountId}", - type: TransactionType.Transfer + amount: request.Amount ); return Ok(transaction);