Пример #1
0
        public async Task <Result <CreateMerchantResponse> > Handle(CreateMerchantCommand request, CancellationToken cancellationToken)
        {
            var merchant = await _identityRepository.GetByEmailAsync(request.Email);

            if (merchant != null)
            {
                return(Result.Fail <CreateMerchantResponse>("merchant_already_exists"));
            }
            var newMerchant = _identityRepository.Add(new Merchant(request.Name, request.Email,
                                                                   request.SupportedCurrencies.Split(',').ToList(),
                                                                   request.CommandId));

            var persistenceResult = await _identityRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            if (persistenceResult.IsSuccess)
            {
                return(Result <CreateMerchantResponse> .Ok(new CreateMerchantResponse
                {
                    Id = newMerchant.Id.ToString(),
                    PrivateKey = newMerchant.PrivateKey,
                    PublicKey = newMerchant.PublicKey
                }));
            }

            return(Result.Fail <CreateMerchantResponse>(persistenceResult.Error));
        }
Пример #2
0
        public async Task <IActionResult> CreateMerchant([FromBody] CreateMerchantRequest request)
        {
            var command = new CreateMerchantCommand(request.Name, request.Email, request.SupportedCurrencies, HttpContext.TraceIdentifier);
            var result  = await _mediator.Send(command);

            return(result.IsSuccess
                ? (IActionResult)Ok(result.Value)
                : UnprocessableEntity());
        }
Пример #3
0
        public async Task Handle(MerchantRegisteredIntegrationEvent @event)
        {
            var innerCommand = new CreateMerchantCommand(@event.MerchantId, @event.MerchantName, @event.MerchantEmail,
                                                         @event.PublicKey, @event.PrivateKey, @event.SupportedCurrencies, @event.CommandId);
            var command = new IdentifiedCommand <CreateMerchantCommand, Result>(innerCommand);
            var result  = await _mediator.Send(command);

            if (!result.IsSuccess)
            {
                _logger.LogWarning("Error handling CreateMerchantCommand for integration event : {eventId} and merchant : {id}", @event.Id, @event.MerchantId);
            }
        }
        public void ShouldFail_When_InputWebsiteUrlInValid(string websiteUrl)
        {
            var command = new CreateMerchantCommand
            {
                Currency           = "AUD",
                Country            = "Australia",
                WebsiteUrl         = websiteUrl,
                DiscountPercentage = 10
            };

            var validationResult = _validator.TestValidate(command);

            validationResult.ShouldHaveValidationErrorFor(nameof(CreateMerchantCommand.WebsiteUrl));
        }
        public void ShouldFail_When_InputCountryInValid(string country)
        {
            var command = new CreateMerchantCommand
            {
                Currency           = "AUD",
                Country            = country,
                WebsiteUrl         = "www.test.com",
                DiscountPercentage = 10
            };

            var validationResult = _validator.TestValidate(command);

            validationResult.ShouldHaveValidationErrorFor(nameof(CreateMerchantCommand.Country));
        }
        public void ShouldFail_When_InputDiscountPercentageInValid(decimal discountPercentage)
        {
            var command = new CreateMerchantCommand
            {
                Currency           = "AUD",
                Country            = "Australia",
                WebsiteUrl         = "www.test.com",
                DiscountPercentage = discountPercentage
            };

            var validationResult = _validator.TestValidate(command);

            validationResult.ShouldHaveValidationErrorFor(nameof(CreateMerchantCommand.DiscountPercentage));
        }
        /// <summary>
        /// Creates a new merchant.
        /// </summary>
        /// <param name="model">Merchant Request</param>
        /// <returns></returns>
        public async Task <IActionResult> Post([FromBody] MerchantRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var command = new CreateMerchantCommand()
            {
                Merchant = model
            };
            int result = await _mediator.Send(command);


            return(Ok(result));
        }
        public void ShouldPass_When_InputFormatValid(
            string currency,
            string country,
            string websiteUrl,
            decimal discountPercentage)
        {
            var command = new CreateMerchantCommand
            {
                Currency           = currency,
                Country            = country,
                WebsiteUrl         = websiteUrl,
                DiscountPercentage = discountPercentage
            };

            var validationResult = _validator.TestValidate(command);

            validationResult.ShouldNotHaveAnyValidationErrors();
        }
Пример #9
0
        public async void ShouldGreateMerchantCorrectly()
        {
            var requestBody = new CreateMerchantCommand
            {
                IsActive           = true,
                Currency           = "AUD",
                WebsiteUrl         = "www.test-03.com",
                Country            = "Australia",
                DiscountPercentage = 5.0m
            };

            var requestMessage = MockHelper.CreateHttpRequestMessage(
                URL,
                HttpMethod.Post,
                requestBody);

            var response = await _testFactory.CreateClient().SendAsync(requestMessage);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task <ActionResult> Postmerchant(CreateMerchantCommand payload)
        {
            var result = await _mediatr.Send(payload);

            return(Ok(result));
        }
Пример #11
0
        public async Task <ActionResult> CreateMerchant([FromBody][Required] CreateMerchantCommand request)
        {
            var response = await Mediator.Send(request);

            return(response.ToActionResult());
        }
Пример #12
0
 public async Task <ActionResult <CreateMerchantCommandDto> > Post([FromBody] CreateMerchantCommand payload)
 {
     return(Ok(await _mediatr.Send(payload)));
 }