Transfer fee and pin validate

This commit is contained in:
2025-10-05 15:52:54 +08:00
parent 47680475b3
commit d1efcdede8
2 changed files with 21 additions and 11 deletions

View File

@@ -439,6 +439,19 @@ public class PaymentService(
throw new InvalidOperationException($"Payee wallet not found for account {payeeAccountId}"); 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( return await CreateTransactionAsync(
payerWallet.Id, payerWallet.Id,
payeeWallet.Id, payeeWallet.Id,

View File

@@ -183,6 +183,7 @@ public class WalletController(AppDatabase db, WalletService ws, PaymentService p
[Required] public decimal Amount { get; set; } [Required] public decimal Amount { get; set; }
[Required] public string Currency { get; set; } = null!; [Required] public string Currency { get; set; } = null!;
[Required] public Guid PayeeAccountId { get; set; } [Required] public Guid PayeeAccountId { get; set; }
[Required] public string PinCode { get; set; } = null!;
} }
[HttpPost("balance")] [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(); if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized();
var payerWallet = await ws.GetWalletAsync(currentUser.Id); // Validate PIN code
if (payerWallet is null) return NotFound("Your wallet was not found, please create one first."); if (!await auth.ValidatePinCode(currentUser.Id, request.PinCode))
return StatusCode(403, "Invalid PIN Code");
var payeeWallet = await ws.GetWalletAsync(request.PayeeAccountId);
if (payeeWallet is null) return NotFound("Payee wallet was not found.");
if (currentUser.Id == request.PayeeAccountId) return BadRequest("Cannot transfer to yourself."); if (currentUser.Id == request.PayeeAccountId) return BadRequest("Cannot transfer to yourself.");
try try
{ {
var transaction = await payment.CreateTransactionAsync( var transaction = await payment.TransferAsync(
payerWalletId: payerWallet.Id, payerAccountId: currentUser.Id,
payeeWalletId: payeeWallet.Id, payeeAccountId: request.PayeeAccountId,
currency: request.Currency, currency: request.Currency,
amount: request.Amount, amount: request.Amount
remarks: request.Remark ?? $"Transfer from {currentUser.Id} to {request.PayeeAccountId}",
type: TransactionType.Transfer
); );
return Ok(transaction); return Ok(transaction);