public void Can_Insert_New_CardAccount() { var user = Context.Set<User>().FirstOrDefault(x => x.UserName == "terminator"); var vendor = Context.Set<CardVendor>().Find("visa"); var currency = Context.Set<Currency>().Find("USD"); var card = new Card("1232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard = new UserCard(card, user, new CardSettings(card.Id, new CardLimits())); Context.Set<UserCard>().Add(userCard); var account = new CardAccount("1234567890123", currency, user) {ExpirationDateUtc = DateTime.UtcNow.AddDays(300)}; Context.Set<CardAccount>().Add(account); Context.SaveChanges(); }
public CardPayment Create(UserCard card, PaymentTemplate template, JObject form) { Argument.NotNull(template, "template"); Argument.NotNull(form, "form"); Argument.NotNull(card, "card"); var paymentProfile = _paymentProfiles.Find(card.Owner.Id); if (paymentProfile == null) { var message = string.Format("Payment profile for user [{0}] was not found.", card.Owner.Id); throw new InvalidOperationException(message); } var paymentForm = _paymentFormFactory.Create(paymentProfile, card.Account, template); paymentForm.MergeWith(form); var paymentOrder = template.OrderTemplate.CreateOrder(paymentForm); var to = paymentOrder.BeneficiaryBankCode == _settings.VaBankCode ? _accounts.Find(paymentOrder.BeneficiaryAccountNo) : _correspondentAccounts.QueryOne(DbQuery.For<CorrespondentAccount>().FilterBy(x => x.Bank.Code == paymentOrder.BeneficiaryBankCode)); if (to == null) { var message = string.Format("Destination account could not be found. Bank code: {0}. Account No: {1}.", paymentOrder.BeneficiaryBankCode, paymentOrder.BeneficiaryAccountNo); throw new InvalidOperationException(message); } var currency = _currencies.Find(paymentOrder.CurrencyISOName); if (currency == null) { var message = string.Format("Currency with code {0} was not found.", paymentOrder.CurrencyISOName); throw new InvalidOperationException(message); } var payment = new CardPayment(card, template, paymentOrder, form, card.Account, to, currency); template.FillInfo(payment, paymentForm); var transactionName = _transactionReferenceBook.ForPayment(template); payment.Withdrawal = card.Account.Withdraw( card, transactionName.Code, transactionName.Description, _settings.Location, payment.MoneyAmount, _moneyConverter); return payment; }
public void Can_Insert_MultipleCards_With_Account() { var user = Context.Set<User>().FirstOrDefault(x => x.UserName == "terminator"); var vendor = Context.Set<CardVendor>().Find("visa"); var currency = Context.Set<Currency>().Find("USD"); var card1 = new Card("2232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard1 = new UserCard(card1, user, new CardSettings(card1.Id, new CardLimits())); var card2 = new Card("3232123413241234", vendor, "TEST", "TEST", DateTime.Today.AddDays(300)); var userCard2 = new UserCard(card2, user, new CardSettings(card2.Id, new CardLimits())); Context.Set<UserCard>().Add(userCard1); Context.Set<UserCard>().Add(userCard2); var account1 = new CardAccount("1234567891234", currency, user) { ExpirationDateUtc = DateTime.UtcNow.AddDays(300) }; account1.Cards.Add(userCard2); Context.Set<CardAccount>().Add(account1); Context.SaveChanges(); }
public UserCard Create( CardAccount cardAccount, CardVendor cardVendor, User cardOwner, string cardholderFirstName, string cardholderLastName, DateTime expirationDateUtc) { Argument.NotNull(cardAccount, "cardAccount"); Argument.NotNull(cardVendor, "cardVendor"); Argument.NotNull(cardOwner, "cardOwner"); var card = _cardFactory.Create( cardVendor, cardholderFirstName, cardholderLastName, expirationDateUtc); var settings = new CardSettings(card.Id, _cardLimitsFactory.CreateDefault(cardAccount.Currency)); var userCard = new UserCard(cardAccount, card, cardOwner, settings); return userCard; }