public void ToPaymentModel_HappyJourney_ReturnsModel() { // Arrange var paymentPostRequest = new PaymentPostRequest { Amount = 100, CardNumber = "1234567890123456", Currency = "USD", ExpiryMonth = 12, ExpiryYear = 2020, MerchantId = Guid.NewGuid(), SecurityCode = 123 }; var bankClientResult = new BankClientResult { TransactionId = Guid.NewGuid(), TransactionStatus = "ok" }; // Act var result = paymentPostRequest.ToPaymentModel(Currency.EUR, bankClientResult); // Assert Assert.NotNull(result); Assert.NotNull(result.TransactionId); Assert.IsType <Payment>(result); }
public async Task <BaseResult <PaymentPostResult> > ProcessPaymentAsync(PaymentPostRequest paymentPostRequest) { var result = new BaseResult <PaymentPostResult>(); var(errors, currency) = await this.ValidatePaymentPostRequest(paymentPostRequest); if (errors.Any()) { result.Errors = errors; return(result); } var bankClientResult = await this.acquiringBankClient.ProcessTransactionAsync(paymentPostRequest.ToBankClientRequest()); if (bankClientResult == null) { result.Errors.Add("bankClient", "Error while processing bank transaction."); return(result); } try { var paymentModel = paymentPostRequest.ToPaymentModel(currency, bankClientResult); var paymentModelResult = await this.paymentRepository.InsertAsync(paymentModel); result.Result = paymentModelResult.ToPostResult(); } catch (Exception ex) { this.logger.LogError("Error while processing payment.", new { Class = nameof(PaymentService), Method = nameof(ProcessPaymentAsync), ex.Message }); result.Errors.Add("paymentProcess", ex.Message); } return(result); }