public void ReturnPaymentDetail()
        {
            var paymentId = Guid.NewGuid();

            var paymentRequest = new PaymentRequest
            {
                CardNumber     = "1111222233334444",
                CardHolderName = "A.Smith",
                CVV            = "123",
                ExpiryDate     = "01/23",
                Currency       = "GBP",
                Amount         = 50.00
            };

            var expectedPaymentResponse = new PaymentResponse
            {
                Id     = paymentId,
                Status = Models.Enums.TransactionStatus.Authorized
            };

            var expectedPaymentDetail = new PaymentDetail(paymentRequest, expectedPaymentResponse);

            _repositoryMock.Setup(x => x.GetPaymentDetailAsync(paymentId))
            .Returns(Task.FromResult(expectedPaymentDetail));

            var paymentDetail = paymentGatewayService.GetPaymentDetailAsync(paymentId).Result;

            paymentDetail.Id = expectedPaymentResponse.Id;
            paymentDetail.Response.Status.Should().Be(expectedPaymentResponse.Status);
            paymentDetail.Request.CardHolderName.Should().Be(paymentRequest.CardHolderName);
            paymentDetail.Request.CardNumber.Should().Be(paymentRequest.MaskCardNumber());
        }
示例#2
0
        public void ProcessValidPayment()
        {
            var paymentRequest = new PaymentRequest
            {
                CardNumber     = "1234123412341234",
                CardHolderName = "JOHN DOE",
                ExpiryDate     = "10/20",
                Amount         = 123.12,
                Currency       = "GBP",
                CVV            = "123"
            };

            var paymentGateway = new PaymentGateway(new MockedBankInstitution(), new MemoryStorage());
            var response       = paymentGateway.ProcessPayment(paymentRequest);

            Assert.IsType <Guid>(response.Id);
            Assert.Equal(Status.Authorized, response.Status);


            var savedResponse = paymentGateway.RetrievePaymentInfo(response.Id);

            Assert.Equal(response.GetHashCode(), savedResponse.Response.GetHashCode());
            Assert.Equal(paymentRequest.Amount, savedResponse.Request.Amount);
            Assert.Equal(paymentRequest.MaskCardNumber(), savedResponse.Request.CardNumber);
        }
        public async Task RetrieveHistoricPaymentSuccessfully()
        {
            var paymentRequest = new PaymentRequest
            {
                CardNumber     = "1111222233334444",
                CardHolderName = "A.Smith",
                CVV            = "123",
                ExpiryDate     = "01/23",
                Currency       = "GBP",
                Amount         = 50.00
            };

            HttpRequestMessage request = CreateProcessPaymentRequest(paymentRequest);

            var response = _client.SendAsync(request).Result;

            response.StatusCode.Should().Be(201);

            var paymentResponseJson = await response.Content.ReadAsStringAsync();

            var paymentResponse = JsonConvert.DeserializeObject <PaymentResponse>(paymentResponseJson);

            var paymentId = paymentResponse.Id;

            request = new HttpRequestMessage(HttpMethod.Get, "/api/payment/getpaymentdetail/" + paymentId.ToString());
            request.Headers.Add("ApiKey", apiKey);

            response = _client.SendAsync(request).Result;

            var paymentDetailJson = await response.Content.ReadAsStringAsync();

            var paymentDetail = JsonConvert.DeserializeObject <PaymentDetail>(paymentDetailJson);

            response.StatusCode.Should().Be(201);
            paymentDetail.Id.Should().Be(paymentResponse.Id);
            paymentDetail.Request.CardNumber.Should().Be(paymentRequest.MaskCardNumber());
        }