public void Setup()
        {
            _configuration   = new Mock <IConfiguration>();
            _bankGatewayMock = new Mock <IBankGateway>();

            foreach (var(key, value) in InitialConfiguration)
            {
                _configuration.SetupGet(x => x[key]).Returns(value);
            }

            var factory = new CustomWebApplicationFactory <Startup>();

            _client = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureAppConfiguration((context, configurationBuilder) =>
                {
                    configurationBuilder.AddInMemoryCollection(InitialConfiguration);
                });

                builder.ConfigureServices(services =>
                {
                    //services.AddSingleton(x => _configuration.Object);
                    services.AddSingleton(x => _bankGatewayMock.Object);
                });
            }).CreateClient();

            _paymentGatewayClient = new PaymentGatewayClient(_client);
        }
Example #2
0
        public void Setup()
        {
            var services = new ServiceCollection();

            services.ConfigureContainer();
            var serviceProvider = services.BuildServiceProvider();

            _paymentGatewayClient = serviceProvider.GetService <PaymentGatewayClient>();
        }
        public void OneTimeSetUp()
        {
            var baseUrl    = new ConfigurationReader().Get("Dependencies:PaymentGateway:BaseUrl");
            var httpClient = new HttpClient()
            {
                BaseAddress = new Uri(baseUrl)
            };

            _client = new PaymentGatewayClient(httpClient);
        }
Example #4
0
        public void SetUp()
        {
            var builder    = new WebHostBuilder().UseStartup <TestStartup>();
            var testServer = new TestServer(builder);

            _client = new PaymentGatewayClient(testServer.CreateClient());

            _paymentRepositoryMock = GetMock <IPaymentRepository>(testServer);
            _bankClientMock        = GetMock <IBankClient>(testServer);
        }
Example #5
0
        public OrderService(OrdersRepository ordersRepository, ProductsRepository productsRepository, UsersRepository usersRepository,
                            ILogger <OrderService> logger, DiscordService discordService, PaymentGatewayClient paymentGatewayClient)
        {
            this.ordersRepository   = ordersRepository;
            this.productsRepository = productsRepository;
            this.usersRepository    = usersRepository;
            this.logger             = logger;
            this.discordService     = discordService;

            PaymentGatewayClient = paymentGatewayClient;
        }
Example #6
0
        public void PaymentGatewayClient_Instantiation_Fails_With_Missing_MerchantId()
        {
            // Arrange
            var merchantId = Guid.Empty;
            var apiKey     = "xxxx";

            // Act
            var client = new PaymentGatewayClient(merchantId, apiKey);

            // Assert
        }
Example #7
0
        public void WhenCalledPaymentGateway_ReturnsPaymentIsSuccessful()
        {
            mockHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(response);

            var httpClient     = new HttpClient(mockHandler.Object);
            var paymentGateway = new PaymentGatewayClient(httpClient);
            var retrievedPosts = paymentGateway.GetAsync(requestUri);

            Assert.NotNull(retrievedPosts);

            mockHandler.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get),
                ItExpr.IsAny <CancellationToken>());
        }
Example #8
0
        public async Task <BankPaymentRequestResponseDto> CreateReference(BankNameType bankName, string userId, long invoiceId)
        {
            var invoice = (UnitOfWork.InvoiceRepository.GetByIdAsync(invoiceId));
            var amount  = UnitOfWork.InvoiceRepository.GetInvoiceAmount(invoiceId);

            var transactionNumber = TokenGenerator.Generate(TokenType.Transaction);

            switch (bankName)
            {
            case BankNameType.Mellat:
                try
                {
                    string result = "";
                    BypassCertificateError();
                    PaymentGatewayClient bp = new PaymentGatewayClient();
                    result = bp.bpPayRequest(
                        Int64.Parse(MellatTerminalId),
                        MellatUserName,
                        MellatUserPassword,
                        invoiceId,
                        amount,
                        SetDefaultDate(),
                        SetDefaultTime(),
                        $"Invoice #{(await invoice).InvoiceNumber}",
                        CallBackUrl,
                        0);
                    string[] res = result.Split(',');
                    if (res[0] == "0")
                    {
                        var financialTransaction = new FinanceTransaction(invoice.Id, transactionNumber, userId, BankNameType.Mellat, res[1]);
                        UnitOfWork.FinanceTransactionRepository.Create(financialTransaction);
                        await UnitOfWork.SaveAsync();

                        return(new BankPaymentRequestResponseDto()
                        {
                            BankName = BankNameType.Mellat,
                            Response = res[1],
                            PaymentRequestType = PaymentRequestType.RefId,
                            PaymentRequestTypeTitle = "REFID",
                            BankPaymentRequestUrl = MellatPgwSite
                        });
                    }
                    else
                    {
                        return(new BankPaymentRequestResponseDto()
                        {
                            HasError = true,
                            Error = BankResultException(res[0], BankNameType.Mellat)
                        });
                    }
                }
                catch
                {
                    return(new BankPaymentRequestResponseDto()
                    {
                        HasError = true,
                        Error = BankResultException("", BankNameType.Mellat)
                    });
                }

            case BankNameType.ZarinPal:
                var invoiceDto = (await invoice).MapTo <InvoiceDto>();
                return(await GetZarinPalReferenceId(invoiceDto, amount, transactionNumber, userId, bankName));

            //case BankNameType.Keshavarzi:
            //    break;
            default:
                throw new ArgumentOutOfRangeException(nameof(bankName), bankName, null);
            }
        }
 public ZarrinPalProvider()
 {
     _gatway = new PaymentGatewayClient();
     _client = new HttpClient();
 }
Example #10
0
 public Retrieving_a_payment_details(DependencyInjectionFixture diFixture)
 {
     _client = new PaymentGatewayClient(diFixture.HttpClient);
 }
Example #11
0
 public Submitting_a_new_payment_request(DependencyInjectionFixture diFixture)
 {
     _client = new PaymentGatewayClient(diFixture.HttpClient);
 }