// TODO: add functionality based on user settings // TODO: add multiple ways to distribute funds public static bool PeriodPay(User user) { var subscriptionInfo = UserSubscriptionInfoRepository.FindOrCreate(user); var paydayTime = subscriptionInfo.last_paid.AddMonths(1); if (DateTime.Now < paydayTime) { return(false); } var currency = subscriptionInfo.selected_currency; var balance = UserBalanceRepository.FindOrCreate(user, currency); decimal amount = 0; amount = balance.balance < subscriptionInfo.selected_amount ? balance.balance : subscriptionInfo.selected_amount; var randomProjectsToFund = 4; // TODO: get from user settings var amountToFundRandomProjects = amount / randomProjectsToFund; for (int i = 1; i <= randomProjectsToFund; i++) { var randomProject = ProjectRepository.FindRandom(); SubscriptionFundingUtils.FundEntity( user, randomProject.id, EntityType.Project, amountToFundRandomProjects, currency ); } return(true); }
public void FundEntity_DataCorrect_EntityFundedTxCreated() { var user = UserFaker.Create(); var project = ProjectFaker.Create(); var amount = Rand.SmallDecimal(); var balance = SubscriptionFundingUtils.FundEntity(user, project.id, EntityType.Project, amount, CurrencyType.BitCoin); Assert.AreEqual(amount, balance.balance); var txs = FundingTransactionRepository.Get(project.id, EntityType.Project, CurrencyType.BitCoin); Assert.AreEqual(1, txs.Length); Assert.AreEqual(amount, txs[0].amount); }