Exemple #1
0
    private WithdrawResult CreateWithdrawResult()
    {
        var ledgerEntries = new List <LedgerEntryData>();

        ledgerEntries.Add(new LedgerEntryData(WithdrawalAsset, WithdrawalAmount - WithdrawalFee, LedgerEntryData.LedgerEntryType.Withdrawal));
        ledgerEntries.Add(new LedgerEntryData(WithdrawalAsset, WithdrawalFee, LedgerEntryData.LedgerEntryType.Fee));
        DateTimeOffset createdTime = new DateTimeOffset(2021, 9, 1, 6, 45, 0, new TimeSpan(-7, 0, 0));
        var            r           = new WithdrawResult(WithdrawalPaymentMethod, WithdrawalAsset, ledgerEntries, WithdrawalId, WithdrawalStatus, createdTime, WithdrawalTargetAddress, WithdrawalTransactionId);

        return(r);
    }
Exemple #2
0
 public EzWithdrawResult(
     WithdrawResult result
     )
 {
     if (result.item != null)
     {
         Item = new EzWallet(result.item);
     }
     if (result.price.HasValue)
     {
         Price = result.price.Value;
     }
 }
        public async Task <IActionResult> Withdraw([FromBody] WithdrawCommand command)
        {
            WithdrawResult result = await _handler.Execute(command);

            if (result == null)
            {
                return(new NoContentResult());
            }
            Model model = new Model(
                result.Transaction.Amount,
                result.Transaction.Description,
                result.Transaction.TransactionDate,
                result.UpdatedBalance
                );

            return(new ObjectResult(model));
        }
        public async Task <IActionResult> Withdraw([FromBody] WithdrawRequest request)
        {
            WithdrawResult depositResult = await withdrawService.Execute(
                request.AccountId,
                request.Amount);

            if (depositResult == null)
            {
                return(new NoContentResult());
            }

            Model model = new Model(
                depositResult.Transaction.Amount,
                depositResult.Transaction.Description,
                depositResult.Transaction.TransactionDate,
                depositResult.UpdatedBalance
                );

            return(new ObjectResult(model));
        }
Exemple #5
0
        public void WithdrawSucceedsWithAvailableFunds(decimal initialAmount, decimal withdrawalAmount, WithdrawResult expectedResult)
        {
            var card = new Card(_number, _pin, initialAmount);

            var actualResult = card.Withdraw(withdrawalAmount, _pin);

            actualResult.Should().Be(expectedResult);

            // Balance should only be affected if the withdraw succeeded.
            if (actualResult == WithdrawResult.Success)
            {
                card.Balance.Should().Be(initialAmount - withdrawalAmount);
            }
            else
            {
                card.Balance.Should().Be(initialAmount);
            }
        }
        public async Task <ActionResult> Withdraw()
        {
            string body;

            using (var stream = new StreamReader(HttpContext.Request.Body))
            {
                body = await stream.ReadToEndAsync();
            }
            var     myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(body);
            string  cardNum  = Convert.ToString(myObject.cardNum);
            decimal amount   = Convert.ToDecimal(myObject.amount);

            if (!IsAuthenticated(cardNum))
            {
                return(Unauthorized());
            }

            try
            {
                if (_context.CheckingCard.FirstOrDefault(c => c.CardNum == cardNum) != null)
                {
                    var         card        = _context.CheckingCard.FirstOrDefault(c => c.CardNum == cardNum);
                    Transaction transaction = new Transaction
                    {
                        TypeOfTxn     = 0,
                        Amount        = amount,
                        DatetimeOfTxn = DateTime.Now,
                        CardSenderNum = card.CardNum
                    };
                    _context.Transaction.Add(transaction);
                    await _context.SaveChangesAsync();

                    if (card.Balance < amount)
                    {
                        await ConfirmWithdraw(card.CardNum, transaction.TxnId, false);

                        return(new OkObjectResult(new { Ok = true, Allowed = false, Errors = new[] { "Not enough money" } }));
                    }
                    else
                    {
                        return(new OkObjectResult(new { Ok = true, Allowed = true, TxnId = transaction.TxnId }));
                    }
                }

                if (_context.CreditCard.FirstOrDefault(c => c.CardNum == cardNum) != null)
                {
                    var card = await _context.CreditCard.FirstOrDefaultAsync(c => c.CardNum == cardNum);

                    var transaction = new Transaction
                    {
                        TypeOfTxn     = 0,
                        Amount        = amount,
                        DatetimeOfTxn = DateTime.Now,
                        CardSenderNum = card.CardNum
                    };
                    _context.Transaction.Add(transaction);
                    await _context.SaveChangesAsync();

                    if (card.Balance < amount)
                    {
                        await ConfirmWithdraw(card.CardNum, transaction.TxnId, false);

                        new OkObjectResult(new { Ok = true, Allowed = false, Errors = new[] { "Not enough money" } });
                    }
                    else
                    {
                        return(new OkObjectResult(new { Ok = true, Allowed = true, transaction.TxnId }));
                    }
                }

                if (_context.DepositCard.FirstOrDefault(c => c.CardNum == cardNum) != null)
                {
                    var card        = _context.DepositCard.FirstOrDefault(c => c.CardNum == cardNum);
                    var transaction = new Transaction
                    {
                        TypeOfTxn     = 0,
                        Amount        = amount,
                        DatetimeOfTxn = DateTime.Now,
                        CardSenderNum = card.CardNum
                    };
                    _context.Transaction.Add(transaction);
                    await _context.SaveChangesAsync();

                    if (card.EndDeposit >= DateTime.Now)
                    {
                        if (card.Balance < amount)
                        {
                            await ConfirmWithdraw(card.CardNum, transaction.TxnId, false);

                            return(new OkObjectResult(new { Ok = true, Allowed = false, Errors = new[] { "Not enough money" } }));
                        }
                        return(new OkObjectResult(new { Ok = true, Allowed = true, Errors = new[] { "Discarding all benefits" } }));
                    }

                    if (card.TotalBalance < amount)
                    {
                        await ConfirmWithdraw(card.CardNum, transaction.TxnId, false);

                        return(new OkObjectResult(new { Ok = true, Allowed = false, Errors = new[] { "Not enough money" } }));
                    }

                    return(new OkObjectResult(new { Ok = true, Allowed = true }));
                }

                return(new OkObjectResult(new { Ok = false, Allowed = false, Errors = new[] { "Card not found" } }));
            }
            catch (Exception exc)
            {
                var res = new WithdrawResult {
                    Ok = false, Allowed = false, Errors = new List <string> {
                        exc.Message
                    }
                };
                return(new ObjectResult(res));
            }
        }