private CreditCard GenerateCredtiCard(AmexCardInfo card) { var account = new CreditCardBankAccount { Id = GenerateBankAccountId(card), BankName = card.BankName, BankCode = card.BankId, BankBranchNumber = card.BankBranchId, AccountNumber = card.BankAccountId }; var splitName = card.UserName.Split(' '); var result = new CreditCard { Id = GenerateCardId(card), CardName = card.CardName, LastDigits = card.CardNumber, HolderId = card.HolderId, OwnerFirstName = splitName[1], OwnerLastName = splitName[0], TypeDescription = card.Club1, CardAccount = account }; return(result); }
private void EnrichTransactionsByDetails(AmexCardInfo card, CreditCardDebitPeriod debit, List <AmexCardTransaction> transactions) { var tasks = CreateDetailsEnrichmentTasks(card.CardIndex, debit, transactions); foreach (var task in tasks) { task.Start(); } Task.WaitAll(tasks.ToArray()); }
private static CreditCardDebitPeriod GenerateDebitPeriod(AmexCardInfo card, CardChargeResponse bankCharge) { return(new CreditCardDebitPeriod { CardId = GenerateCardId(card), CardLastDigits = bankCharge.CardNumber, Date = AutoMapper.Mapper.Map <DateTime>(bankCharge.BillingDate), Amount = bankCharge.BillingSumSekel, Transactions = new List <CreditCardTransaction>() }); }
private IEnumerable <CreditCardDebitPeriod> GenerateDebitPeriods(AmexCardInfo card, IEnumerable <CardChargeResponse> bankCharges) { var result = new List <CreditCardDebitPeriod>(); foreach (var bankCharge in bankCharges) { result.Add(GenerateDebitPeriod(card, bankCharge)); } return(result); }
private List <CreditCardDebitPeriod> GenerateBasicDebits(AmexCardInfo card, DateTime startDate, DateTime endDate) { var result = new List <CreditCardDebitPeriod>(); for (DateTime date = startDate; date < endDate.AddMonths(1); date = date.AddMonths(1)) { var bankCharges = _api.GetBankDebit(card.BankAccountId, card.CardNumber, date.Year, date.Month); var bankDebits = GenerateDebitPeriods(card, bankCharges); result.AddRange(bankDebits); } return(result); }
private static CreditCardDebitPeriod GenerateDebitPeriodForTransaction(AmexCardInfo card, CreditCardDebitPeriod debit, AmexCardTransaction transaction) { return(new CreditCardDebitPeriod { CardId = GenerateCardId(card), CardLastDigits = card.CardNumber, Date = debit.Date, Amount = String.IsNullOrEmpty(transaction.DealSumOutbound) ? Convert.ToDecimal(transaction.PaymentSum) : Convert.ToDecimal(transaction.DealSumOutbound), Transactions = new List <CreditCardTransaction>() }); }
private List <CreditCardDebitPeriod> GenerateDebitsWithTransactions(AmexCardInfo card, List <CreditCardDebitPeriod> debits, bool includeDeatils) { var result = new List <CreditCardDebitPeriod>(); foreach (var debit in debits) { var transactions = _api.GetTransactions(card.CardIndex, debit.Date.Year, debit.Date.Month).ToList(); var transactionalDebits = FetchInternalDebits(card, debit, transactions, includeDeatils); debit.Transactions = GenerateCardTransactions(transactions, debit.Date); if (includeDeatils) { EnrichTransactionsByDetails(card, debit, transactions); } result.AddRange(transactionalDebits); } result.AddRange(debits); return(result); }
private static string GenerateCardId(AmexCardInfo card) { return($"{card.HolderId}-{card.CardNumber}"); }
private static string GenerateBankAccountId(AmexCardInfo card) { return($"{card.BankId}-{card.BankBranchId}-{card.BankAccountId}"); }
private List <CreditCardDebitPeriod> FetchInternalDebits(AmexCardInfo card, CreditCardDebitPeriod debit, IList <AmexCardTransaction> transactions, bool includeDeatils) { var result = new List <CreditCardDebitPeriod>(); for (int i = 0; i < transactions.Count; i++) { var trs = transactions[i]; if (!String.IsNullOrEmpty(trs.DealsInbound) && trs.VoucherNumber == null) { if (trs.DealSumType == "P" && trs.MoreInfo == "חיוב במועד הבא") { transactions.RemoveAt(i); transactions.RemoveAt(i - 1); i -= 2; } else if (trs.DealSumType == "T" && trs.DealsInbound == "NO") { transactions.RemoveAt(i); i--; } else if (trs.DealSumType == "T" && trs.DealsInbound == "yes") { var newDebit = GenerateDebitPeriodForTransaction(card, debit, transactions[i - 1]); var debitTrs = GenerateCardTransaction(transactions[i - 1], newDebit.Date); newDebit.Transactions.Add(debitTrs); result.Add(newDebit); if (includeDeatils) { EnrichTransactionsByDetails(card, newDebit, transactions.ToList()); } transactions.RemoveAt(i); transactions.RemoveAt(i - 1); i -= 2; } else if (trs.DealSumType == "1") { transactions.RemoveAt(i); i--; } } else if (String.IsNullOrEmpty(trs.DealsInbound)) { if (trs.DealSumOutbound == null && !trs.FullSupplierNameOutbound.Equals("CASH ADVANCE FEE")) { transactions.RemoveAt(i); i--; } else if (Convert.ToDecimal(trs.DealSumOutbound) < 0) { var newDebit = GenerateDebitPeriodForTransaction(card, debit, trs); var debitTrs = GenerateCardTransaction(trs, newDebit.Date); newDebit.Transactions.Add(debitTrs); result.Add(newDebit); if (includeDeatils) { EnrichTransactionsByDetails(card, newDebit, transactions.ToList()); } transactions.RemoveAt(i); i--; } } } return(result); }