Exemplo n.º 1
0
        public static void AddAlibabaDefaultBankAccount(this Customer customer, ISortCodeChecker sortCodeChecker = null)
        {
            const string          bankAccount = "00000000";
            const string          sortCode    = "000000";
            const BankAccountType accountType = BankAccountType.Personal;

            if (customer == null)
            {
                ms_oLog.Debug("Customer not specified for adding an Alibaba default bank account (#{0}, code {1}, type {2}).",
                              bankAccount,
                              sortCode,
                              accountType
                              );

                return;
            }             // if

            if (customer.IsAlibaba)
            {
                customer.AddBankAccount("00000000", "000000", BankAccountType.Personal);
                return;
            }             // if

            ms_oLog.Debug(
                "Not adding an Alibaba default bank account (#{1}, code {2}, type {3}) to customer {0} because this is not an Alibaba customer.",
                customer.Stringify(),
                bankAccount,
                sortCode,
                accountType
                );
        }         // AddAlibabaDefaultBankAccount
Exemplo n.º 2
0
        public PaymentAccountsController(
            CustomerRepository customersRepository,
            ICustomerMarketPlaceRepository customerMarketplacesReporsitory,
            IWorkplaceContext context,
            ISortCodeChecker sortCodeChecker,
            BankAccountUniqChecker bankAccountUniqChecker)
        {
            this.customersRepository             = customersRepository;
            this.serviceClient                   = new ServiceClient();
            this.customerMarketplacesReporsitory = customerMarketplacesReporsitory;

            this.context                = context;
            this.sortCodeChecker        = sortCodeChecker;
            this.bankAccountUniqChecker = bankAccountUniqChecker;
        }
 public PaymentAccountsController(
     DatabaseDataHelper dbHelper,
     CustomerRepository customersRepository,
     IEzbobWorkplaceContext context,
     IMPUniqChecker mpChecker,
     IYodleeAccountChecker yodleeAccountChecker,
     BankAccountUniqChecker bankAccountUniqChecker,
     ISortCodeChecker sortCodeChecker)
 {
     this.dbHelper               = dbHelper;
     this.customersRepository    = customersRepository;
     this.context                = context;
     this.serviceClient          = new ServiceClient();
     this.mpChecker              = mpChecker;
     this.yodleeAccountChecker   = yodleeAccountChecker;
     this.bankAccountUniqChecker = bankAccountUniqChecker;
     this.sortCodeChecker        = sortCodeChecker;
 }
Exemplo n.º 4
0
        }         // AddAlibabaDefaultBankAccount

        public static int AddBankAccount(this Customer customer, string bankAccount, string sortCode, BankAccountType accountType, BankAccountUniqChecker bankAccountUniqChecker = null, ISortCodeChecker sortCodeChecker = null)
        {
            if (customer == null)               // can happen for Alibaba call only
            {
                ms_oLog.Debug("Customer not specified for adding an account (#{0}, code {1}, type {2}).",
                              bankAccount,
                              sortCode,
                              accountType
                              );

                return(-1);
            }             // if

            if (customer.BankAccounts.Any(a => a.BankAccount == bankAccount && a.SortCode == sortCode))
            {
                ms_oLog.Debug(
                    "Bank account (#{1}, code {2}, type {3}) already exists at customer {0}.",
                    customer.Stringify(),
                    bankAccount,
                    sortCode,
                    accountType
                    );

                return(-2);
            }             // if

            if (sortCodeChecker == null)
            {
                sortCodeChecker = ObjectFactory.GetInstance <ISortCodeChecker>();
            }             // if

            var card = new CardInfo {
                BankAccount = bankAccount,
                SortCode    = sortCode,
                Customer    = customer,
                Type        = accountType,
            };

            try {
                sortCodeChecker.Check(card);
            }
            catch (Exception e) {
                ms_oLog.Debug(
                    e,
                    "Just FYI: exception caught while checking a sort code for new bank account (#{1}, code {2}, type {3}) of customer {0}.",
                    customer.Stringify(),
                    bankAccount,
                    sortCode,
                    accountType
                    );
            }             // try

            ms_oLog.Debug(
                "Adding a new bank account (#{1}, code {2}, type {3}) to customer {0}.",
                customer.Stringify(),
                bankAccount,
                sortCode,
                accountType
                );

            customer.BankAccounts.Add(card);

            if (bankAccountUniqChecker != null)
            {
                try {
                    bankAccountUniqChecker.Check(customer.Id, card);
                } catch (BankAccountIsAlreadyAddedException) {
                    ms_oLog.Debug(
                        "Account already was added by another customer {0} bank: {1} {2} {3}",
                        customer.Id,
                        bankAccount,
                        sortCode,
                        accountType
                        );
                    customer.BlockTakingLoan = true;
                }
            }

            ms_oLog.Debug(
                "Setting a new bank account (#{1}, code {2}, type {3}) as a default one for customer {0}.",
                customer.Stringify(),
                bankAccount,
                sortCode,
                accountType
                );

            customer.SetDefaultCard(card);

            ms_oLog.Debug(
                "Saving to DB a new bank account (#{1}, code {2}, type {3}) for customer {0}.",
                customer.Stringify(),
                bankAccount,
                sortCode,
                accountType
                );

            ObjectFactory.GetInstance <CustomerRepository>().SaveOrUpdate(customer);

            ms_oLog.Debug(
                "A new bank account (#{1}, code {2}, type {3}) has been added to customer {0}. Account id: {4}",
                customer.Stringify(),
                bankAccount,
                sortCode,
                accountType,
                card.Id
                );

            return(card.Id);
        }         // AddBankAccount
Exemplo n.º 5
0
        }         // Name

        public override void Execute()
        {
            Broker broker = null;

            try {
                if (string.IsNullOrEmpty(this.model.AccountNumber) || !Regex.IsMatch(this.model.AccountNumber, @"^\d{8}$"))
                {
                    throw new StrategyWarning(this, "Invalid account number");
                }

                if (string.IsNullOrEmpty(this.model.SortCode) || !Regex.IsMatch(this.model.SortCode, @"^\d{6}$"))
                {
                    throw new StrategyWarning(this, "Invalid sort code");
                }

                ISortCodeChecker sortCodeChecker = CurrentValues.Instance.PostcodeAnywhereEnabled
                                        ? (ISortCodeChecker) new SortCodeChecker(CurrentValues.Instance.PostcodeAnywhereMaxBankAccountValidationAttempts)
                                        : (ISortCodeChecker) new FakeSortCodeChecker(CurrentValues.Instance.PostcodeAnywhereMaxBankAccountValidationAttempts);

                var sp = new FindBrokerID(this.model, DB, Log);
                sp.ExecuteNonQuery();

                if (sp.BrokerID <= 0)
                {
                    Log.Alert("BrokerAddBank broker id not found by email {0}", this.model.BrokerEmail);
                    throw new StrategyWarning(this, "Failed adding bank account");
                }                 // if

                var brokerRepository = ObjectFactory.GetInstance <BrokerRepository>();
                broker = brokerRepository.GetByID(sp.BrokerID);

                if (broker == null)
                {
                    Log.Alert("BrokerAddBank broker not found by id {0}", sp.BrokerID);
                    throw new StrategyWarning(this, "Failed adding bank account");
                }                 // if

                var cardInfo = new CardInfo {
                    BankAccount = this.model.AccountNumber,
                    SortCode    = this.model.SortCode,
                    Type        = (BankAccountType)Enum.Parse(typeof(BankAccountType), this.model.BankAccountType),
                    Broker      = broker,
                    IsDefault   = true
                };

                sortCodeChecker.Check(cardInfo);

                foreach (CardInfo bankAccount in broker.BankAccounts)
                {
                    bankAccount.IsDefault = false;
                }

                broker.BankAccounts.Add(cardInfo);

                var loanCommissionsWithoutCard = broker.LoanBrokerCommissions.Where(x =>
                                                                                    x.CardInfo == null && x.PaidDate == null && x.Status != "Done"
                                                                                    );

                foreach (var commission in loanCommissionsWithoutCard)
                {
                    commission.CardInfo = cardInfo;
                }

                brokerRepository.SaveOrUpdate(broker);
            } catch (SortCodeNotFoundException) {
                throw new StrategyWarning(this, "Sort code was not found");
            } catch (UnknownSortCodeException) {
                throw new StrategyWarning(this, "Sort code was not found");
            } catch (InvalidAccountNumberException) {
                throw new StrategyWarning(this, "Account number is not valid");
            } catch (NotValidSortCodeException) {
                throw new StrategyWarning(this, "Sort code is not valid");
            } catch (Exception ex) {
                Log.Error(ex, "BrokerAddBank failed " + this.model.BrokerEmail + " id: " + (broker == null ? 0 : broker.ID));
                throw new StrategyWarning(this, "Failed adding bank account");
            }     // try
        }         // Execute