public void Create_DataCorrect_BalanceAndTransactionCreated() { var invoice = InvoiceFaker.Create(); var balance = FundingBalanceRepository.Create( invoice.entity_id, invoice.entity_type, invoice.currency_type ); FundingBalanceRepository.AddFunds(balance, invoice); Assert.NotNull(balance); var txs = FundingTransactionRepository.Get(invoice.entity_id, invoice.entity_type, invoice.currency_type); Assert.AreEqual(1, txs.Length); var transaction = txs[0]; balance = balance.Refresh(); Assert.AreEqual(invoice.amount, balance.balance); Assert.AreEqual(balance.entity_id, transaction.entity_id); Assert.AreEqual(balance.entity_type, transaction.entity_type); Assert.AreEqual(balance.currency_type, transaction.currency_type); }
public static FundingBalance FundEntity( User from, int entityId, EntityType entityType, decimal amount, CurrencyType currencyType ) { var balance = FundingBalanceRepository.FindOrCreate(entityId, entityType, currencyType); balance = FundingBalanceRepository.AddFunds(from, balance, amount); return(balance.Refresh()); }
public static FundingBalance Create( int entityId = 0, EntityType entityType = EntityType.Project, CurrencyType currencyType = CurrencyType.Ethereum, decimal balance = 0.1M ) { var newBalance = FundingBalanceRepository.Create( entityId == 0 ? Rand.Int() : entityId, entityType, currencyType ); newBalance.UpdateBalance(balance); return(newBalance.Refresh()); }
// TODO: add auth for getting user balance? public FundingBalanceController() { Get("/api/v1/entity/funding/balances/get", _ => { var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { new ShouldHaveParameters(new[] { "entity_guid", "entity_type" }), new ShouldBeCorrectEnumValue("entity_type", typeof(EntityType)), new EntityShouldExist(), }, true); if (errors.Count > 0) { return(HttpResponse.Errors(errors)); } var entityType = (EntityType)GetRequestEnum("entity_type", typeof(EntityType)); var entityId = EntityUtils.GetEntityId(GetRequestStr("entity_guid"), entityType); var balances = FundingBalanceRepository.Get(entityId, entityType); return(HttpResponse.Item("balances", new FundingBalanceTransformer().Many(balances))); }); }
public void AddFunds_DataCorrect_AddFunds() { var user = UserFaker.Create(); var invoice = InvoiceFaker.Create(user); var balance = FundingBalanceRepository.Create( invoice.entity_id, invoice.entity_type, invoice.currency_type ); FundingBalanceRepository.AddFunds(balance, invoice); Assert.NotNull(balance); balance = balance.Refresh(); Assert.AreEqual(invoice.amount, balance.balance); var newInvoice = InvoiceFaker.Create(user, invoice.entity_id); balance = FundingBalanceRepository.AddFunds(balance, newInvoice).Refresh(); Assert.AreEqual(invoice.amount + newInvoice.amount, balance.balance); }
// TODO: add functionality for user balances public static FundingBalance FundEntity(Invoice invoice) { if (invoice.status != InvoiceStatus.Confirmed) { return(null); } var balance = FundingBalanceRepository.Find(invoice.entity_id, invoice.entity_type, invoice.currency_type); balance = balance ?? FundingBalanceRepository.Create( invoice.entity_id, invoice.entity_type, invoice.currency_type ); if (invoice.entity_type == EntityType.UserBalance) { } else { balance = FundingBalanceRepository.AddFunds(balance, invoice); } return(balance.Refresh()); }