Exemple #1
0
        public void ShouldValidateThatTheTransferIsNotInStatusPendingWhenTryingToSign()
        {
            //Arrange
            var transferValidator = new TransferValidator();
            var transfer          = new Transfer
            {
                Amount = 100,
                DestinationCurrencyCode = "EUR",
                Status = Status.Signed
            };

            //Act
            var result = transferValidator.Validate(transfer);

            //Assert
            result.Succeded.Should().BeFalse();
        }
Exemple #2
0
        public BaseResponse <TransferResponse> Transfer(string userId, TransferRequest transferRequest)
        {
            var response = new BaseResponse <TransferResponse>();

            try
            {
                transferRequest.UserId = userId;
                TransferValidator transferValidator = new TransferValidator(_checkingAccountService);
                FluentValidation.Results.ValidationResult validationResult = transferValidator.Validate(transferRequest);

                if (!validationResult.IsValid)
                {
                    response.AddErrors(validationResult.Errors);
                    return(response);
                }

                var from = _checkingAccountService.UpdateBalance(transferRequest.NumberFrom, transferRequest.Amount * -1);
                var to   = _checkingAccountService.UpdateBalance(transferRequest.NumberTo, transferRequest.Amount);

                _transactionService.Add(new Transaction
                {
                    Amount = transferRequest.Amount,
                    FromCheckingAccountId = from.Id,
                    ToCheckingAccountId   = to.Id
                });

                _checkingAccountService.Commit();

                response.Data = new TransferResponse {
                    Balance = from.Balance
                };
            }
            catch (Exception ex)
            {
                _checkingAccountService.Rollback();
                response.AddError(1, "Erro inesperado");
            }
            return(response);
        }
Exemple #3
0
        // public IActionResult ConfirmTransferBalance([FromForm] TransferModel model)
        public IActionResult ConfirmTransferBalance([FromForm] TransferModel model)
        {
            // TransferValidator
            TransferValidator bankValidator = new TransferValidator();
            ValidationResult  result        = bankValidator.Validate(model);

            if (!result.IsValid)
            {
                return(BadRequest(result.Errors));
            }

            if (ModelState.IsValid)
            {
                var cust = _custManager.GetCustomerDetails(model.AccountNumber_from);
                var jsonRequestBehavior = new JsonSerializerSettings();
                Repository.Services.TransactionModel gotoPaymentDirect = new Repository.Services.TransactionModel
                {
                    FullName   = cust.Result.Surname + " " + cust.Result.GivenName,
                    CustomerID = cust.Result.CustomerId.ToString(),
                    Amount     = model.Amount,
                    Savecode   = GenerateMerchantRef(),
                    Email      = cust.Result.EmailAdress,
                    Phone      = cust.Result.TelephoneNumber,
                    IsActive   = false,
                    IsDeleted  = false
                };

                var postTransction = _payment.PostTransaction(gotoPaymentDirect);
                if (postTransction.UniqueKey != null)
                {
                    return(Json(new { redirectUrl = postTransction.UniqueKey, isRedirect = true }, jsonRequestBehavior));
                }


                if (gotoPaymentDirect.Amount != 0)
                {
                    return(RedirectToAction("MakePayment", gotoPaymentDirect));
                }
                else
                {
                    return(View("MakePayment", gotoPaymentDirect));
                }

                //  var result = await _cashier.TransferBalance(model);
                //if (result != null)
                //{
                //    var subjectFrom = "ALERT NOTIFICATION";

                //    var message = "</br><b> Dear </b>" + result.recepientName;
                //    message += ("<br />");
                //    message += "</br><b> Your account: </b>" + result.accountNumber;
                //    message += ("<br />");
                //    message += "</br><b> Debited with: #</b>" + model.Amount;
                //    message += ("<br />");
                //    message += "</br><b> Date of Transaction: #</b>" + result.Date;
                //    message += ("<br />");
                //    //message += "</br><b> VERIFY CODE: </b>" + Generate.GenerateVerificationCode().ToString();
                //    //message += ("<br />");
                //    message += ("<br />");
                //    //message += "</br>has been registered successful on Cyberspace E-procurement Portal.</br>";
                //    //message += "</br>Kindly, log in via " + requisitionURL + " and validate the required documents.";
                //    message += "</br>Regards";

                //  await  _emailSender.SendEmailAsync(result.recipientEmail, subjectFrom, message, "");

                //    var subjectTo = "ALERT NOTIFICATION";

                //    var messages = "</br><b> Dear </b>" + result.recievedMails.recipientEmail;
                //    messages += ("<br />");
                //    messages += "</br><b> Your account: </b>" + result.recievedMails.accountNumber;
                //    messages += ("<br />");
                //    messages += "</br><b> Credited with: #</b>" + model.Amount;
                //    messages += ("<br />");
                //    messages += "</br><b> Date of Transaction: #</b>" + result.recievedMails.Date;
                //    messages += ("<br />");
                //    messages += ("<br />");
                //    messages += "</br>Regards";

                //    await _emailSender.SendEmailAsync(result.recipientEmail, subjectTo, messages, "");

                //string acountN0 = result.accountNumber;
                //TODO: Send Email with AccountNumber And Verification Code
                //string nameTransFrom = result.recepientName;
                //bool emailSent = _emailSender.sendmail(result.recipientEmail, nameTransFrom , model.Amount +" " + "Debited from account No." + " " + result.accountNumber );//* Generate.GenerateVerificationCode()*/);

                //string nameTransTo = result.recievedMails.recepientName;
                //bool emailSentR = _emailSender.sendmail(result.recievedMails.recipientEmail, nameTransTo, model.Amount.ToString() +" " + "Credited to account No." + " " + result.recievedMails.accountNumber/*, result.Amount*//* Generate.GenerateVerificationCode()*/);

                //alert message
                //TempData["Message"] = "Transaction Successful";

                //    dynamic transRef = TempData["Message"];

                //    Alert("success", transRef, NotificationType.success);

                //    return RedirectToAction("Index", "Home");
                //}
            }
            else
            {
                TempData["Error"] = "bad";
            }
            return(View(model));
        }
Exemple #4
0
        public BaseResponse <TransferResponse> Transfer(string userId, TransferRequest transferRequest)
        {
            var response = new BaseResponse <TransferResponse>();

            try
            {
                transferRequest.UserId = userId;

                var checkingAccountFrom = _checkingAccountApplication.GetByAccountNumber(transferRequest.NumberFrom);
                var checkingAccountTo   = _checkingAccountApplication.GetByAccountNumber(transferRequest.NumberTo);

                TransferValidator transferValidator = new TransferValidator(_checkingAccountApplication);
                FluentValidation.Results.ValidationResult validationResult = transferValidator.Validate(transferRequest);

                if (!validationResult.IsValid)
                {
                    List <ErrorResponse> erros = new List <ErrorResponse>();

                    foreach (var item in validationResult.Errors)
                    {
                        ErrorResponse errorResponse = new ErrorResponse {
                            Message = item.ErrorMessage, Code = item.GetHashCode()
                        };
                        erros.Add(errorResponse);
                    }

                    response.Errors.AddRange(erros);

                    return(response);
                }

                decimal balanceFrom = checkingAccountFrom.Balance - transferRequest.Amount;
                decimal balanceTo   = checkingAccountTo.Balance + transferRequest.Amount;

                var from = _checkingAccountApplication.UpdateBalance(transferRequest.NumberFrom, balanceFrom);
                var to   = _checkingAccountApplication.UpdateBalance(transferRequest.NumberTo, balanceTo);

                if (from != null && to != null)
                {
                    _transactionService.Add(new Transaction
                    {
                        Amount = transferRequest.Amount,
                        FromCheckingAccountId = checkingAccountFrom.UserId,
                        ToCheckingAccountId   = checkingAccountTo.UserId
                    });

                    response.Result = new TransferResponse {
                        Balance = balanceFrom
                    };
                }
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ErrorResponse
                {
                    Code    = ex.GetHashCode(),
                    Message = ex.Message
                });
            }
            return(response);
        }