예제 #1
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)));
        }
        public void ModelFactory_MerchantBalance_NullInput_IsConverted()
        {
            MerchantBalance merchantBalanceModel = null;

            ModelFactory modelFactory = new ModelFactory();

            MerchantBalanceResponse merchantBalanceResponse = modelFactory.ConvertFrom(merchantBalanceModel);

            merchantBalanceResponse.ShouldBeNull();
        }
        public void ModelFactory_MerchantBalance_IsConverted()
        {
            MerchantBalance merchantBalanceModel = TestData.MerchantBalanceModel;

            ModelFactory modelFactory = new ModelFactory();

            MerchantBalanceResponse merchantBalanceResponse = modelFactory.ConvertFrom(merchantBalanceModel);

            merchantBalanceResponse.ShouldNotBeNull();
            merchantBalanceResponse.MerchantId.ShouldBe(merchantBalanceModel.MerchantId);
            merchantBalanceResponse.EstateId.ShouldBe(merchantBalanceModel.EstateId);
            merchantBalanceResponse.AvailableBalance.ShouldBe(merchantBalanceModel.AvailableBalance);
            merchantBalanceResponse.Balance.ShouldBe(merchantBalanceModel.Balance);
        }
예제 #4
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="merchantBalance"></param>
        /// <returns></returns>
        public MerchantBalanceResponse ConvertFrom(MerchantBalance merchantBalance)
        {
            if (merchantBalance == null)
            {
                return(null);
            }

            return(new MerchantBalanceResponse
            {
                MerchantId = merchantBalance.MerchantId,
                EstateId = merchantBalance.EstateId,
                AvailableBalance = merchantBalance.AvailableBalance,
                Balance = merchantBalance.Balance
            });
        }
        public void ModelFactory_Merchant_WithBalance_IsConverted()
        {
            Merchant merchantModel = TestData.MerchantModelWithAddressesContactsDevicesAndOperators;
            MerchantBalance merchantBalanceModel = TestData.MerchantBalanceModel;

            ModelFactory modelFactory = new ModelFactory();

            MerchantResponse merchantResponse = modelFactory.ConvertFrom(merchantModel, merchantBalanceModel);

            merchantResponse.ShouldNotBeNull();
            merchantResponse.MerchantId.ShouldBe(merchantModel.MerchantId);
            merchantResponse.MerchantName.ShouldBe(merchantModel.MerchantName);
            merchantResponse.EstateId.ShouldBe(merchantModel.EstateId);
            merchantResponse.Addresses.ShouldHaveSingleItem();

            AddressResponse addressResponse = merchantResponse.Addresses.Single();
            addressResponse.AddressId.ShouldBe(merchantModel.Addresses.Single().AddressId);
            addressResponse.AddressLine1.ShouldBe(merchantModel.Addresses.Single().AddressLine1);
            addressResponse.AddressLine2.ShouldBe(merchantModel.Addresses.Single().AddressLine2);
            addressResponse.AddressLine3.ShouldBe(merchantModel.Addresses.Single().AddressLine3);
            addressResponse.AddressLine4.ShouldBe(merchantModel.Addresses.Single().AddressLine4);
            addressResponse.Town.ShouldBe(merchantModel.Addresses.Single().Town);
            addressResponse.Region.ShouldBe(merchantModel.Addresses.Single().Region);
            addressResponse.Country.ShouldBe(merchantModel.Addresses.Single().Country);
            addressResponse.PostalCode.ShouldBe(merchantModel.Addresses.Single().PostalCode);

            merchantResponse.Contacts.ShouldHaveSingleItem();
            ContactResponse contactResponse = merchantResponse.Contacts.Single();
            contactResponse.ContactId.ShouldBe(merchantModel.Contacts.Single().ContactId);
            contactResponse.ContactEmailAddress.ShouldBe(merchantModel.Contacts.Single().ContactEmailAddress);
            contactResponse.ContactName.ShouldBe(merchantModel.Contacts.Single().ContactName);
            contactResponse.ContactPhoneNumber.ShouldBe(merchantModel.Contacts.Single().ContactPhoneNumber);

            merchantResponse.AvailableBalance.ShouldBe(merchantBalanceModel.AvailableBalance);
            merchantResponse.Balance.ShouldBe(merchantBalanceModel.Balance);
        }
예제 #6
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="merchant">The merchant.</param>
        /// <returns></returns>
        public MerchantResponse ConvertFrom(Merchant merchant,
                                            MerchantBalance merchantBalance = null)
        {
            if (merchant == null)
            {
                return(null);
            }

            MerchantResponse merchantResponse = new MerchantResponse
            {
                EstateId     = merchant.EstateId,
                MerchantId   = merchant.MerchantId,
                MerchantName = merchant.MerchantName,
            };

            if (merchant.Addresses != null && merchant.Addresses.Any())
            {
                merchantResponse.Addresses = new List <AddressResponse>();

                merchant.Addresses.ForEach(a => merchantResponse.Addresses.Add(new AddressResponse
                {
                    AddressId    = a.AddressId,
                    Town         = a.Town,
                    Region       = a.Region,
                    PostalCode   = a.PostalCode,
                    Country      = a.Country,
                    AddressLine1 = a.AddressLine1,
                    AddressLine2 = a.AddressLine2,
                    AddressLine3 = a.AddressLine3,
                    AddressLine4 = a.AddressLine4
                }));
            }

            if (merchant.Contacts != null && merchant.Contacts.Any())
            {
                merchantResponse.Contacts = new List <ContactResponse>();

                merchant.Contacts.ForEach(c => merchantResponse.Contacts.Add(new ContactResponse
                {
                    ContactId           = c.ContactId,
                    ContactPhoneNumber  = c.ContactPhoneNumber,
                    ContactEmailAddress = c.ContactEmailAddress,
                    ContactName         = c.ContactName
                }));
            }

            if (merchant.Devices != null && merchant.Devices.Any())
            {
                merchantResponse.Devices = new Dictionary <Guid, String>();

                foreach ((Guid key, String value) in merchant.Devices)
                {
                    merchantResponse.Devices.Add(key, value);
                }
            }

            if (merchant.Operators != null && merchant.Operators.Any())
            {
                merchantResponse.Operators = new List <MerchantOperatorResponse>();

                merchant.Operators.ForEach(a => merchantResponse.Operators.Add(new MerchantOperatorResponse
                {
                    Name           = a.Name,
                    MerchantNumber = a.MerchantNumber,
                    OperatorId     = a.OperatorId,
                    TerminalNumber = a.TerminalNumber
                }));
            }

            // Only include the balance if the dto fed in is not null
            if (merchantBalance != null)
            {
                merchantResponse.AvailableBalance = merchantBalance.AvailableBalance;
                merchantResponse.Balance          = merchantBalance.Balance;
            }

            return(merchantResponse);
        }