Skip to content

Commit

Permalink
Add AMERICAN_EXPRESS_AESUDEF1 bank integration
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
  • Loading branch information
kyrias committed Aug 8, 2023
1 parent 33453a5 commit 3dca17e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import AmericanExpressAesudef1 from './banks/american-express-aesudef1.js';
import IngPlIngbplpw from './banks/ing-pl-ingbplpw.js';
import IntegrationBank from './banks/integration-bank.js';
import MbankRetailBrexplpw from './banks/mbank-retail-brexplpw.js';
import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';

const banks = [MbankRetailBrexplpw, SandboxfinanceSfin0000, IngPlIngbplpw];
const banks = [
AmericanExpressAesudef1,
IngPlIngbplpw,
MbankRetailBrexplpw,
SandboxfinanceSfin0000,
];

export default (institutionId) =>
banks.find((b) => b.institutionIds.includes(institutionId)) ||
Expand Down
55 changes: 55 additions & 0 deletions src/app-gocardless/banks/american-express-aesudef1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { amountToInteger, sortByBookingDate } from '../utils.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
institutionIds: ['AMERICAN_EXPRESS_AESUDEF1'],

normalizeAccount(account) {
return {
account_id: account.id,
institution: account.institution,
// The `iban` field for these American Express cards is actually a masked
// version of the PAN. No IBAN is provided.
mask: account.iban.slice(-5),
iban: null,
name: [account.details, `(${account.iban.slice(-5)})`].join(' '),
official_name: account.details,
// The Actual account `type` field is legacy and is currently not used
// for anything, so we leave it as the default of `checking`.
type: 'checking',
};
},

normalizeTransaction(transaction, _booked) {
/**
* The American Express Europe integration sends the actual date of
* purchase as `bookingDate`, and `valueDate` appears to contain a date
* related to the actual booking date, though sometimes offset by a day
* compared to the American Express website.
*/
delete transaction.valueDate;
return transaction;
},

sortTransactions(transactions = []) {
return sortByBookingDate(transactions);
},

/**
* For SANDBOXFINANCE_SFIN0000 we don't know what balance was
* after each transaction so we have to calculate it by getting
* current balance from the account and subtract all the transactions
*
* As a current balance we use `interimBooked` balance type because
* it includes transaction placed during current day
*/
calculateStartingBalance(sortedTransactions = [], balances = []) {
const currentBalance = balances.find(
(balance) => 'information' === balance.balanceType.toString(),
);

return sortedTransactions.reduce((total, trans) => {
return total - amountToInteger(trans.transactionAmount.amount);
}, amountToInteger(currentBalance.balanceAmount.amount));
},
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/239.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [kyrias]
---

Add American Express AESUDEF1 GoCardless bank integration

0 comments on commit 3dca17e

Please sign in to comment.