Skip to content

Commit

Permalink
Add bank handler for VIRGIN_NRNBGB22 (Virgin Money) (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Jun 16, 2024
1 parent 1af5ab0 commit 62c6a87
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app-gocardless/bank-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SandboxfinanceSfin0000 from './banks/sandboxfinance-sfin0000.js';
import SparNordSpNoDK22 from './banks/sparnord-spnodk22.js';
import SpkMarburgBiedenkopfHeladef1mar from './banks/spk-marburg-biedenkopf-heladef1mar.js';
import SpkKarlsruhekarsde66 from './banks/spk-karlsruhe-karsde66.js';
import VirginNrnbgb22 from './banks/virgin_nrnbgb22.js';

export const banks = [
AbancaCaglesmm,
Expand All @@ -33,6 +34,7 @@ export const banks = [
SparNordSpNoDK22,
SpkMarburgBiedenkopfHeladef1mar,
SpkKarlsruhekarsde66,
VirginNrnbgb22,
];

export default (institutionId) =>
Expand Down
65 changes: 65 additions & 0 deletions src/app-gocardless/banks/tests/virgin_nrnbgb22.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Virgin from '../virgin_nrnbgb22.js';
import { mockTransactionAmount } from '../../services/tests/fixtures.js';

describe('Virgin', () => {
describe('#normalizeTransaction', () => {
it('does not alter simple payee information', () => {
const transaction = {
bookingDate: '2024-01-01T00:00:00Z',
remittanceInformationUnstructured: 'DIRECT DEBIT PAYMENT',
transactionAmount: mockTransactionAmount,
};

const normalizedTransaction = Virgin.normalizeTransaction(
transaction,
true,
);

expect(normalizedTransaction.creditorName).toEqual(
'DIRECT DEBIT PAYMENT',
);
expect(normalizedTransaction.debtorName).toEqual('DIRECT DEBIT PAYMENT');
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual(
'DIRECT DEBIT PAYMENT',
);
});

it('formats bank transfer payee and references', () => {
const transaction = {
bookingDate: '2024-01-01T00:00:00Z',
remittanceInformationUnstructured: 'FPS, Joe Bloggs, Food',
transactionAmount: mockTransactionAmount,
};

const normalizedTransaction = Virgin.normalizeTransaction(
transaction,
true,
);

expect(normalizedTransaction.creditorName).toEqual('Joe Bloggs');
expect(normalizedTransaction.debtorName).toEqual('Joe Bloggs');
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual(
'Food',
);
});

it('removes method information from payee name', () => {
const transaction = {
bookingDate: '2024-01-01T00:00:00Z',
remittanceInformationUnstructured: 'Card 99, Tesco Express',
transactionAmount: mockTransactionAmount,
};

const normalizedTransaction = Virgin.normalizeTransaction(
transaction,
true,
);

expect(normalizedTransaction.creditorName).toEqual('Tesco Express');
expect(normalizedTransaction.debtorName).toEqual('Tesco Express');
expect(normalizedTransaction.remittanceInformationUnstructured).toEqual(
'Card 99, Tesco Express',
);
});
});
});
39 changes: 39 additions & 0 deletions src/app-gocardless/banks/virgin_nrnbgb22.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Fallback from './integration-bank.js';

/** @type {import('./bank.interface.js').IBank} */
export default {
...Fallback,

institutionIds: ['VIRGIN_NRNBGB22'],

accessValidForDays: 90,

normalizeTransaction(transaction, booked) {
const transferPrefixes = ['MOB', 'FPS'];
const methodRegex = /^(Card|WLT)\s\d+/;

const parts = transaction.remittanceInformationUnstructured.split(', ');

if (transferPrefixes.includes(parts[0])) {
// Transfer remittance information begins with either "MOB" or "FPS"
// the second field contains the payee and the third contains the
// reference

transaction.creditorName = parts[1];
transaction.debtorName = parts[1];
transaction.remittanceInformationUnstructured = parts[2];
} else if (parts[0].match(methodRegex)) {
// The payee is prefixed with the payment method, eg "Card 11, {payee}"

transaction.creditorName = parts[1];
transaction.debtorName = parts[1];
} else {
// Simple payee name

transaction.creditorName = transaction.remittanceInformationUnstructured;
transaction.debtorName = transaction.remittanceInformationUnstructured;
}

return Fallback.normalizeTransaction(transaction, booked);
},
};
6 changes: 6 additions & 0 deletions upcoming-release-notes/360.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [matt-fidd]
---

Add bank handler for VIRGIN_NRNBGB22 (Virgin Money) for more accurate payees

0 comments on commit 62c6a87

Please sign in to comment.