public async Task <IActionResult> MakePayment([FromBody] MakePaymentCommandDto commandDto) { var command = _mapper.Map <MakePaymentCommand>(commandDto); var response = await _mediator.Send(command); if (response.Status.Equals("success")) { _logger.Information("{Timestamp} {EventId} {Message}", DateTime.UtcNow.ToString(), response.Id.ToString(), "Payment successful"); return(Created(nameof(MakePaymentCommand), new { response.Id })); } else { if (response.ValidationErrors.Count > 0) { _logger.Information("{Timestamp} {EventId} {Message}", DateTime.UtcNow.ToString(), response.Reason); } else { _logger.Information("{Timestamp} {EventId} {Message}", DateTime.UtcNow.ToString(), response.Id.ToString(), response.Reason); } // Not quite sure what HTTP status code should be used for a failed request? return(BadRequest(new { response.Reason })); } }
private static (MakePaymentCommandDto, MakePaymentCommand) CreateFakeMakePaymentCommandAndDto() { var merchantPaymentId = "15359b7d-4e92-4a02-b303-f7529277fe05"; var billingDetails = new BillingDetails { Name = "Test User", CardType = "visa", CardNumber = "4000100020003000", ExpiryMonth = 12, ExpiryYear = 2022, Cvv = "155", BillingAddress = new BillingAddress() { Title = "Mr", FirstName = "Test", LastName = "User", Country = "United Kingdom", Address1 = "Test Address Line 1", Address2 = "Test Address Line 2", Postcode = "ABC DEF" } }; var currency = "GBP"; var amount = 100; var makePaymentCommandDto = new MakePaymentCommandDto { MerchantPaymentId = merchantPaymentId, BillingDetails = billingDetails, Currency = currency, Amount = amount }; var makePaymentCommand = new MakePaymentCommand { MerchantPaymentId = merchantPaymentId, BillingDetails = billingDetails, Currency = currency, Amount = amount }; return(makePaymentCommandDto, makePaymentCommand); }