Skip to content

Commit

Permalink
feat: add charged currency support for max (#806)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov authored Dec 17, 2023
1 parent 9cbceaa commit 25a4fb1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/scrapers/max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { fixInstallments, sortTransactionsByDate, filterOldTransactions } from '
import { Transaction, TransactionStatuses, TransactionTypes } from '../transactions';
import { getDebug } from '../helpers/debug';
import { ScraperOptions } from './interface';
import { SHEKEL_CURRENCY, DOLLAR_CURRENCY, EURO_CURRENCY } from '../constants';

const debug = getDebug('max');

Expand All @@ -18,6 +19,7 @@ interface ScrapedTransaction {
paymentDate?: string;
purchaseDate: string;
actualPaymentAmount: string;
paymentCurrency: number | null;
originalCurrency: string;
originalAmount: number;
planName: string;
Expand Down Expand Up @@ -149,6 +151,20 @@ function getInstallmentsInfo(comments: string) {
total: parseInt(matches[1], 10),
};
}

function getChargedCurrency(currencyId: number | null) {
switch (currencyId) {
case 376:
return SHEKEL_CURRENCY;
case 840:
return DOLLAR_CURRENCY;
case 978:
return EURO_CURRENCY;
default:
return undefined;
}
}

function mapTransaction(rawTransaction: ScrapedTransaction): Transaction {
const isPending = rawTransaction.paymentDate === null;
const processedDate = moment(isPending ?
Expand All @@ -168,6 +184,7 @@ function mapTransaction(rawTransaction: ScrapedTransaction): Transaction {
originalAmount: -rawTransaction.originalAmount,
originalCurrency: rawTransaction.originalCurrency,
chargedAmount: -rawTransaction.actualPaymentAmount,
chargedCurrency: getChargedCurrency(rawTransaction.paymentCurrency),
description: rawTransaction.merchantName.trim(),
memo: rawTransaction.comments,
category: categories.get(rawTransaction?.categoryId),
Expand Down

0 comments on commit 25a4fb1

Please sign in to comment.