Example #1
0
        /// <summary>
        /// Starts an iDeal transaction.
        /// </summary>
        /// <param name="transaction">IDeal transaction detail model.</param>
        /// <returns>Model holding details on start of transaction. </returns>
        public async Task <StartTransactionResponse> StartTransaction(IDealTransaction transaction)
        {
            var response = await this.ApiPost(transaction.StartApi, new Dictionary <string, string>
            {
                { "rtlo", transaction.ShopID.ToString() },
                { "bank", transaction.Bank },
                { "amount", transaction.Amount.ToString() },
                { "description", transaction.Description },
                { "reporturl", transaction.ReportUrl },
                { "returnurl", transaction.ReturnUrl },
                { "cancelurl", transaction.CancelUrl },
                { "test", "1" }
            });

            if (response.IsSuccessStatusCode)
            {
                var apiResponse = await response.Content.ReadAsStringAsync();

                _logger.LogInformation(string.Format("Got API response: {0}", apiResponse));

                return(new StartTransactionResponse(apiResponse));
            }

            _logger.LogWarning(string.Format("API Returned statuscode other than succes. ({0}, {1})", response.StatusCode, response.ReasonPhrase));

            // Custom errors here:
            throw new Exception("Failed to get response from API");
        }
Example #2
0
        public void CharFilter_SetInvalidDescription_Exception()
        {
            // Arrange
            IDealTransaction iDealTransaction = new IDealTransaction();
            int lowerLimit = iDealTransaction.MinimumAmount;
            int upperLimit = iDealTransaction.MaximumAmount;

            // Act
            Action setTooHigh = () => iDealTransaction.Amount = upperLimit + 1;
            Action setTooLow  = () => iDealTransaction.Amount = lowerLimit - 1;

            // Assert
            Assert.ThrowsException <ArgumentOutOfRangeException>(setTooHigh, "Transaction model shouldn't accept value above upper limit");
            Assert.ThrowsException <ArgumentOutOfRangeException>(setTooLow, "Transaction model shouldn't accept value below lower limit");
        }
Example #3
0
        public void InvalidInput_Filter_ToValidString()
        {
            // Arrange
            const string inputString    = "You# (@Sho))(uld b(*!@#e ab__~++~_le )(2!(*$#)(*)) r@@@@@@@@ea@@@@@d ______th_____is______ 1*&)(&2)(*()$@!&(*3)*($)!@*(@";
            const string expectedOutput = "You Should be able 2 read this 1";

            // Act (calls setter)
            IDealTransaction iDealTransaction = new IDealTransaction()
            {
                Description = inputString
            };

            // Assert
            Assert.AreEqual(expectedOutput, iDealTransaction.Description, "Didn't filter input correctly.");
            Assert.AreEqual(32, iDealTransaction.Description.Length, "Failed to limit charcount to 32.");
        }
Example #4
0
        public async Task StartTransactionAsync()
        {
            // Arrange
            var clientHandlerStub = new DelegatingHandlerStub();
            var client            = new HttpClient(clientHandlerStub)
            {
                BaseAddress = new System.Uri("https://transaction.digiwallet.nl/")
            };
            var mockFactory = new Mock <IHttpClientFactory>();

            // Always return our mock client
            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            IHttpClientFactory mockHttpFactory = mockFactory.Object;

            IDealTransactionService iDealTransactionservice = new IDealTransactionService(mockHttpFactory, Mock.Of <ILogger <IDealTransactionService> >());
            IDealTransaction        transaction             = new IDealTransaction()
            {
                ShopID      = 149631,
                Amount      = 2000,
                Bank        = "ABNAL2A",
                Description = "Testing 1. 2.",
                CancelUrl   = "http://development.woonz.nl/DigiWallet/cancel",
                ReturnUrl   = "http://development.woonz.nl/DigiWallet/return",
                ReportUrl   = "http://development.woonz.nl/DigiWallet/report"
            };

            // Act
            StartTransactionResponse startModel = await iDealTransactionservice.StartTransaction(transaction);

            // Assert
            Assert.AreEqual(startModel.TransactionNr, 103084, "Didn't parse transaction ID correctly");
            Assert.AreEqual(startModel.StatusCode, "000000", "Didn't parse statuscode correctly");
            Assert.AreEqual(startModel.Status, StartTransactionResponseCodes.Started, "Didn't interpret success status correctly");
            Assert.AreEqual(startModel.OutboundUrl, "https://pay.digiwallet.nl/consumer/ideal/launch/103084/da85a5e0-b29e-11e8-9332-ecf4cbbfde30/0", "Didn't read outbound URL correctly");
            Assert.IsNull(startModel.ResponseBody, "Set responsebody when it shouldn't have been set");
        }