Esempio n. 1
0
        private void ValidateCreatePaymentLevelModel(EditPaymentLevel model, Brand.Interface.Data.Brand brand)
        {
            if (brand == null)
            {
                throw new RegoException("app:common.invalidBrand");
            }

            var currency = brand.BrandCurrencies.SingleOrDefault(c => c.CurrencyCode == model.Currency);

            if (currency == null)
            {
                throw new RegoException("app:payment.invalidCurrency");
            }

            var paymentLevels = _paymentQueries.GetPaymentLevels(brand.Id);

            if (paymentLevels.Any(pl => pl.Name == model.Name && pl.BrandId == brand.Id && pl.Id != model.Id))
            {
                throw new RegoException("app:payment.levelNameUnique");
            }

            if (paymentLevels.Any(pl => pl.Code == model.Code && pl.BrandId == brand.Id && pl.Id != model.Id))
            {
                throw new RegoException("app:payment.levelCodeUnique");
            }

            if (model.IsDefault &&
                paymentLevels.Any(
                    pl => pl.Id != model.Id && pl.BrandId == model.Brand && pl.CurrencyCode == model.Currency && pl.IsDefault))
            {
                throw new RegoException("Default payment level for the brand and currency combination already exists.");
            }
        }
Esempio n. 2
0
        public void Cannot_save_payment_level_with_invalid_brand()
        {
            // Arrange
            var brandTestHelper   = Container.Resolve <BrandTestHelper>();
            var paymentTestHelper = Container.Resolve <PaymentTestHelper>();

            var licensee     = brandTestHelper.CreateLicensee();
            var brand        = brandTestHelper.CreateBrand(licensee, isActive: true);
            var paymentLevel = paymentTestHelper.CreatePaymentLevel(brand.Id, brand.DefaultCurrency);

            var data = new EditPaymentLevel
            {
                Id                   = paymentLevel.Id,
                Brand                = brand.Id,
                Name                 = TestDataGenerator.GetRandomString(6, "0123456789ABCDEF"),
                Code                 = TestDataGenerator.GetRandomString(6, "0123456789ABCDEF"),
                Currency             = "CAD",
                EnableOfflineDeposit = true,
                IsDefault            = false,
                BankAccounts         = null
            };

            LogWithNewAdmin(Modules.PaymentLevelManager, Permissions.Update);

            // Act
            Assert.Throws <InsufficientPermissionsException>(() => _paymentLevelCommands.Save(data));
        }
Esempio n. 3
0
 private void FillBankReceipts(EditPaymentLevel model, IQueryable <BankAccount> accounts)
 {
     foreach (var account in accounts)
     {
         account.InternetSameBank            = model.InternetSameBankSelection.Contains(account.Id);
         account.AtmSameBank                 = model.AtmSameBankSelection.Contains(account.Id);
         account.CounterDepositSameBank      = model.CounterDepositSameBankSelection.Contains(account.Id);
         account.InternetDifferentBank       = model.InternetDifferentBankSelection.Contains(account.Id);
         account.AtmDifferentBank            = model.AtmDifferentBankSelection.Contains(account.Id);
         account.CounterDepositDifferentBank = model.CounterDepositDifferentBankSelection.Contains(account.Id);
     }
 }
Esempio n. 4
0
        private IEnumerable <PaymentGatewaySettings> GetPaymentGatewaySettings(EditPaymentLevel model)
        {
            List <PaymentGatewaySettings> paymentGatewaySettings = null;

            if (model.PaymentGatewaySettings != null)
            {
                var paymentGatewaySettingsIds = model.PaymentGatewaySettings.Select(ba => new Guid(ba));
                paymentGatewaySettings = _repository.PaymentGatewaySettings
                                         .Include(x => x.Brand)
                                         .Where(ba => paymentGatewaySettingsIds.Contains(ba.Id)).ToList();
            }
            return(paymentGatewaySettings);
        }
Esempio n. 5
0
        private EditPaymentLevel CreatePaymentLevelData()
        {
            var data = new EditPaymentLevel
            {
                Id                   = Guid.NewGuid(),
                Brand                = BrandId,
                Name                 = TestDataGenerator.GetRandomString(6, "0123456789ABCDEF"),
                Code                 = TestDataGenerator.GetRandomString(6, "0123456789ABCDEF"),
                Currency             = "CAD",
                EnableOfflineDeposit = true,
                EnableOnlineDeposit  = true,
                IsDefault            = true
            };

            return(data);
        }
Esempio n. 6
0
        private IQueryable <BankAccount> GetBankAccounts(EditPaymentLevel model)
        {
            var bankAccounts = Enumerable.Empty <BankAccount>().AsQueryable();

            if (model.BankAccounts != null)
            {
                var bankAccountIds = model.BankAccounts.Select(ba => new Guid(ba));
                bankAccounts = _repository.BankAccounts
                               .Include(o => o.Bank.Accounts.Select(t => t.AccountType))
                               .Where(ba => bankAccountIds.Contains(ba.Id));

                if (bankAccounts.Any(ba => ba.CurrencyCode != model.Currency))
                {
                    throw new RegoException("app:payment.levelAccountCurrencyMismatch");
                }
            }

            return(bankAccounts);
        }
Esempio n. 7
0
        public PaymentLevelSaveResult Save(EditPaymentLevel model)
        {
            Brand.Interface.Data.Brand brand = null;

            if (model.Brand.HasValue)
            {
                brand = _brandRepository.Brands.Include(b => b.BrandCurrencies).SingleOrDefault(b => b.Id == model.Brand);
            }

            ValidateCreatePaymentLevelModel(model, brand);

            var currency     = brand.BrandCurrencies.Single(c => c.CurrencyCode == model.Currency);
            var currencyCode = currency.CurrencyCode;

            var bankAccounts = GetBankAccounts(model);

            FillBankReceipts(model, GetBankAccounts(model));

            var paymentGatewaySettings = GetPaymentGatewaySettings(model);

            var now = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);

            var paymentLevel = new PaymentLevel
            {
                Id                   = model.Id ?? Guid.NewGuid(),
                BrandId              = brand.Id,
                CurrencyCode         = currencyCode,
                Status               = PaymentLevelStatus.Active,
                CreatedBy            = _actorInfoProvider.Actor.UserName,
                DateCreated          = now,
                ActivatedBy          = _actorInfoProvider.Actor.UserName,
                DateActivated        = now,
                Code                 = model.Code,
                Name                 = model.Name,
                EnableOfflineDeposit = model.EnableOfflineDeposit,
                EnableOnlineDeposit  = model.EnableOnlineDeposit,
                BankFeeRatio         = model.BankFeeRatio,
                MaxBankFee           = model.MaxBankFee
            };

            _repository.PaymentLevels.Add(paymentLevel);

            if (model.IsDefault)
            {
                _brandCommands.MakePaymentLevelDefault(paymentLevel.Id, paymentLevel.BrandId, currencyCode);
            }

            paymentLevel.BankAccounts = new List <BankAccount>();

            if (bankAccounts != null)
            {
                foreach (var bankAccount in bankAccounts.Where(x => x.Status == BankAccountStatus.Active))
                {
                    paymentLevel.BankAccounts.Add(bankAccount);
                }
            }

            paymentLevel.PaymentGatewaySettings = new List <PaymentGatewaySettings>();
            if (paymentGatewaySettings != null)
            {
                foreach (var settings in paymentGatewaySettings)
                {
                    paymentLevel.PaymentGatewaySettings.Add(settings);
                }
            }

            _repository.SaveChanges();

            _eventBus.Publish(new PaymentLevelAdded(
                                  paymentLevel.Id,
                                  paymentLevel.Code,
                                  paymentLevel.Name,
                                  paymentLevel.BrandId,
                                  paymentLevel.CurrencyCode,
                                  paymentLevel.Status,
                                  paymentLevel.CreatedBy,
                                  paymentLevel.DateCreated)
            {
                EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
            });

            return(new PaymentLevelSaveResult
            {
                Message = "app:payment.levelCreated",
                PaymentLevelId = paymentLevel.Id
            });
        }
Esempio n. 8
0
        public PaymentLevelSaveResult Edit(EditPaymentLevel model)
        {
            var id = model.Id;

            var paymentLevel = _repository.PaymentLevels
                               .Include(l => l.Brand)
                               .Include(l => l.BankAccounts)
                               .SingleOrDefault(l => l.Id == id.Value);

            if (paymentLevel == null)
            {
                throw new RegoException("app:common.invalidId");
            }

            var  currencyCode = paymentLevel.CurrencyCode;
            Guid?brandId      = paymentLevel.BrandId;

            var paymentLevels = _paymentQueries.GetPaymentLevels(brandId.Value);

            if (paymentLevels.Any(pl => pl.Name == model.Name && pl.BrandId == brandId && pl.Id != model.Id))
            {
                throw new RegoException("app:payment.levelNameUnique");
            }

            if (paymentLevels.Any(pl => pl.Code == model.Code && pl.BrandId == brandId && pl.Id != model.Id))
            {
                throw new RegoException("app:payment.levelCodeUnique");
            }

            if (model.IsDefault && paymentLevels.Any(pl => pl.Id != model.Id && pl.BrandId == model.Brand && pl.CurrencyCode == model.Currency && pl.IsDefault))
            {
                throw new RegoException("Default payment level for the brand and currency combination already exists.");
            }

            var bankAccounts = GetBankAccounts(model);

            FillBankReceipts(model, GetBankAccounts(model));

            var paymentGatewaySettings = GetPaymentGatewaySettings(model);

            var now = DateTimeOffset.Now.ToBrandOffset(paymentLevel.Brand.TimezoneId);

            paymentLevel.UpdatedBy   = _actorInfoProvider.Actor.UserName;
            paymentLevel.DateUpdated = now;

            paymentLevel.Code = model.Code;
            paymentLevel.Name = model.Name;
            paymentLevel.EnableOfflineDeposit = model.EnableOfflineDeposit;
            paymentLevel.EnableOnlineDeposit  = model.EnableOnlineDeposit;
            paymentLevel.BankFeeRatio         = model.BankFeeRatio;
            paymentLevel.MaxBankFee           = model.MaxBankFee;

            paymentLevel.CurrencyCode = currencyCode;
            paymentLevel.Id           = (Guid)id;
            paymentLevel.BrandId      = (Guid)brandId;

            if (model.IsDefault)
            {
                _brandCommands.MakePaymentLevelDefault(paymentLevel.Id, paymentLevel.BrandId, currencyCode);
            }

            paymentLevel.BankAccounts = new List <BankAccount>();
            if (bankAccounts != null)
            {
                foreach (var bankAccount in bankAccounts.Where(x => x.Status == BankAccountStatus.Active))
                {
                    paymentLevel.BankAccounts.Add(bankAccount);
                }
            }
            paymentLevel.PaymentGatewaySettings.Clear();
            if (paymentGatewaySettings != null)
            {
                foreach (var settings in paymentGatewaySettings)//filter status?
                {
                    paymentLevel.PaymentGatewaySettings.Add(settings);
                }
            }

            _repository.SaveChanges();
            _eventBus.Publish(new PaymentLevelEdited(
                                  paymentLevel.Id,
                                  paymentLevel.Code,
                                  paymentLevel.Name,
                                  paymentLevel.BrandId,
                                  paymentLevel.CurrencyCode,
                                  paymentLevel.Status,
                                  paymentLevel.CreatedBy,
                                  paymentLevel.DateCreated
                                  )
            {
                EventCreated = DateTimeOffset.Now.ToBrandOffset(paymentLevel.Brand.TimezoneId),
            });

            return(new PaymentLevelSaveResult
            {
                Message = "app:payment.levelUpdated",
                PaymentLevelId = paymentLevel.Id
            });
        }