Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GoCardless integration for ENTERCARD_SWEDNOKK #506

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kyrias
Copy link
Contributor

@kyrias kyrias commented Nov 23, 2024

No description provided.

@actual-github-bot actual-github-bot bot changed the title Add GoCardless integration for ENTERCARD_SWEDNOKK [WIP] Add GoCardless integration for ENTERCARD_SWEDNOKK Nov 23, 2024
@kyrias kyrias changed the title [WIP] Add GoCardless integration for ENTERCARD_SWEDNOKK Add GoCardless integration for ENTERCARD_SWEDNOKK Nov 23, 2024
Copy link
Contributor

coderabbitai bot commented Nov 23, 2024

Walkthrough

The pull request introduces changes to the bank integration system within the application. Specifically, it adds a new bank, EntercardSwednokk, by importing it from ./banks/entercard-swednokk.js and includes it in the banks array in src/app-gocardless/bank-factory.js. Additionally, the previously commented-out bank import, SandboxfinanceSfin0000, is now active and also included in the banks array. The overall structure of the banks array remains unchanged. Furthermore, a new file, entercard-swednokk.js, is created, which implements the IBank interface for the Entercard Swednokk institution. This file defines various properties and methods for account and transaction normalization, including methods for normalizing account data, processing transactions, sorting transactions, and calculating starting balances. The changes do not affect the existing method signature of the default export function or the BANKS_WITH_LIMITED_HISTORY constant.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • matt-fidd

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
src/app-gocardless/banks/entercard-swednokk.js (1)

36-41: Avoid mutating the input 'transaction' object

Modifying the transaction object directly can lead to unintended side effects. Instead of mutating transaction.transactionAmount, consider creating a new object with the updated transactionAmount.

Apply this diff to avoid mutating the input object:

 const remittanceInformationUnstructured =
   transaction.remittanceInformationUnstructured;
 if (
   remittanceInformationUnstructured &&
   remittanceInformationUnstructured.startsWith('billingAmount: ')
 ) {
-  transaction.transactionAmount = {
+  const updatedTransactionAmount = {
     amount: parseFloat(remittanceInformationUnstructured.substring(15)),
     currency: 'SEK',
   };
+  return {
+    ...transaction,
+    transactionAmount: updatedTransactionAmount,
+    payeeName: formatPayeeName(transaction),
+    date: transaction.valueDate
+      ? d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd')
+      : null,
+  };
 }

This ensures that the original transaction object remains unmodified.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 69a04a5 and 3560f73.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/506.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • src/app-gocardless/bank-factory.js (4 hunks)
  • src/app-gocardless/banks/entercard-swednokk.js (1 hunks)
🔇 Additional comments (5)
src/app-gocardless/bank-factory.js (3)

25-25: Verify if sandbox bank activation is intentional

The sandbox bank SandboxfinanceSfin0000 has been uncommented alongside the new Entercard integration. This seems unusual for a production bank addition.

Let's check if this was discussed in the PR or if there are related test changes:

✅ Verification successful

Sandbox bank is used for integration testing

The sandbox bank SandboxfinanceSfin0000 is intentionally included in the codebase as it's used for integration testing:

  • It's referenced in test files (gocardless-service.spec.js, integration-bank.spec.js)
  • The README explicitly mentions it as a template: "Create new a bank class based on app-gocardless/banks/sandboxfinance-sfin0000.js"
  • It's consistently used across multiple test fixtures and integration tests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any test files or documentation mentioning the sandbox bank
rg -i "sandboxfinance|sfin0000" --type md --type js

Length of output: 3151


Line range hint 69-116: Verify bank configuration requirements

Please verify:

  1. Whether ENTERCARD_SWEDNOKK should be added to BANKS_WITH_LIMITED_HISTORY
  2. If the institutionId in the implementation matches "ENTERCARD_SWEDNOKK"

Let's check the configuration:

✅ Verification successful

Bank configuration verification completed

Based on the code analysis:

  1. The institutionId "ENTERCARD_SWEDNOKK" is correctly implemented in the bank file.
  2. The bank should not be added to BANKS_WITH_LIMITED_HISTORY as:
    • The implementation shows no specific history limitations
    • The bank follows the standard transaction fetching pattern
    • BANKS_WITH_LIMITED_HISTORY is used to cap transaction history at 89 days for specific banks, which isn't a requirement for this integration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the institution ID in the implementation
rg -A 2 "institutionIds.*ENTERCARD" ./banks/entercard-swednokk.js

# Look for any documentation about history limitations
rg -i "entercard.*history" --type md

Length of output: 176


Script:

#!/bin/bash
# Let's first find the correct path for the bank implementation
fd -t f "entercard" --full-path

# Search for institution ID pattern in all files
rg -i "entercard.*swednokk" 

# Check if there's any documentation about this bank
rg -i "entercard" --type md

Length of output: 539


Script:

#!/bin/bash
# Let's check the implementation of entercard-swednokk.js to see if there are any history limitations
cat src/app-gocardless/banks/entercard-swednokk.js

# Let's also check if there are any patterns or documentation about banks with limited history
rg -i "limited.?history" --type js

Length of output: 2310


Script:

#!/bin/bash
# Let's check how maxHistoricalDays is used for banks with limited history
rg -A 5 "maxHistoricalDays:" src/app-gocardless/services/gocardless-service.js

# Let's also check if there are any comments or documentation about the criteria for limited history banks
rg -B 2 "BANKS_WITH_LIMITED_HISTORY" src/app-gocardless/

Length of output: 1034


44-44: Verify EntercardSwednokk implementation

The bank is correctly added to the array, but let's verify its implementation matches the interface requirements.

Let's check the implementation:

✅ Verification successful

EntercardSwednokk implementation matches interface requirements

The implementation correctly implements all required methods from the IBank interface:

  • institutionIds: Correctly defined with 'ENTERCARD_SWEDNOKK'
  • accessValidForDays: Set to 180
  • normalizeAccount: Properly formats account details with required fields
  • normalizeTransaction: Handles transaction normalization with special forex handling
  • sortTransactions: Uses common utility for sorting
  • calculateStartingBalance: Correctly implements balance calculation

The implementation follows similar patterns to other bank implementations like American Express, with appropriate customizations for Entercard's specific needs, particularly in forex transaction handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the new bank implements required interface methods
ast-grep --pattern 'export default {
  $$$
  institutionIds: $_,
  normalizeAccount: $_,
  normalizeTransaction: $_,
  $$$
}' ./banks/entercard-swednokk.js

# Check for test coverage
rg -l "entercard.*\.test\." 

Length of output: 264


Script:

#!/bin/bash
# Let's first find the correct path for the bank implementation
fd -t f -i "entercard"

# After finding the file, we'll check its content
fd -t f -i "entercard" --exec cat {}

Length of output: 1994


Script:

#!/bin/bash
# Let's verify the test coverage
fd -t f -i "entercard.*test"

# Let's also check the bank interface requirements
cat src/app-gocardless/banks/bank.interface.js

Length of output: 154


Script:

#!/bin/bash
# Let's find the interface file first
fd -t f "bank.interface"

# Let's also check other bank implementations for comparison
fd -t f -d 1 . src/app-gocardless/banks/ --exec ls -la {}

Length of output: 3306


Script:

#!/bin/bash
# Let's check the interface requirements
cat src/app-gocardless/banks/bank.interface.ts

# Let's also check a similar bank implementation for comparison
cat src/app-gocardless/banks/american-express-aesudef1.js

Length of output: 3217

src/app-gocardless/banks/entercard-swednokk.js (2)

55-57: Verify the correctness of starting balance calculation

The calculateStartingBalance function subtracts each transaction amount from the initial balance. Please verify that this logic accurately reflects the intended calculation, considering the sign of transaction amounts and whether they should be added or subtracted to compute the starting balance.


24-24: Ensure 'account.institution_id' is defined

In the official_name property, you are using account.institution_id. Please verify that institution_id exists on the account object to avoid undefined values.

return {
...transaction,
payeeName: formatPayeeName(transaction),
date: d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure 'transaction.valueDate' is defined before parsing

If transaction.valueDate is undefined or invalid, d.parseISO may result in an invalid date, and d.format could produce unexpected results or throw an error. Consider checking that transaction.valueDate is a valid ISO string before parsing.

Apply this diff to handle undefined transaction.valueDate:

 return {
   ...transaction,
   payeeName: formatPayeeName(transaction),
-  date: d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd'),
+  date: transaction.valueDate
+    ? d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd')
+    : null,
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
date: d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd'),
date: transaction.valueDate
? d.format(d.parseISO(transaction.valueDate), 'yyyy-MM-dd')
: null,

Comment on lines +38 to +39
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Parse and validate 'amount' to ensure it's a valid number

When extracting the amount from remittanceInformationUnstructured, it's important to parse and validate it to ensure it's a valid number. This prevents potential errors or injection attacks due to unexpected input formats.

Apply this diff to parse and validate the amount:

 transaction.transactionAmount = {
-  amount: remittanceInformationUnstructured.substring(15),
+  amount: parseFloat(remittanceInformationUnstructured.substring(15)),
   currency: 'SEK',
 };
+if (isNaN(transaction.transactionAmount.amount)) {
+  // Handle the error appropriately, e.g., throw an error or set a default value
+  throw new Error('Invalid transaction amount extracted from remittance information.');
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
amount: parseFloat(remittanceInformationUnstructured.substring(15)),
currency: 'SEK',
if (isNaN(transaction.transactionAmount.amount)) {
// Handle the error appropriately, e.g., throw an error or set a default value
throw new Error('Invalid transaction amount extracted from remittance information.');
}

Comment on lines +35 to +41
transaction.remittanceInformationUnstructured;
if (remittanceInformationUnstructured.startsWith('billingAmount: ')) {
transaction.transactionAmount = {
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle undefined 'remittanceInformationUnstructured' before calling 'startsWith'

If transaction.remittanceInformationUnstructured is undefined or null, calling startsWith on it will result in a runtime error. Consider adding a check to ensure it is defined before calling startsWith.

Apply this diff to fix the issue:

 const remittanceInformationUnstructured =
   transaction.remittanceInformationUnstructured;
+if (
+  remittanceInformationUnstructured &&
+  remittanceInformationUnstructured.startsWith('billingAmount: ')
+) {
   transaction.transactionAmount = {
     amount: remittanceInformationUnstructured.substring(15),
     currency: 'SEK',
   };
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
transaction.remittanceInformationUnstructured;
if (remittanceInformationUnstructured.startsWith('billingAmount: ')) {
transaction.transactionAmount = {
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
};
}
const remittanceInformationUnstructured =
transaction.remittanceInformationUnstructured;
if (
remittanceInformationUnstructured &&
remittanceInformationUnstructured.startsWith('billingAmount: ')
) {
transaction.transactionAmount = {
amount: remittanceInformationUnstructured.substring(15),
currency: 'SEK',
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant