public async Task <PaymentTransaction> Save(TransactionResponse transactionResponse, PaymentCommand paymentCommand) { var transactionId = RandomGenerator.Next(); var transaction = new PaymentTransaction { Amount = paymentCommand.Amount, Card = new Card { ExpiryMonth = paymentCommand.ExpiryMonth, ExpiryYear = paymentCommand.ExpiryYear, Number = paymentCommand.CardNumber }, CurrencyCode = paymentCommand.CurrencyCode, Status = transactionResponse.Status, BankTransactionReferenceId = transactionResponse.TransactionId, Message = transactionResponse.Message, Id = transactionId }; var fileName = Path.Combine(_appSettings.Value.PaymentsDirectoryBasePath, transactionId.ToString()); await File.WriteAllTextAsync(fileName, JsonConvert.SerializeObject(transaction)); return(transaction); }
public async Task <PaymentTransaction> HandleAsync(PaymentCommand paymentCommand) { var validationResult = await _paymentCommandValidator.ValidateAsync(paymentCommand); if (!validationResult.IsValid) { throw new PaymentCommandException(paymentCommand, validationResult.ToString(), 1002); } var transactionResponse = await _paymentProcessor.ProcessPayment(paymentCommand); return(await _paymentCommandRepository.Save(transactionResponse, paymentCommand)); }
public PaymentCommandException(PaymentCommand paymentCommand, string errorMessage, int errorCode) { PaymentCommand = paymentCommand; Errors = errorMessage; ErrorCode = errorCode; }