Exemplo n.º 1
0
        public void Do_Not_Make_Transfer_When_User_Gives_Wrong_Account_Number()
        {
            //Arrange
            var toUser = new UserDto {
                Id = 1
            };
            var fromUser = new UserDto {
                Id = 2
            };
            var moneyTransferDto = new MoneyTransferDto
            {
                CashAmount = 100M, CreatedOn = DateTime.Now, From = fromUser, Id = 1, Name = "Test", To = toUser
            };

            _bankAccountServiceMock.Setup(s => s.TakeCash(It.Is <decimal>(m => m.Equals(moneyTransferDto.CashAmount)),
                                                          It.Is <int>(i => i.Equals(moneyTransferDto.From.Id)))).Returns(true);
            _bankAccountServiceMock.Setup(s => s.GiveCash(It.Is <decimal>(m => m.Equals(moneyTransferDto.CashAmount)),
                                                          It.Is <int>(i => i.Equals(moneyTransferDto.To.Id)))).Returns(false);
            var service = InstantiateService();
            //Act
            var result = service.Transfer(moneyTransferDto);

            //Assert
            _bankAccountServiceMock.VerifyAll();
            Assert.AreEqual(false, result.Success);
            Assert.AreEqual(
                "Error occurs when trying to transfer money from customer. Make sure you've provided valid account number",
                result.Message);
        }
Exemplo n.º 2
0
        public void Create_Successful_Transfer()
        {
            //Arrange
            var toUser = new UserDto {
                Id = 1
            };
            var fromUser = new UserDto {
                Id = 2
            };
            var moneyTransferDto = new MoneyTransferDto
            {
                CashAmount = 100M, CreatedOn = DateTime.Now, From = fromUser, Id = 1, Name = "Test", To = toUser
            };

            _bankAccountServiceMock.Setup(s => s.TakeCash(It.Is <decimal>(m => m.Equals(moneyTransferDto.CashAmount)),
                                                          It.Is <int>(i => i.Equals(moneyTransferDto.From.Id)))).Returns(true);
            _bankAccountServiceMock.Setup(s => s.GiveCash(It.Is <decimal>(m => m.Equals(moneyTransferDto.CashAmount)),
                                                          It.Is <int>(i => i.Equals(moneyTransferDto.To.Id)))).Returns(true);
            var moneyTransfer = new MoneyTransfer();

            _moneyTransferRepositoryMock.Setup(s => s.Create(It.Is <MoneyTransfer>(m =>
                                                                                   m.ToId == toUser.Id && m.CashAmount == moneyTransferDto.CashAmount && m.FromId == fromUser.Id)));
            var service = InstantiateService();
            //Act
            var result = service.Transfer(moneyTransferDto);

            //Assert
            _bankAccountServiceMock.VerifyAll();
            _moneyTransferRepositoryMock.VerifyAll();
            Assert.IsTrue(result.Success);
            Assert.AreEqual("Transfer has been successful", result.Message);
        }
Exemplo n.º 3
0
 public IActionResult AddMoneyToAccount([FromBody] MoneyTransferDto moneyTransferDto)
 {
     if (moneyTransferDto.Money != 0)
     {
         var account = _accountService.GetAccountByNumber(moneyTransferDto.AccountNumber);
         account.Balance += moneyTransferDto.Money;
         _accountService.Update(account);
         return(Ok());
     }
     return(BadRequest());
 }
Exemplo n.º 4
0
        public ResultDto Transfer(MoneyTransferDto moneyTransferDto)
        {
            ResultDto resultDto = new ResultDto()
            {
                Success = false
            };

            if (moneyTransferDto.From.Id != moneyTransferDto.To.Id)
            {
                var successTransferFrom = _bankAccountService.TakeCash(moneyTransferDto.CashAmount, moneyTransferDto.From.Id);
                if (successTransferFrom)
                {
                    var successTransferTo = _bankAccountService.GiveCash(moneyTransferDto.CashAmount, moneyTransferDto.To.Id);

                    if (successTransferTo)
                    {
                        var moneyTransfer = new MoneyTransfer()
                        {
                            CashAmount = moneyTransferDto.CashAmount,
                            CreatedOn  = DateTime.Now,
                            FromId     = moneyTransferDto.From.Id,
                            ToId       = moneyTransferDto.To.Id,
                            Name       = moneyTransferDto.Name
                        };

                        _moneyTransferRepository.Create(moneyTransfer);

                        resultDto.Success = true;
                        resultDto.Message = "Transfer has been successful";
                    }
                    else
                    {
                        resultDto.Message = "Error occurs when trying to transfer money from customer. Make sure you've provided valid account number";
                    }
                }
                else
                {
                    resultDto.Message = "Error occurs when trying to transfer money from customer. Make sure you have enough money.";
                }
            }
            else
            {
                resultDto.Message = "You cannot transfer money to yourself!";
            }
            return(resultDto);
        }
Exemplo n.º 5
0
        public IHttpActionResult Transfer(MoneyTransferDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            dto.From.Id = User.Identity.GetUserId().Value;

            var result = _moneyTransferService.Transfer(dto);


            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            else
            {
                return(Ok(result.Message));
            }
        }
Exemplo n.º 6
0
        public void Do_Not_Make_Transfer_From_User_To_Himself()
        {
            //Arrange
            var toUser = new UserDto {
                Id = 1
            };
            var fromUser = new UserDto {
                Id = 1
            };
            var moneyTransferDto = new MoneyTransferDto
            {
                CashAmount = 100M, CreatedOn = DateTime.Now, From = fromUser, Id = 1, Name = "Test", To = toUser
            };
            var service = InstantiateService();
            //Act
            var result = service.Transfer(moneyTransferDto);

            //Assert
            Assert.AreEqual(false, result.Success);
            Assert.AreEqual("You cannot transfer money to yourself!", result.Message);
        }
        public IActionResult Transfer(MoneyTransferDto mt)
        {
            if (!Utility.ValidYMobileNo(mt.pid))
            {
                return(BadRequest(new ApiResponse(-3000, "Sorry, the target mobile was wrong")));
            }
            if (mt.amt <= 0)
            {
                return(BadRequest(new ApiResponse(-3001, "Sorry, the amount was wrong")));
            }
            var partnerResult = this._partnerManager.Validate(mt.pid);

            if (!partnerResult.Success)
            {
                return(BadRequest(new ApiResponse(-3002, "Sorry, the target pos was wrong")));
            }

            var currentUser = _partnerManager.GetPartnerById(this.HttpContext.User.Identity.Name);

            var moneyTransfer = new MoneyTransfer();

            moneyTransfer.Partner          = partnerResult.Partner;
            moneyTransfer.PayType.Id       = "cash";
            moneyTransfer.PayNo            = "0000";
            moneyTransfer.PayDate          = DateTime.Now;
            moneyTransfer.PayBank          = "";
            moneyTransfer.CreatedBy        = currentUser;
            moneyTransfer.AccessChannel.Id = "api";
            moneyTransfer.Amount           = mt.amt;
            moneyTransfer.BillNo           = "00";
            moneyTransfer.RequestNo        = "00";
            moneyTransfer.RequestAmount    = mt.amt;
            moneyTransfer.Note             = mt.note;
            moneyTransfer.ApiTransaction   = mt.seq;

            var result = new MoneyTransferRepo(_db, _partnerManager, _partnerActivity).Create(moneyTransfer);

            if (!result.Success)
            {
                if (result.AffectedCount == -500)
                {
                    return(BadRequest(new ApiResponse(-3003, "Sorry, undefined rule")));
                }
                if (result.AffectedCount == -501)
                {
                    return(BadRequest(new ApiResponse(-3004, $"Sorry, your balance was not enough {(currentUser.Balance - currentUser.Reserved).ToString("N0")}")));
                }
                if (result.AffectedCount == -502)
                {
                    return(BadRequest(new ApiResponse(-3005, $"Sorry, amount less than min limit")));
                }
                if (result.AffectedCount == -503)
                {
                    return(BadRequest(new ApiResponse(-3006, "Sorry, amount more than max limit")));
                }
                if (result.AffectedCount == -506)
                {
                    return(BadRequest(new ApiResponse(-3007, "Sorry, your account was invalid")));
                }
                if (result.AffectedCount == -507)
                {
                    return(BadRequest(new ApiResponse(-3008, "Sorry, inconsistent data")));
                }
                if (result.AffectedCount == -508)
                {
                    return(BadRequest(new ApiResponse(-3009, $"Sorry, duplicated sequence {moneyTransfer.ApiTransaction}")));
                }
            }
            moneyTransfer = new MoneyTransferRepo(_db, _partnerManager, _partnerActivity).GetSingleOrDefault(result.AffectedCount);
            moneyTransfer.Partner.Balance   = _partnerManager.GetBalance(moneyTransfer.Partner.Account);
            moneyTransfer.CreatedBy.Balance = _partnerManager.GetBalance(moneyTransfer.CreatedBy.Account);
            new NotificationRepo(_db, _partnerManager).SendNotification <MoneyTransfer>("MoneyTransfer.Create", result.AffectedCount, moneyTransfer);

            return(Ok(new {
                resultCode = 0,
                resultDesc = "OK",
                transferId = moneyTransfer.Id,
                seq = moneyTransfer.ApiTransaction,
                from = moneyTransfer.CreatedBy.Id + " | " + moneyTransfer.CreatedBy.Account,
                to = moneyTransfer.Partner.Id + " | " + moneyTransfer.Partner.Account,
                amt = moneyTransfer.Amount,
                netAmt = moneyTransfer.NetAmount,
                recAmt = moneyTransfer.ReceivedAmount,
                taxPer = moneyTransfer.TaxPercent,
                taxAmt = moneyTransfer.TaxAmount,
                bonusPer = moneyTransfer.BonusPercent,
                bonusAmt = moneyTransfer.BounsAmount,
                bonusTaxPer = moneyTransfer.BounsTaxPercent,
                bonusTaxAmt = moneyTransfer.BounsTaxAmount,
                yourBal = (moneyTransfer.CreatedBy.Balance - moneyTransfer.CreatedBy.Reserved)
            }));
        }