/// <inheritdoc />
 public PaymentInfo GetPaymentInfo(Guid id)
 {
     using (var context = new PaymentGatewayContext(ConnectionString))
     {
         return(context.PaymentsInfo.FirstOrDefault(pi => pi.Response.Id == id));
     }
 }
示例#2
0
        public async Task Given_AValidPaymentWithCreditCard_When_TryToInsert_Then_IsInsertedWithSuccess()
        {
            // arrange
            var dbContextOptions = new DbContextOptionsBuilder <PaymentGatewayContext>()
                                   .UseInMemoryDatabase(databaseName: "InsertTestDatabase")
                                   .Options;

            PaymentMethod paymentMethod = new CreditCard(
                new CVV("235"),
                "John Doe",
                "9568475845123569",
                new ExpiryDate(this.futureMonth, this.futureYear)
                );

            Payment payment = new Payment(542.50D, "USD", paymentMethod);

            // act
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                var repository = new PaymentRepository(context);
                await repository.SaveAsync(payment);
            }

            // assert
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                Assert.Equal(1, context.Payment.Count());
                Assert.NotNull(context.Payment.Single());

                var paymentFromDatabase = context.Payment.Include(p => p.PaymentMethod).Single();

                Assert.Equal(542.50D, paymentFromDatabase.Amount);
            }
        }
示例#3
0
        public async Task Given_APaymentId_When_ThePaymentExistsOnTheDataBase_Then_ReturnsThePaymentDetails()
        {
            // arrange
            var dbContextOptions = new DbContextOptionsBuilder <PaymentGatewayContext>()
                                   .UseInMemoryDatabase(databaseName: "GetTestDatabase")
                                   .Options;

            PaymentMethod paymentMethod = new CreditCard(
                new CVV("737"),
                "John Doe",
                "4168842845189769",
                new ExpiryDate(this.futureMonth, this.futureYear)
                );

            Payment payment = new Payment(850D, "EUR", paymentMethod);

            // act
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                var repository = new PaymentRepository(context);
                await repository.SaveAsync(payment);
            }

            // assert
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                var repository = new PaymentRepository(context);

                var paymentFromDatabase = await repository.GetByIdAsync(payment.Id);

                Assert.NotNull(paymentFromDatabase);
                Assert.Equal(payment.Amount, paymentFromDatabase.Amount);
                Assert.Equal(payment.Currency, paymentFromDatabase.Currency);
            }
        }
示例#4
0
 public PaymentService(PaymentGatewayContext context, ILogger <PaymentService> logger, IUserService userService, IBankService bankService, IHttpContextAccessor httpContext)
 {
     _context     = context;
     _logger      = logger;
     _userService = userService;
     _httpContext = httpContext;
     _bankService = bankService;
 }
 /// <inheritdoc />
 public void SavePaymentInfo(PaymentInfo objectToSave)
 {
     using (var context = new PaymentGatewayContext(ConnectionString))
     {
         context.PaymentsInfo.Add(objectToSave);
         context.SaveChanges();
     }
 }
示例#6
0
            public void TestInitialize()
            {
                _bank = new Mock <IAcquiringBank>();

                _db = new PaymentGatewayContext(new DbContextOptionsBuilder <PaymentGatewayContext>().UseInMemoryDatabase(TestContext.TestName).Options);

                _client = _factory.CreateTestClient(TestContext.TestName, services =>
                {
                    services.AddSingleton(_bank.Object);
                    services.AddApiKeys(_defaultApiKey);
                });

                _client.DefaultRequestHeaders.Add("X-Api-Key", _defaultApiKey);
            }
示例#7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, PaymentGatewayContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();

            DbInitializer.Initialize(context);
        }
示例#8
0
        public async Task Given_APaymentId_When_ThePaymentExistsOnTheDataBase_Then_ReturnsThePaymentWithPaymentMethodDetails()
        {
            // arrange
            var dbContextOptions = new DbContextOptionsBuilder <PaymentGatewayContext>()
                                   .UseInMemoryDatabase(databaseName: "GetWithPaymentMethodTestDatabase")
                                   .Options;

            PaymentMethod paymentMethod = new CreditCard(
                new CVV("865"),
                "John Doe",
                "5342569487345682",
                new ExpiryDate(this.futureMonth, this.futureYear)
                );

            Payment payment = new Payment(1050.87D, "RUB", paymentMethod);

            // act
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                var repository = new PaymentRepository(context);
                await repository.SaveAsync(payment);
            }

            // assert
            using (var context = new PaymentGatewayContext(dbContextOptions))
            {
                var repository = new PaymentRepository(context);

                var paymentFromDatabase = await repository.GetByIdIncludingPaymentMethodAsync(payment.Id);

                Assert.NotNull(paymentFromDatabase);
                Assert.Equal(payment.Amount, paymentFromDatabase.Amount);
                Assert.Equal(payment.Currency, paymentFromDatabase.Currency);
                Assert.NotNull(paymentFromDatabase.PaymentMethod);

                var creditCard             = (paymentMethod as CreditCard);
                var creditCardFromDatabase = (paymentFromDatabase.PaymentMethod as CreditCard);

                Assert.Equal(creditCard.CVV, creditCardFromDatabase.CVV);
                Assert.Equal(creditCard.Name, creditCardFromDatabase.Name);
                Assert.Equal(creditCard.CardNumber, creditCardFromDatabase.CardNumber);
                Assert.Equal(creditCard.ExpiryDate, creditCardFromDatabase.ExpiryDate);
            }
        }
        public async Task TestGetPaymentByID_IDFound()
        {
            // create mock version
            var mockUserService         = new Mock <IUserService>();
            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var options = new DbContextOptionsBuilder <PaymentGatewayContext>()
                          .UseInMemoryDatabase(databaseName: "TestDatabase").Options;

            // Insert data into the database
            var dbContext  = new PaymentGatewayContext(options);
            var paymentId1 = Guid.NewGuid().ToString();
            var paymentId2 = Guid.NewGuid().ToString();
            var paymentId3 = Guid.NewGuid().ToString();

            dbContext.PaymentItems.Add(new Payment()
            {
                ID = paymentId1, Amount = 32, UserID = "TestUserID", CreditCardNumber = "1234561234561234", CVV = 657, Currency = "EURO", ExpirationDate = new DateTime(2020, 12, 1), IsPaymentSuccessful = true
            });
            dbContext.PaymentItems.Add(new Payment()
            {
                ID = paymentId2, Amount = 500, UserID = "TestUserID", CreditCardNumber = "1234561234561235", CVV = 123, Currency = "SHEKEL", ExpirationDate = new DateTime(2025, 5, 1), IsPaymentSuccessful = false
            });
            dbContext.PaymentItems.Add(new Payment()
            {
                ID = paymentId3, Amount = 421, UserID = "Test2UserID", CreditCardNumber = "1234561234561236", CVV = 789, Currency = "DOLLAR", ExpirationDate = new DateTime(2021, 2, 13), IsPaymentSuccessful = true
            });
            dbContext.SaveChanges();

            mockHttpContextAccessor.Setup(_ => _.HttpContext.User.Identity.Name).Returns("testMerchantID - doesnt matter");
            mockUserService.Setup(x => x.GetUserIdFromToken(It.IsAny <string>())).Returns("TestUserID");

            var service    = new PaymentService(dbContext, null, mockUserService.Object, null, mockHttpContextAccessor.Object);
            var paymentDTO = await service.GetPaymentByID(paymentId1);

            Assert.AreEqual(paymentDTO.ID, paymentId1);
            Assert.AreEqual(paymentDTO.Amount, 32);
            Assert.AreEqual(paymentDTO.IsPaymentSuccessful, true);
            Assert.AreEqual(paymentDTO.ExpirationDate, new DateTime(2020, 12, 1));
            Assert.AreEqual(paymentDTO.MaskedCardNumber, "1234 56XX XXXX 1234");
            Assert.AreEqual(paymentDTO.Currency, "EURO");
        }
示例#10
0
 public UserService(PaymentGatewayContext context)
 {
     _context = context;
 }
 public TransactionsController(PaymentGatewayContext context)
 {
     _context = context;
 }
 public ApiKeyRepository(PaymentGatewayContext context)
 {
     _context = context;
 }
示例#13
0
 public PaymentRepository(PaymentGatewayContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
 public RepositoryAcquirerSale(PaymentGatewayContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
示例#15
0
 public PaymentsController(PaymentGatewayContext context, ILogger <PaymentsController> logger, IUserService userService, IPaymentService paymentService)
 {
     _context        = context;
     _logger         = logger;
     _paymentService = paymentService;
 }
 public MerchantsController(PaymentGatewayContext context)
 {
     _context = context;
 }
示例#17
0
 public CardRepository(PaymentGatewayContext context)
 {
     _context = context;
 }
示例#18
0
 public Repository(PaymentGatewayContext context) =>
 this.context = context;
示例#19
0
 public ChargesController(PaymentGatewayContext db, IAcquiringBank bank, ILogger <ChargesController> logger)
 {
     _db     = db ?? throw new ArgumentNullException(nameof(db));
     _bank   = bank ?? throw new ArgumentNullException(nameof(bank));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public AdminController(PaymentGatewayContext _db)
 {
     this._db = _db;
 }
示例#21
0
 public UsersController(PaymentGatewayContext context, ILogger <PaymentsController> logger, IUserService userService)
 {
     _context     = context;
     _logger      = logger;
     _userService = userService;
 }
示例#22
0
 public BankService(PaymentGatewayContext context, ILogger <BankService> logger)
 {
     _context = context;
     _logger  = logger;
 }
示例#23
0
 public TransactionController(PaymentGatewayContext db, IUserTransaction userTransaction)
 {
     _db = db;
     this.userTransaction = userTransaction;
 }
示例#24
0
 public PaymentRepository(PaymentGatewayContext context) :
     base(context)
 {
 }
 public RepositoryStore(PaymentGatewayContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
 public PaymentsRepository(PaymentGatewayContext dbContext, ILogger <PaymentsRepository> logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
 public GenericRepository(PaymentGatewayContext dbContext)
 {
     _dbContext = dbContext;
 }
 public PaymentGatewayAuthToken()
 {
     this._db = new PaymentGatewayContext();
 }
 public UsersController(PaymentGatewayContext _db, IUserTransaction userTransaction)
 {
     this._db             = _db;
     this.userTransaction = userTransaction;
 }
示例#30
0
 public MerchantRepository(PaymentGatewayContext context)
 {
     _context = context;
 }