public Task ProcessPaymentAsync(PaymentRequest paymentRequest) { var processor = _processorFactory.CreateProcessor(paymentRequest.RequestType); if (processor == null) { throw new NotImplementedException($"Processor is not found for {paymentRequest.RequestType}"); } return(processor.ProcessAsync(paymentRequest)); }
public IActionResult Create([FromBody] CreateOrderRequest orderRequest) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(new { Message = "request object can not be validated!" })); } try { var order = _mapper.Map <Order>(orderRequest); var processor = _processorFactory.CreateProcessor(order.PaymentGateway); var receipt = processor.Process(order); return(Ok(new CreateOrderResponse { Receipt = _mapper.Map <ReceiptModel>(receipt) })); } catch (Exception exception) { _logger.LogError("exception occured in Create", exception); return(BadRequest(new CreateOrderResponse { Receipt = new ReceiptModel() { CreationDate = DateTime.UtcNow, OrderNumber = orderRequest.OrderNumber, Status = OrderStatusInfo.Failed } })); } }
internal IProcessor CreateProcessorMock(Type requestType) { return(ProcessorFactoryMock.CreateProcessor(requestType)); }
public Calculator(IProcessorFactory processorFactory) { Processor = processorFactory.CreateProcessor(); }
/// <summary> /// Create new <see cref="HomeController" /> instance. /// </summary> /// <param name="processorFactory">factory for create processor class.</param> public HomeController(IProcessorFactory processorFactory) { Processor = processorFactory.CreateProcessor(); }