eshaham / israeli-bank-scrapers

Provide scrapers for all major Israeli banks and credit card companies
MIT License
563 stars 152 forks source link

Add a charged currency property to transactions #80

Closed eshaham closed 3 years ago

eshaham commented 6 years ago

In some cases when users have a foreign currency account in their banks, transactions in that foreign currency get charged directly against the foreign currency bank account, and conversion to ILS is not needed.

Currently this module always assumes chargedAmount is returned in ILS. We should introduce a new chargedCurrency property to transactions that will hold the actual currency used.

asfktz commented 6 years ago

I would like to handle that for Isracard and Bank Hapoalim.

One challenge I have it that I'm not sure I've seen a case where a transaction in foreign currency is converted to ILS.

In my Isracard account, I see that some of my transactions are converted to ILS, but the "Original Currency" column is also ILS:

(Isracard) image

Note: My credit card is set to transfer money from my מט"ח account for foreign currency

Do you have an example of such case?

eshaham commented 6 years ago

@asfktz actually, I don't spend in foreign currency in my isracard account, but I believe that @erezd ran into it when he was setting up the scraper for amex, so perhaps he could provide an example / screenshot.

as for bank hapoalim, I'm not sure we need to implement this feature for checking accounts. if I'm not mistaken, an amount in a foreign currency cannot be transferred to an ILS checking account, but you actually need to either convert it first, or setup an additional checking account in that foreign currency. but I could be wrong.

esakal commented 5 years ago

Hi @asfktz, following eshaham/israeli-ynab-updater#22 you mentioned that the transaction contain the following information:

{
  "currencyId": "USD",
  "currentPaymentCurrency": "USD",
}

can't we use those fields to figure original and charged currency?

Regarding the banks I think we can scrape also the foreign accounts, I can add the Leumi account if needed

esakal commented 5 years ago

@asfktz I would like to promote the support for charged currency. Please take a look at #155, I added new field to leumi-card named chargedCurrency in charged-currency branch. If you can add their support for Isracard it would be great.

asfktz commented 5 years ago

Better late than never. I'm working on the chargedCurrency field for Isracard.

First here are examples of the two transaction types

Transaction Examples

1. A transaction that is charged in foreign currency:

(It charges my foreign currency account directly)

image

{
    "specificDate": null,
    "cardIndex": "0",
    "dealsInbound": null,
    "supplierId": null,
    "supplierName": null,
    "dealSumType": null,
    "paymentSumSign": null,
    "purchaseDate": null,
    "fullPurchaseDate": null,
    "moreInfo": null,
    "horaatKeva": null,
    "voucherNumber": "0069338",
    "voucherNumberRatz": null,
    "solek": null,
    "purchaseDateOutbound": "13/05",
    "fullPurchaseDateOutbound": "13/05/2019",
    "currencyId": "USD",
    "currentPaymentCurrency": "USD",
    "city": "1650485163",
    "supplierNameOutbound": "NOTION SO",
    "fullSupplierNameOutbound": "NOTION SO",
    "paymentDate": "15/05",
    "fullPaymentDate": "15/05/2019",
    "isShowDealsOutbound": "_",
    "adendum": null,
    "voucherNumberRatzOutbound": "804475868",
    "isShowLinkForSupplierDetails": null,
    "dealSum": null,
    "paymentSum": null,
    "fullSupplierNameHeb": null,
    "dealSumOutbound": "5.00",
    "paymentSumOutbound": "5.00",
    "isHoraatKeva": "false",
    "stage": null,
    "returnCode": null,
    "message": null,
    "returnMessage": null,
    "displayProperties": null,
    "tablePageNum": "0",
    "isError": "false",
    "isCaptcha": "false",
    "isButton": "false",
    "siteName": null,
    "clientIpAddress": null
  }

2. A transaction that is convert to ILS:

image

{
    "specificDate": null,
    "cardIndex": "0",
    "dealsInbound": null,
    "supplierId": null,
    "supplierName": null,
    "dealSumType": null,
    "paymentSumSign": null,
    "purchaseDate": null,
    "fullPurchaseDate": null,
    "moreInfo": null,
    "horaatKeva": null,
    "voucherNumber": "0012655",
    "voucherNumberRatz": null,
    "solek": null,
    "purchaseDateOutbound": "14/06",
    "fullPurchaseDateOutbound": "14/06/2019",
    "currencyId": "NIS",
    "currentPaymentCurrency": "NIS",
    "city": "G.CO/HELPP",
    "supplierNameOutbound": "GOOGLE  BLINKIS",
    "fullSupplierNameOutbound": "GOOGLE  BLINKIST",
    "paymentDate": "16/06",
    "fullPaymentDate": "16/06/2019",
    "isShowDealsOutbound": "_",
    "adendum": null,
    "voucherNumberRatzOutbound": "917339015",
    "isShowLinkForSupplierDetails": null,
    "dealSum": null,
    "paymentSum": null,
    "fullSupplierNameHeb": null,
    "dealSumOutbound": "79.90",
    "paymentSumOutbound": "79.90",
    "isHoraatKeva": "false",
    "stage": null,
    "returnCode": null,
    "message": null,
    "returnMessage": null,
    "displayProperties": null,
    "tablePageNum": "0",
    "isError": "false",
    "isCaptcha": "false",
    "isButton": "false",
    "siteName": null,
    "clientIpAddress": null
  }

The Problem

Take a look at the converted transaction (example 2), In the GUI, you can see that the original amount is $22 and it is converted to 72.90 ILS.

Now, getting the chargedCurrency is easy, we can use currencyId or currentPaymentCurrency.

But, we use currencyId for the originalCurrency already:

https://github.com/eshaham/israeli-bank-scrapers/blob/560e0cdceb7a1751fa80231319784affd59cc2fb/src/scrapers/base-isracard-amex.js#L110-L111

So, we need to find a way to get the real originalCurrency and originalAmount.

The problem is that while we can see it in the GUI, the API response does not return anything that can be used as originalCurrency and originalAmount (maybe it rendered server side?)

Any ideas? @eshaham @esakal

eshaham commented 5 years ago

@asfktz It's weird that they specify ILS for the original amount, although the transaction was originally USD. I would probably stick with the currency of what they claim to be the original amount, because, as can be seen in your first example, it can be in other currencies.

asfktz commented 5 years ago

OK, so I added chargedCurrency, and for Isracard, its always the same as originalCurrency

https://github.com/eshaham/israeli-bank-scrapers/blob/9484be69d0009297a5b5215357eaca304a6b7fe1/src/scrapers/base-isracard-amex.js#L110-L113

I feel a bit awkward knowing that the originalCurrency & originalAmount is wrong. We know that know, but I don't think it will be clear for anyone else.

I wish there was a way to at least tell that this transaction's currency is converted

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sagiba commented 4 years ago

Has there been any consensus regarding this issue?

I just ran into it, with a card that had GBP transactions that were charged in USD. For example:

    "currencyId": "USD",
    "currentPaymentCurrency": "GBP",
    "dealSumOutbound": "5.60",
    "fullSupplierNameOutbound": "TFL TRAVEL CH",
    "paymentSumOutbound": "7.59",
}

The result of this with the current isracard scraper is: originalAmount = -5.6, chargedAmount = -7.59, originalCurrency = USD

This is wrong, because the original currency is GBP and not USD.

sagiba commented 4 years ago

@esakal can you please re-open this issue?

esakal commented 4 years ago

@sagiba I re-opened this one but reading the thread I'm a bit confuse about what can/should be done here.

sagiba commented 4 years ago

@esakal, we need to change originalCurrency to map to currentPaymentCurrency instead of currencyId, and add another field, chargeCurrency, that maps to currencyId.

I can take care of this after we agree on #418, because I first want to add some test coverage on the conversion logic here.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.