コード例 #1
0
        public async Task <IActionResult> ProceedPaymentRequest([FromBody] PaymentRequest paymentRequest,
                                                                [FromServices] IGenerateGuid gatewayPaymentIdGenerator,
                                                                [FromServices] IKnowAllPaymentRequests paymentRequestsRepository,
                                                                [FromServices] IProcessPayment paymentProcessor)
        {
            var gatewayPaymentId = gatewayPaymentIdGenerator.Generate();

            var commandResult = await _commandHandler.Handle(paymentRequest.AsCommand(gatewayPaymentId));

            switch (commandResult)
            {
            case SuccessCommandResult <Payment> success:
                var paymentDto = success.Entity.AsDto();

                return(AcceptedAtRoute(nameof(PaymentReadController.GetPaymentInfo),
                                       routeValues: new { gateWayPaymentId = paymentDto.GatewayPaymentId },
                                       value: paymentDto));

            case InvalidCommandResult invalid:
                return(ActionResultHelper.ToActionResult(invalid));

            case FailureCommandResult failure:
                return(ActionResultHelper.ToActionResult(failure));


            default:
                throw new NotSupportedException();
            }
        }