Esempio n. 1
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateMerchantRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorResponse().AddErrors(ModelState)));
            }

            try
            {
                var merchant = Mapper.Map <Merchant>(request);

                IMerchant createdMerchant = await _merchantService.CreateAsync(merchant);

                return(Ok(Mapper.Map <MerchantModel>(createdMerchant)));
            }
            catch (Exception exception) when(exception is DuplicateMerchantNameException ||
                                             exception is DuplicateMerchantApiKeyException)
            {
                await _log.WriteWarningAsync(nameof(MerchantsController), nameof(CreateAsync), request.ToJson(),
                                             exception);

                return(BadRequest(ErrorResponse.Create(exception.Message)));
            }
            catch (Exception exception)
            {
                await _log.WriteErrorAsync(nameof(MerchantsController), nameof(CreateAsync), request.ToJson(),
                                           exception);

                throw;
            }
        }
        public BaseResponse <GetMerchantResponse, ErrorsResponse> CreateMerchant(CreateMerchantRequest request)
        {
            var method   = HttpMethod.Post;
            var endpoint = $"/merchants";

            return(this.SendRequest <GetMerchantResponse>(method, endpoint, request, authMode: "token"));
        }
Esempio n. 3
0
        public void CreateMerchantRequest_CanBeCreated_IsCreated()
        {
            CreateMerchantRequest createMerchantRequest = CreateMerchantRequest.Create(TestData.EstateId, TestData.MerchantId,
                                                                                       TestData.MerchantName, TestData.MerchantAddressLine1,
                                                                                       TestData.MerchantAddressLine2, TestData.MerchantAddressLine3,
                                                                                       TestData.MerchantAddressLine4, TestData.MerchantTown,
                                                                                       TestData.MerchantRegion, TestData.MerchantPostalCode, TestData.MerchantCountry,
                                                                                       TestData.MerchantContactName, TestData.MerchantContactPhoneNumber,
                                                                                       TestData.MerchantContactEmailAddress);

            createMerchantRequest.ShouldNotBeNull();
            createMerchantRequest.EstateId.ShouldBe(TestData.EstateId);
            createMerchantRequest.MerchantId.ShouldBe(TestData.MerchantId);
            createMerchantRequest.Name.ShouldBe(TestData.MerchantName);
            createMerchantRequest.AddressLine1.ShouldBe(TestData.MerchantAddressLine1);
            createMerchantRequest.AddressLine2.ShouldBe(TestData.MerchantAddressLine2);
            createMerchantRequest.AddressLine3.ShouldBe(TestData.MerchantAddressLine3);
            createMerchantRequest.AddressLine4.ShouldBe(TestData.MerchantAddressLine4);
            createMerchantRequest.Town.ShouldBe(TestData.MerchantTown);
            createMerchantRequest.Region.ShouldBe(TestData.MerchantRegion);
            createMerchantRequest.PostalCode.ShouldBe(TestData.MerchantPostalCode);
            createMerchantRequest.Country.ShouldBe(TestData.MerchantCountry);
            createMerchantRequest.ContactName.ShouldBe(TestData.MerchantContactName);
            createMerchantRequest.ContactPhoneNumber.ShouldBe(TestData.MerchantContactPhoneNumber);
            createMerchantRequest.ContactEmailAddress.ShouldBe(TestData.MerchantContactEmailAddress);
        }
        public async Task <IActionResult> CreateAsync([FromBody] CreateMerchantRequest request)
        {
            try
            {
                var merchant = Mapper.Map <Merchant>(request);

                IMerchant createdMerchant = await _merchantService.CreateAsync(merchant);

                return(Ok(Mapper.Map <MerchantModel>(createdMerchant)));
            }
            catch (InvalidRowKeyValueException e)
            {
                _log.Error(e, $"{e.Variable}: {e.Value}");

                return(BadRequest(ErrorResponse.Create(e.Message)));
            }
            catch (Exception exception) when(exception is DuplicateMerchantNameException ||
                                             exception is DuplicateMerchantApiKeyException ||
                                             exception is DuplicateMerchantEmailException)
            {
                _log.Warning(exception.Message, context: request.ToDetails());

                return(BadRequest(ErrorResponse.Create(exception.Message)));
            }
        }
Esempio n. 5
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());
        }
Esempio n. 6
0
        public void MerchantRequestHandler_CreateMerchantRequest_IsHandled()
        {
            Mock <IMerchantDomainService> merchantDomainService = new Mock <IMerchantDomainService>();
            MerchantRequestHandler        handler = new MerchantRequestHandler(merchantDomainService.Object);

            CreateMerchantRequest request = TestData.CreateMerchantRequest;

            Should.NotThrow(async() =>
            {
                await handler.Handle(request, CancellationToken.None);
            });
        }
Esempio n. 7
0
 public void TestInitialize()
 {
     _appService            = new PaylikeAppService(string.Empty);
     _createMerchantRequest = new CreateMerchantRequest()
     {
         Name       = "TestMerchant_" + DateTime.Now.Ticks.ToString(),
         Currency   = Currency.EUR,
         Test       = true,
         Email      = "*****@*****.**",
         Website    = "test.com",
         Descriptor = "descriptor",
         Company    = new Company()
         {
             Country = Country.Austria
         },
         Bank = new Bank()
         {
             IBAN = "NL18ABNA0484869868"
         }
     };
 }
Esempio n. 8
0
        /// <summary>
        /// Creates the merchant.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="createMerchantRequest">The create merchant request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateMerchantResponse> CreateMerchant(String accessToken,
                                                                  Guid estateId,
                                                                  CreateMerchantRequest createMerchantRequest,
                                                                  CancellationToken cancellationToken)
        {
            CreateMerchantResponse response = null;

            String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants");

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(createMerchantRequest);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <CreateMerchantResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error creating new merchant {createMerchantRequest.Name} for estate {estateId}.", ex);

                throw exception;
            }

            return(response);
        }
        public async Task WhenICreateTheFollowingMerchants(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                // lookup the estate id based on the name in the table
                EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow);
                String        token         = this.TestingContext.AccessToken;
                if (String.IsNullOrEmpty(estateDetails.AccessToken) == false)
                {
                    token = estateDetails.AccessToken;
                }

                String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName");
                CreateMerchantRequest createMerchantRequest = new CreateMerchantRequest
                {
                    Name    = merchantName,
                    Contact = new Contact
                    {
                        ContactName  = SpecflowTableHelper.GetStringRowValue(tableRow, "ContactName"),
                        EmailAddress = SpecflowTableHelper.GetStringRowValue(tableRow, "EmailAddress")
                    },
                    Address = new Address
                    {
                        AddressLine1 = SpecflowTableHelper.GetStringRowValue(tableRow, "AddressLine1"),
                        Town         = SpecflowTableHelper.GetStringRowValue(tableRow, "Town"),
                        Region       = SpecflowTableHelper.GetStringRowValue(tableRow, "Region"),
                        Country      = SpecflowTableHelper.GetStringRowValue(tableRow, "Country")
                    }
                };

                CreateMerchantResponse response = await this.TestingContext.DockerHelper.EstateClient
                                                  .CreateMerchant(token, estateDetails.EstateId, createMerchantRequest, CancellationToken.None).ConfigureAwait(false);

                response.ShouldNotBeNull();
                response.EstateId.ShouldBe(estateDetails.EstateId);
                response.MerchantId.ShouldNotBe(Guid.Empty);

                // Cache the merchant id
                estateDetails.AddMerchant(response.MerchantId, merchantName);

                this.TestingContext.Logger.LogInformation($"Merchant {merchantName} created with Id {response.MerchantId} for Estate {estateDetails.EstateName}");
            }

            foreach (TableRow tableRow in table.Rows)
            {
                EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow);

                String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName");

                Guid merchantId = estateDetails.GetMerchantId(merchantName);

                String token = this.TestingContext.AccessToken;
                if (String.IsNullOrEmpty(estateDetails.AccessToken) == false)
                {
                    token = estateDetails.AccessToken;
                }

                await Retry.For(async() =>
                {
                    MerchantResponse merchant = await this.TestingContext.DockerHelper.EstateClient
                                                .GetMerchant(token, estateDetails.EstateId, merchantId, CancellationToken.None)
                                                .ConfigureAwait(false);

                    merchant.MerchantName.ShouldBe(merchantName);
                });
            }
        }
Esempio n. 10
0
 public ApiResponse <Merchant> CreateMerchant(CreateMerchantRequest request)
 {
     return(SendApiRequest <CreateMerchantRequest, Merchant>(request));
 }
Esempio n. 11
0
 public Task <MerchantModel> CreateMerchantAsync(CreateMerchantRequest request)
 {
     return(_runner.RunWithDefaultErrorHandlingAsync(() => _merchantsApi.CreateAsync(request)));
 }