Skip to content

Commit

Permalink
feat: [#174295674] Reworks the description extraction on payments (#2171
Browse files Browse the repository at this point in the history
)

* [#174295674] Reworks the description extraction on payments

* Refactoring

* [#174295674] add tests

Co-authored-by: Matteo Boschi <[email protected]>
  • Loading branch information
CrisTofani and Undermaken authored Aug 31, 2020
1 parent f5c6dc0 commit f1a4432
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ts/utils/__tests__/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ describe("cleanTransactionDescription", () => {
"RFA/0123456789012/666.98/TXT/ actual description",
"actual description"
],
[
"RFS/0123456789012/666.98/TXT/ actual description",
"actual description"
],
[
"/RFS/0123456789012/666.98/TXT/ actual description",
"actual description"
],
["actual description", "actual description"]
].forEach(([dirty, cleaned]) => {
expect(cleanTransactionDescription(dirty)).toEqual(cleaned);
Expand Down
14 changes: 9 additions & 5 deletions ts/utils/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,19 @@ export function walletHasFavoriteAvailablePsp(
return walletPspInPsps !== undefined;
}

/**
* This tags are defined in PagoPA specs for transaction description.
* @see https://pagopa-codici.readthedocs.io/it/latest/_docs/Capitolo3.html
*/
const prefixes: ReadonlyArray<string> = ["RFA", "RFB", "RFS"];

const hasDescriptionPrefix = (description: string) =>
description.startsWith("/RFA/") ||
description.startsWith("/RFB/") ||
description.startsWith("RFA/") ||
description.startsWith("RFB/");
prefixes.some(
p => description.startsWith(`${p}/`) || description.startsWith(`/${p}/`)
);

/**
* This function removes the tag from payment description of a PagoPA transaction.
* @see https://pagopa-codici.readthedocs.io/it/latest/_docs/Capitolo3.html
*/
export const cleanTransactionDescription = (description: string): string => {
// detect description in pagoPA format - note that we also check for cases
Expand Down

0 comments on commit f1a4432

Please sign in to comment.