예제 #1
0
        public async void GetPaymentTestSucceedsWhenPaymentExists()
        {
            PaymentDTO paymentDto = await paymentsService.GetPayment(1);

            Assert.Equal("*****@*****.**", paymentDto.CustomerContact);
            Assert.Equal("449.99", paymentDto.Amount.ToString());
            Assert.Equal("1234************", paymentDto.CardNumber);
            Assert.Equal("1", paymentDto.PaymentStatusCode.ToString());
            Assert.Equal("01/12/2019 00:00:00", paymentDto.CardExpiryDate.ToString());
        }
예제 #2
0
        public async Task <IActionResult> GetPaymentById([FromRoute(Name = "id")] Guid paymentId)
        {
            try
            {
                var pay = await paymentService.GetPayment(paymentId);

                var leasing = leasingService.GetLeasing(pay.Data.Leasing).Result.Data;
                var id      = ExtractIdFromToken(Request.Headers[HttpRequestHeader.Authorization.ToString()]);

                if (!leasing.Owner.Equals(id) && leasing.Renter != id && !IsAdmin(Request.Headers[HttpRequestHeader.Authorization.ToString()]))
                {
                    throw new ForbiddenApiException();
                }

                return(Ok(pay));
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new BadRequestApiException();
            }
        }
예제 #3
0
        public async Task <object> GetPayment(int id)
        {
            var payment = await _paymentsService.GetPayment(id);

            if (payment == null)
            {
                return(JsonResults.Error(errorNum: 404, errorMessage: "Payment not found"));
            }

            var model = GetPaymentModel(payment);

            return(JsonResults.Success(model));
        }