diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/CoffeeCard.MobilePay.RefundConsoleApp.csproj b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/CoffeeCard.MobilePay.RefundConsoleApp.csproj deleted file mode 100644 index 6eec22c4..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/CoffeeCard.MobilePay.RefundConsoleApp.csproj +++ /dev/null @@ -1,36 +0,0 @@ - - - Exe - net6.0 - DFDD8F8A-7D35-4108-8AA2-B1F46A237155 - enable - - - - appsettings.json - - - www.analogio.dk.pfx - - - Always - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Handler/RefundHandler.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Handler/RefundHandler.cs deleted file mode 100644 index 360dea0d..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Handler/RefundHandler.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.MobilePay.Exception; -using CoffeeCard.MobilePay.RefundConsoleApp.IO; -using CoffeeCard.MobilePay.RefundConsoleApp.Model; -using CoffeeCard.MobilePay.Service; -using CoffeeCard.MobilePay.Service.v1; -using Microsoft.Extensions.Logging; - -namespace CoffeeCard.MobilePay.RefundConsoleApp.Handler -{ - public class RefundHandler - { - private readonly ILogger _log; - private readonly IMobilePayService _mobilePayService; - private readonly IOutputWriter> _outputWriter; - - public RefundHandler(ILogger log, IOutputWriter> outputWriter, - IMobilePayService mobilePayService) - { - _log = log; - _mobilePayService = mobilePayService; - _outputWriter = outputWriter; - } - - public async Task RefundPayments(IEnumerable completedOrders) - { - var results = new List(); - foreach (var completedOrder in completedOrders) - try - { - var result = await _mobilePayService.RefundPayment(completedOrder.OrderId); - _log.LogInformation("SUCCESS Refunded order={result}", result); - - results.Add(new RefundResponse(completedOrder.OrderId, Status.Success) - { - OriginalTransactionId = result.OriginalTransactionId, - RefundTransactionId = result.TransactionId, - Remainder = result.Remainder - }); - } - catch (MobilePayException ex) - { - _log.LogError("FAILED Could not refund order={order}. Error={ex}", completedOrder.OrderId, ex); - results.Add(new RefundResponse(completedOrder.OrderId, Status.Failed)); - } - - await _outputWriter.WriteToFileAsync(results); - } - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/CompletedOrderInputReader.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/CompletedOrderInputReader.cs deleted file mode 100644 index 45d3c82b..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/CompletedOrderInputReader.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using CoffeeCard.MobilePay.RefundConsoleApp.Model; -using Microsoft.Extensions.Logging; - -namespace CoffeeCard.MobilePay.RefundConsoleApp.IO -{ - public class CompletedOrderInputReader : IInputReader - { - private readonly ILogger _log; - - public CompletedOrderInputReader(ILogger log) - { - _log = log; - } - - public async Task> ReadFromCommaSeparatedFile(string path) - { - try - { - string lines; - using (var reader = new StreamReader(path)) - { - lines = await reader.ReadToEndAsync(); - } - - var completedOrders = ParseInputToTransactions(lines); - _log.LogInformation("{size} MobilePay transactions read from {path}", completedOrders.Count, path); - - return completedOrders; - } - catch (IOException ex) - { - _log.LogError("Error reading file. {ex}", ex); - return new List(); - } - } - - private IList ParseInputToTransactions(string lines) - { - var splitLine = lines.Split(","); - - return splitLine.Select(line => new CompletedOrder(line.Trim())).ToList(); - } - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IInputReader.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IInputReader.cs deleted file mode 100644 index f9339cc8..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IInputReader.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using CoffeeCard.MobilePay.RefundConsoleApp.Model; - -namespace CoffeeCard.MobilePay.RefundConsoleApp.IO -{ - public interface IInputReader - { - public Task> ReadFromCommaSeparatedFile(string path); - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IOutputWriter.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IOutputWriter.cs deleted file mode 100644 index 90a29c0f..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/IOutputWriter.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace CoffeeCard.MobilePay.RefundConsoleApp.IO -{ - public interface IOutputWriter - { - Task WriteToFileAsync(T refunds); - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/MobilePayRefundOutputWriter.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/MobilePayRefundOutputWriter.cs deleted file mode 100644 index 5f974dba..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/IO/MobilePayRefundOutputWriter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using CoffeeCard.MobilePay.RefundConsoleApp.Model; -using Microsoft.Extensions.Logging; - -namespace CoffeeCard.MobilePay.RefundConsoleApp.IO -{ - public class MobilePayRefundOutputWriter : IOutputWriter> - { - private const string FileName = "output.txt"; - - private readonly ILogger _log; - - public MobilePayRefundOutputWriter(ILogger log) - { - _log = log; - } - - public async Task WriteToFileAsync(IList refunds) - { - await using var writer = new StreamWriter(FileName); - foreach (var refund in refunds) await writer.WriteLineAsync(refund.ToString()); - - _log.LogInformation("Refund results saved to {filename}", FileName); - } - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/CompletedOrder.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/CompletedOrder.cs deleted file mode 100644 index 5de501cf..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/CompletedOrder.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CoffeeCard.MobilePay.RefundConsoleApp.Model -{ - public class CompletedOrder - { - public string OrderId { get; } - - public CompletedOrder(string orderId) - { - OrderId = orderId; - } - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/RefundResponse.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/RefundResponse.cs deleted file mode 100644 index 7d1985a4..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Model/RefundResponse.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace CoffeeCard.MobilePay.RefundConsoleApp.Model -{ - public class RefundResponse - { - - public RefundResponse(string orderId, Status status) - { - OrderId = orderId; - Status = status; - } - public Status Status { get; } - public string OrderId { get; } - - public string? OriginalTransactionId { get; set; } - public string? RefundTransactionId { get; set; } - public double? Remainder { get; set; } - - public override string ToString() - { - return - $"{nameof(Status)}: {Status}, {nameof(OrderId)}: {OrderId}, {nameof(OriginalTransactionId)}: {OriginalTransactionId}, {nameof(RefundTransactionId)}: {RefundTransactionId}, {nameof(Remainder)}: {Remainder}"; - } - } - - public enum Status - { - Success, - Failed - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Program.cs b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Program.cs deleted file mode 100644 index aab785fd..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/Program.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net.Http; -using System.Threading.Tasks; -using Autofac; -using CoffeeCard.Common.Configuration; -using CoffeeCard.MobilePay.Client; -using CoffeeCard.MobilePay.RefundConsoleApp.Handler; -using CoffeeCard.MobilePay.RefundConsoleApp.IO; -using CoffeeCard.MobilePay.RefundConsoleApp.Model; -using CoffeeCard.MobilePay.Service; -using CoffeeCard.MobilePay.Service.v1; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; - -namespace CoffeeCard.MobilePay.RefundConsoleApp -{ - internal class Program - { - private ILogger _log; - - private IContainer _container; - - protected Program(IContainer container) - { - _container = container; - _log = _container.Resolve>(); - _log.LogInformation("Dependency Injection and configuration setup"); - } - - private static async Task Main() - { - var program = Startup(); - try - { - await program.RefundPayments("input.txt"); - - program._log.LogInformation("Finished processing refunds"); - Environment.Exit(0); - } - catch (System.Exception ex) - { - program._log.LogError("Error while processing refunds. Error={ex}", ex); - Environment.Exit(1); - } - } - - private static Program Startup() - { - // Load Configuration File - var configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", false, true) - .Build(); - - var builder = new ContainerBuilder(); - - // Load MobilePaySettings from Configuration - builder.Register(c => configuration.GetSection("MobilePaySettings").Get()) - .SingleInstance(); - - // setup DI for MobilePay services - builder.RegisterType().As>(); - builder.RegisterType().As>>(); - builder.RegisterType().As(); - builder.RegisterType(); - builder.RegisterType().SingleInstance(); - builder.RegisterType().As().SingleInstance(); - builder.Register(c => new PhysicalFileProvider(Directory.GetCurrentDirectory())).As(); - - builder.Register(l => LoggerFactory.Create(c => c.AddConsole())).As().SingleInstance(); - builder.RegisterGeneric(typeof(Logger<>)).As(typeof(ILogger<>)).SingleInstance(); - - return new Program(builder.Build()); - } - - private async Task RefundPayments(string path) - { - var mpInputReader = _container.Resolve>(); - var completedOrders = await mpInputReader.ReadFromCommaSeparatedFile(path); - - var refundHandler = _container.Resolve(); - await refundHandler.RefundPayments(completedOrders); - } - } -} \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/README.md b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/README.md deleted file mode 100644 index f0209088..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Readme - -Simple ConsoleApp for refunding completed MobilePay orders. - -## Dependencies - -The console app depends on `MobilePaySettings` from the ASP.NET `appsettings.json` file and a MobilePay certificate for -communicating with the MobilePay Appswitch API. - -## How to run - -1. Insert OrderIds in the `input.txt` file, sepereated by a comma -2. Run the conesole app -3. Results will be stored in the `output.txt` file showing which OrderIds were successfully or failed getting refunded \ No newline at end of file diff --git a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/input.txt b/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/input.txt deleted file mode 100644 index 5f282702..00000000 --- a/coffeecard/CoffeeCard.MobilePay.RefundConsoleApp/input.txt +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file