Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added credit utilization for credit cards (isracard-amex for now) #795

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/scrapers/base-isracard-amex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ interface ScrapedTransaction {
paymentSumOutbound: number;
}


interface ScrapedAccount {
index: number;
accountNumber: string;
processedDate: string;
}

interface AccountCredit {
creditUtilization: number;
creditTotal: number;
}

interface ScrapedLoginValidation {
Header: {
Status: string;
Expand Down Expand Up @@ -98,6 +102,28 @@ interface ScrapedTransactionData {
}>;
}

function getCreditUtilizationUrl(servicesUrl: string) {
return buildUrl(servicesUrl, {
queryParams: {
reqName: 'RikuzNetuneyCreditDigi',
},
});
}

async function fetchCreditUtilization(page: Page, servicesUrl: string): Promise<_.Dictionary<AccountCredit>> {
const dataUrl = getCreditUtilizationUrl(servicesUrl);
const dataResult = await fetchGetWithinPage<ScrapedAccountsWithinPageResponse>(page, dataUrl);
return _.fromPairs(
dataResult.RikuzNetuneyCreditDigiBean.cardsTotal.map((item) => [
item.cardNumberTail,
{
creditUtilization: parseFloat(item.nitzulLoCredit),
creditTotal: parseFloat(item.misgeretKolelet.replace(/,/g, '')),
},
])
);
}

function getAccountsUrl(servicesUrl: string, monthMoment: Moment) {
const billingDate = monthMoment.format('YYYY-MM-DD');
return buildUrl(servicesUrl, {
Expand Down Expand Up @@ -284,6 +310,7 @@ function getExtraScrap(accountsWithIndex: ScrapedAccountsWithIndex[], page: Page
async function fetchAllTransactions(page: Page, options: ExtendedScraperOptions, startMoment: Moment) {
const futureMonthsToScrape = options.futureMonthsToScrape ?? 1;
const allMonths = getAllMonthMoments(startMoment, futureMonthsToScrape);
const creditUtilization = await fetchCreditUtilization(page, options.servicesUrl);
const results: ScrapedAccountsWithIndex[] = await Promise.all(allMonths.map(async (monthMoment) => {
return fetchTransactions(page, options, startMoment, monthMoment);
}));
Expand All @@ -308,6 +335,8 @@ async function fetchAllTransactions(page: Page, options: ExtendedScraperOptions,
const accounts = Object.keys(combinedTxns).map((accountNumber) => {
return {
accountNumber,
creditUtilization: creditUtilization[accountNumber].creditUtilization,
creditTotal: creditUtilization[accountNumber].creditTotal,
txns: combinedTxns[accountNumber],
};
});
Expand Down
2 changes: 2 additions & 0 deletions src/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

export interface TransactionsAccount {
accountNumber: string;
creditUtilization?: number;
creditTotal?: number;
balance?: number;
txns: Transaction[];
}
Expand Down