public async Task <bool> ProcessPayment(Domain.Orders.Order order, PaymentDTO payment) { var orderRequest = new OrderInProcessingIntegrationEvent() { OrderId = order.Id, CustomerId = order.CustomerId, Price = order.Amount, PaymentType = 1, //TODO: Implement the proper type in the future CardName = payment.CardHolderName, CardNumber = payment.CardNumber, Expiration = payment.CardExpiration, CVV = payment.CardCvv }; var response = await _messageBus.RequestAsync <OrderInProcessingIntegrationEvent, ResponseMessage>(orderRequest); if (response.ValidResult.IsValid) { return(true); } foreach (var error in response.ValidResult.Errors) { AddError(error.ErrorMessage); } return(false); }
private async Task <ResponseMessage> AuthorizePayment(OrderInProcessingIntegrationEvent message) { ResponseMessage response; using var scope = _serviceProvider.CreateScope(); var paymentService = scope.ServiceProvider.GetRequiredService <IPaymentService>(); var payment = new Payment { OrderId = message.OrderId, PaymentMethod = (PaymentMethod)message.PaymentType, Price = message.Price, CreditCard = new CreditCard(message.CardName, message.CardNumber, message.Expiration, message.CVV) }; response = await paymentService.AuthorizePayment(payment); return(response); }