Exemplo n.º 1
0
        public PaymentControllerFixture()
        {
            _fixture            = new Fixture();
            _fakePaymentService = A.Fake <IPaymentService>();
            _fakeLoggerService  = A.Fake <ILoggerService>();
            _paymentDataDto     = _fixture.Create <PaymentDataDto>();
            var _paymentUri = "http://localhost/payment";

            _controller =
                new PaymentController(_fakePaymentService, _fakeLoggerService)
            {
                Request = new HttpRequestMessage {
                    RequestUri = new Uri(_paymentUri)
                }
            };


            var transaction = _fixture.Create <string>();

            A.CallTo(() => _fakePaymentService.Submit(A <BankAccount> .Ignored, A <DepositDetail> .Ignored)).Returns(transaction);

            Mapper.Initialize(config =>
            {
                config.CreateMap <PaymentDataDto, DepositDetail>();
                config.CreateMap <PaymentDataDto, BankAccount>();
            });
        }
 public async Task <ActionResult> Payment(PaymentDataDto paymentDataDto)
 {
     // var addPayment = await _counterService.AddPaymentAsync(paymentDataDto);
     // if (addPayment != null)
     //     return Created(String.Empty, addPayment);
     return(BadRequest("Insufficient funds"));
 }
Exemplo n.º 3
0
        public IHttpActionResult Post([FromBody] PaymentDataDto paymentDataDto)
        {
            _loggerService.Log(LogLevel.Info, "Submit payment start.");

            var depositDetail = Mapper.Map <PaymentDataDto, DepositDetail>(paymentDataDto);
            var account       = Mapper.Map <PaymentDataDto, BankAccount>(paymentDataDto);

            var transactionId = _paymentService.Submit(account, depositDetail);

            _loggerService.Log(LogLevel.Info, "Submit payment successful.");

            return(Created($"{Request.RequestUri}/{transactionId}", paymentDataDto));
        }
Exemplo n.º 4
0
        public async Task <Payment> AddPaymentAsync(PaymentDataDto paymentDataDto)
        {
            var payment = _mapper.Map <PaymentDataDto, Payment>(paymentDataDto);

            // payment.UserId = pau;
            payment.PaymentId = Guid.NewGuid();
            payment.Date      = DateTime.Now;
            var byIdAsync = await _unitOfWork.PriceList.GetByIdAsync(paymentDataDto.Service);

            payment.Description = byIdAsync.Service;
            if (await CanPayAsync(payment.UserId, byIdAsync.Price))
            {
                payment.DebitAmount = byIdAsync.Price;
                payment.Success     = true;
                await _unitOfWork.Payments.AddAsync(payment);

                await _unitOfWork.CommitAsync();

                return(payment);
            }
            return(null);
        }