Exemplo n.º 1
0
        public static async Task AsyncMain()
        {
            var configuration   = GetConfigurationBuilder();
            var serviceProvider = GetServiceProvider(configuration);

            var issuerRepo = serviceProvider.GetService <IIDealIssuerRepository>();
            var iDealTransactionService  = serviceProvider.GetService <IIDealTransactionService>();
            var transactionStatusService = serviceProvider.GetService <ITransactionStatusService>();
            var logger = serviceProvider.GetRequiredService <ILogger <Program> >();

            logger.LogDebug("GETTING ISSUERS");
            var issuers = await issuerRepo.GetIssuers();

            logger.LogDebug(string.Format("Found {0} issuers", issuers.Count()));
            logger.LogDebug(string.Join("\n", issuers.Select(issuer => string.Format("ID: {0}, Name: {1}", issuer.Id, issuer.BankName))));

            var result = await iDealTransactionService.StartTransaction(new Models.Transaction.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"
            });

            logger.LogDebug(string.Format("== Transaction response ===\nStatuscode: {0}\nStatus enum: {1}\nResponse body {2}", result.StatusCode, result.Status, result.ResponseBody));
            logger.LogDebug($"Outbound URL: {result.OutboundUrl}");

            if (result.Status == StartTransactionResponseCodes.Started)
            {
                var checkModel = new TransactionStatusRequestModel()
                {
                    ApiEndpoint           = "ideal/check",
                    ShopID                = 149631,
                    TransactionID         = result.TransactionNr,
                    RestrictResponseCount = true,
                    TestMode              = true
                };

                logger.LogDebug("Started transaction check loop, press ctrl + c to quit");

                while (true)
                {
                    var currentStatus = await transactionStatusService.CheckTransaction(checkModel);

                    logger.LogInformation(string.Format("== Current Status ===\nStatuscode: {0}\nStatus enum: {1}\nResponse body {2}", currentStatus.StatusCode, currentStatus.Status, currentStatus.ResponseBody));
                    Thread.Sleep(10000);
                }
            }
            else
            {
                logger.LogWarning("Failed to start transaction");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks transaction state with DigiWallet. This functionality is the same for every transaction provider.
        /// Currently, you need to set the API endpoints manually in the <see cref="TransactionStatusRequestModel"/>.
        /// Make sure they match the values in the <see cref="Models.Transaction.TransactionBase.CheckApi"/> implementation value.
        /// </summary>
        /// <param name="requestModel"></param>
        /// <returns></returns>
        public async Task <TransactionStatusResponseModel> CheckTransaction(TransactionStatusRequestModel requestModel)
        {
            var response = await this.ApiPost(requestModel.ApiEndpoint, new Dictionary <string, string>
            {
                { "rtlo", requestModel.ShopID.ToString() },
                { "trxid", requestModel.TransactionID.ToString() },
                { "test", requestModel.TestMode ? "1" : "0" },
                { "once", requestModel.RestrictResponseCount ? "1" : "0" }
            });

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

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

                return(new TransactionStatusResponseModel(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");
        }