Example #1
0
        public async Task <IActionResult> GetContract([FromRoute] Guid estateId,
                                                      [FromRoute] Guid contractId,
                                                      [FromQuery] Boolean includeProducts,
                                                      [FromQuery] Boolean includeProductsWithFees,
                                                      CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Contract contract = await this.EstateManagementManager.GetContract(estateId, contractId, includeProducts, includeProductsWithFees, cancellationToken);

            if (contract == null)
            {
                throw new NotFoundException($"Contract not found with estate Id {estateId} and contract Id {contractId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(contract)));
        }
        public async Task <IActionResult> GetEstate([FromRoute] Guid estateId,
                                                    CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Estate estate = await this.EstateManagementManager.GetEstate(estateId, cancellationToken);

            if (estate == null)
            {
                throw new NotFoundException($"Estate not found with estate Id {estateId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(estate)));
        }
Example #3
0
        public async Task <IActionResult> DisableTransactionFeeForProduct([FromRoute] Guid estateId,
                                                                          [FromRoute] Guid contractId,
                                                                          [FromRoute] Guid productId,
                                                                          [FromRoute] Guid transactionFeeId,
                                                                          CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Create the command
            DisableTransactionFeeForProductRequest command = DisableTransactionFeeForProductRequest.Create(contractId, estateId,
                                                                                                           productId,
                                                                                                           transactionFeeId);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Ok($"{ContractController.ControllerRoute}/{contractId}/products/{productId}/transactionFees/{transactionFeeId}"));
        }
Example #4
0
        public async Task <IActionResult> AssignOperator([FromRoute] Guid estateId,
                                                         [FromRoute] Guid merchantId,
                                                         AssignOperatorRequestDTO assignOperatorRequest,
                                                         CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            AssignOperatorToMerchantRequest command = AssignOperatorToMerchantRequest.Create(estateId, merchantId, assignOperatorRequest.OperatorId,
                                                                                             assignOperatorRequest.MerchantNumber, assignOperatorRequest.TerminalNumber);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new AssignOperatorResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                OperatorId = assignOperatorRequest.OperatorId
            }));
        }
Example #5
0
        public async Task <IActionResult> GetMerchant([FromRoute] Guid estateId, [FromRoute] Guid merchantId, CancellationToken cancellationToken)
        {
            String estateRoleName   = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("EstateRoleName")) ? "Estate" : Environment.GetEnvironmentVariable("EstateRoleName");
            String merchantRoleName = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MerchantRoleName")) ? "Merchant" : Environment.GetEnvironmentVariable("MerchantRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[]
            {
                estateRoleName,
                merchantRoleName
            }) == false)
            {
                return(this.Forbid());
            }

            Claim estateIdClaim   = null;
            Claim merchantIdClaim = null;

            // Determine the users role
            if (this.User.IsInRole(estateRoleName))
            {
                // Estate user
                // Get the Estate Id claim from the user
                estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId");
            }

            if (this.User.IsInRole(merchantRoleName))
            {
                // Get the merchant Id claim from the user
                estateIdClaim   = ClaimsHelper.GetUserClaim(this.User, "EstateId");
                merchantIdClaim = ClaimsHelper.GetUserClaim(this.User, "MerchantId");
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(merchantId, merchantIdClaim) == false)
            {
                return(this.Forbid());
            }

            Merchant merchant = await this.EstateManagementManager.GetMerchant(estateId, merchantId, cancellationToken);

            if (merchant == null)
            {
                throw new NotFoundException($"Merchant not found with estate Id {estateId} and merchant Id {merchantId}");
            }

            MerchantBalance merchantBalance = await this.EstateManagementManager.GetMerchantBalance(estateId, merchantId, cancellationToken);

            if (merchantBalance == null)
            {
                throw new NotFoundException($"Merchant Balance details not found with estate Id {estateId} and merchant Id {merchantId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(merchant, merchantBalance)));
        }
Example #6
0
        public async Task <IActionResult> MakeDeposit([FromRoute] Guid estateId,
                                                      [FromRoute] Guid merchantId,
                                                      [FromBody] MakeMerchantDepositRequestDTO makeMerchantDepositRequest,
                                                      CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Convert the source
            Models.MerchantDepositSource merchantDepositSourceModel = Models.MerchantDepositSource.NotSet;
            switch (makeMerchantDepositRequest.Source)
            {
            case MerchantDepositSource.Manual:
                merchantDepositSourceModel = Models.MerchantDepositSource.Manual;
                break;

            case MerchantDepositSource.Automatic:
                merchantDepositSourceModel = Models.MerchantDepositSource.Automatic;
                break;

            default:
                merchantDepositSourceModel = Models.MerchantDepositSource.Manual;
                break;
            }

            MakeMerchantDepositRequest command = MakeMerchantDepositRequest.Create(estateId,
                                                                                   merchantId,
                                                                                   merchantDepositSourceModel,
                                                                                   makeMerchantDepositRequest.Reference,
                                                                                   makeMerchantDepositRequest.DepositDateTime,
                                                                                   makeMerchantDepositRequest.Amount);

            // Route the command
            Guid depositId = await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new MakeMerchantDepositResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                DepositId = depositId
            }));
        }
Example #7
0
        public async Task <IActionResult> CreateMerchant([FromRoute] Guid estateId,
                                                         [FromBody] CreateMerchantRequestDTO createMerchantRequest,
                                                         CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid merchantId = Guid.NewGuid();

            // Create the command
            CreateMerchantRequest command = CreateMerchantRequest.Create(estateId,
                                                                         merchantId,
                                                                         createMerchantRequest.Name,
                                                                         createMerchantRequest.Address.AddressLine1,
                                                                         createMerchantRequest.Address.AddressLine2,
                                                                         createMerchantRequest.Address.AddressLine3,
                                                                         createMerchantRequest.Address.AddressLine4,
                                                                         createMerchantRequest.Address.Town,
                                                                         createMerchantRequest.Address.Region,
                                                                         createMerchantRequest.Address.PostalCode,
                                                                         createMerchantRequest.Address.Country,
                                                                         createMerchantRequest.Contact.ContactName,
                                                                         createMerchantRequest.Contact.PhoneNumber,
                                                                         createMerchantRequest.Contact.EmailAddress);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new CreateMerchantResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                AddressId = command.AddressId,
                ContactId = command.ContactId
            }));
        }
Example #8
0
        public async Task <IActionResult> GetTransactionFeesForProduct([FromRoute] Guid estateId,
                                                                       [FromRoute] Guid merchantId,
                                                                       [FromRoute] Guid contractId,
                                                                       [FromRoute] Guid productId,
                                                                       CancellationToken cancellationToken)
        {
            String estateRoleName   = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("EstateRoleName")) ? "Estate" : Environment.GetEnvironmentVariable("EstateRoleName");
            String merchantRoleName = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MerchantRoleName")) ? "Merchant" : Environment.GetEnvironmentVariable("MerchantRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[]
            {
                estateRoleName,
                merchantRoleName
            }) == false)
            {
                return(this.Forbid());
            }

            Claim estateIdClaim   = null;
            Claim merchantIdClaim = null;

            // Determine the users role
            if (this.User.IsInRole(estateRoleName))
            {
                // Estate user
                // Get the Estate Id claim from the user
                estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId");
            }

            if (this.User.IsInRole(merchantRoleName))
            {
                // Get the merchant Id claim from the user
                estateIdClaim   = ClaimsHelper.GetUserClaim(this.User, "EstateId");
                merchantIdClaim = ClaimsHelper.GetUserClaim(this.User, "MerchantId");
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(merchantId, merchantIdClaim) == false)
            {
                return(this.Forbid());
            }

            List <TransactionFee> transactionFees = await this.EstateManagementManager.GetTransactionFeesForProduct(estateId, merchantId, contractId, productId, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(transactionFees)));
        }
Example #9
0
        public async Task <IActionResult> AddTransactionFeeForProductToContract([FromRoute] Guid estateId,
                                                                                [FromRoute] Guid contractId,
                                                                                [FromRoute] Guid productId,
                                                                                [FromBody] AddTransactionFeeForProductToContractRequestDTO addTransactionFeeForProductToContractRequest,
                                                                                CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid transactionFeeId = Guid.NewGuid();

            Models.Contract.CalculationType calculationType = (Models.Contract.CalculationType)addTransactionFeeForProductToContractRequest.CalculationType;
            Models.Contract.FeeType         feeType         = (Models.Contract.FeeType)addTransactionFeeForProductToContractRequest.FeeType;

            // Create the command
            AddTransactionFeeForProductToContractRequest command = AddTransactionFeeForProductToContractRequest.Create(contractId, estateId,
                                                                                                                       productId,
                                                                                                                       transactionFeeId,
                                                                                                                       addTransactionFeeForProductToContractRequest.Description,
                                                                                                                       calculationType,
                                                                                                                       feeType,
                                                                                                                       addTransactionFeeForProductToContractRequest.Value);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{ContractController.ControllerRoute}/{contractId}/products/{productId}/transactionFees/{transactionFeeId}",
                                new AddTransactionFeeForProductToContractResponse
            {
                EstateId = estateId,
                ContractId = contractId,
                ProductId = productId,
                TransactionFeeId = transactionFeeId
            }));
        }
Example #10
0
        public async Task <IActionResult> GetContracts([FromRoute] Guid estateId,
                                                       CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            List <Contract> contracts = await this.EstateManagementManager.GetContracts(estateId, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(contracts)));
        }
Example #11
0
        public async Task <IActionResult> CreateMerchantUser([FromRoute] Guid estateId,
                                                             [FromRoute] Guid merchantId,
                                                             [FromBody] CreateMerchantUserRequestDTO createMerchantUserRequest,
                                                             CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Create the command
            CreateMerchantUserRequest request = CreateMerchantUserRequest.Create(estateId, merchantId, createMerchantUserRequest.EmailAddress,
                                                                                 createMerchantUserRequest.Password,
                                                                                 createMerchantUserRequest.GivenName,
                                                                                 createMerchantUserRequest.MiddleName,
                                                                                 createMerchantUserRequest.FamilyName);

            // Route the command
            Guid userId = await this.Mediator.Send(request, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}/users/{userId}",
                                new CreateMerchantUserResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                UserId = userId
            }));
        }
Example #12
0
        public async Task <IActionResult> CreateContract([FromRoute] Guid estateId,
                                                         [FromBody] CreateContractRequestDTO createContractRequest,
                                                         CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid contractId = Guid.NewGuid();

            // Create the command
            CreateContractRequest command = CreateContractRequest.Create(contractId, estateId, createContractRequest.OperatorId, createContractRequest.Description);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{ContractController.ControllerRoute}/{contractId}",
                                new CreateContractResponse
            {
                EstateId = estateId,
                OperatorId = command.OperatorId,
                ContractId = contractId
            }));
        }
Example #13
0
        public async Task <IActionResult> AddDevice([FromRoute] Guid estateId,
                                                    [FromRoute] Guid merchantId,
                                                    [FromBody] AddMerchantDeviceRequestDTO addMerchantDeviceRequest,
                                                    CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid deviceId = Guid.NewGuid();

            AddMerchantDeviceRequest command = AddMerchantDeviceRequest.Create(estateId, merchantId, deviceId, addMerchantDeviceRequest.DeviceIdentifier);

            // Route the command
            await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new AddMerchantDeviceResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                DeviceId = deviceId
            }));
        }