8000 feat: Column Connector for Payments by gitstart-app[bot] · Pull Request #351 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Column Connector for Payments #351

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

Merged
merged 3 commits into from
Apr 10, 2025
Merged

feat: Column Connector for Payments #351

merged 3 commits into from
Apr 10, 2025

Conversation

gitstart-app[bot]
Copy link
Contributor
@gitstart-app gitstart-app bot commented Mar 6, 2025

This PR was created by GitStart to address the requirements from this ticket: LNK-39.


Integrate Column Connector for the Payments Service

Features

Copy link
Contributor
coderabbitai bot commented Mar 6, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@gitstart-formance
Copy link
gitstart-formance commented Mar 7, 2025

Tested cases

  1. Install Column Connector

    • The connector should be installed successfully.
  2. Uninstall Column Connector

    • The connector should be removed successfully from the database.

    • There’s no more polling for data for that connector.

  3. Create a Bank Account

    • A new bank account should be created in Column and saved to the database.

    • The response body should return the created bank account ID.

  4. Fetching Payments

    • Payments should be fetched and stored correctly.

    • Pagination should be handled properly.

  5. Fetching External Accounts

    • Accounts should be fetched and stored correctly.

    • Pagination should be handled properly.

Payouts

  • Wire Transfer
  • Internation Transfer (Swift)
  • ACH transfer
  • Real Time Transfer

Transfer

  • Internal transfers are working

Reversal

  • Funds are reversed to the correct account -

Fails with the following error

{
    "errorCode": "INTERNAL",
    "errorMessage": "WorkflowId length exceeds limit."
}

Webhooks

The following statuses are triggered and processed:

  • book.transfer.updated
  • wire.outgoing_transfer.completed
  • ach.outgoing_transfer.settled
  • swift.outgoing_transfer.completed

@gitstart-app gitstart-app bot marked this pull request as ready for review March 8, 2025 21:37
@gitstart-app gitstart-app bot requested a review from a team as a code owner March 8, 2025 21:37
Copy link
codecov bot commented Mar 8, 2025

Codecov Report

Attention: Patch coverage is 84.21322% with 308 lines in your changes missing coverage. Please review.

Project coverage is 61.29%. Comparing base (4684930) to head (8b31798).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ternal/connectors/plugins/public/column/webhook.go 78.68% 57 Missing and 24 partials ⚠️
...connectors/plugins/public/column/client/payouts.go 86.86% 36 Missing and 13 partials ⚠️
...ernal/connectors/plugins/public/column/payments.go 77.86% 16 Missing and 11 partials ⚠️
...nectors/plugins/public/column/external_accounts.go 77.02% 11 Missing and 6 partials ⚠️
...rnal/connectors/plugins/public/column/transfers.go 80.89% 14 Missing and 3 partials ⚠️
...nternal/connectors/plugins/public/column/plugin.go 87.78% 13 Missing and 3 partials ⚠️
...ernal/connectors/plugins/public/column/accounts.go 77.41% 9 Missing and 5 partials ⚠️
...connectors/plugins/public/column/client/webhook.go 76.00% 8 Missing and 4 partials ⚠️
...ternal/connectors/plugins/public/column/payouts.go 86.36% 5 Missing and 4 partials ⚠️
.../connectors/plugins/public/column/client/client.go 78.37% 8 Missing ⚠️
... and 14 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #351      +/-   ##
==========================================
+ Coverage   59.63%   61.29%   +1.66%     
==========================================
  Files         538      565      +27     
  Lines       26734    28677    +1943     
==========================================
+ Hits        15942    17578    +1636     
- Misses       9953    10170     +217     
- Partials      839      929      +90     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


var response ReversePayoutResponse
var errRes columnError
_, err = c.httpClient.Do(ctx, request, &response, errRes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_, err = c.httpClient.Do(ctx, request, &response, errRes)
_, err = c.httpClient.Do(ctx, request, &response, &errRes)

Comment on lines 193 to 191
addressLine1 := models.ExtractNamespacedMetadata(newExternalBankAccount.Metadata, client.ColumnAddressLine1MetadataKey)

if addressLine1 != "" {

if newExternalBankAccount.Country == nil {
return fmt.Errorf("country is required")
}

}

if addressLine1 == "" && newExternalBankAccount.Country != nil {
return fmt.Errorf("metadata field country is not required when addressLine1 is not provided")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell from the documentation the following fields should always be present in the Bank Account creation request:

  • address.line_1
  • address.city
  • address.country_code

So I think we can simply check if all these fields are present, and if not return a validation error. The split of validation logic here + the validation logic in validateAddress is not optimal in my opinion as it creates a double validation and makes the conditions in the code harder to understand and therefore easier to create bugs.

Can we simplify it so that the validation function is the one that returns the errors? Perhaps it could also extract address data into an intermediate Address struct that can be be used in the requests to both the BankAccount creation and Payout initiation requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see much improvement on this front unfortunately. I understand that there is added complexity due to the validateAddress function being shared between transfer and bank account requests. How can we make this simpler (eg. fewer branches of code, less nested if statements)?

My suggestion would be to add a layer of separation between the extraction of metadata and the actual validation (what fields are required for which type of request). If you want to share code between two functions there is a need for a good abstraction to make that easy to read, debug and modify.

For example:

  1. Extract All the metadata into a ColumnAddress struct which contains all the fields related to address that will be used to make the request
  2. Pass your populated ColumnAddress struct to the validation function. The validation function now only checks if fields are valid and returns typed validation errors. It does not need to know about metadata tags (clean separation of concerns). If the validation concerns are different between bank account and transfer you might even want two different validation functions.
  3. Since you've already extracted all the fields into a struct you can get rid of all the metadata extraction happening in your code after the validation and use ColumnAddress to populate the request.

Such an approach would reduce nested if statements, reduce repetition and make functions more single-purpose (which also makes them easier to unit test and maintain).

8000
@gitstart-app gitstart-app bot marked this pull request as draft March 10, 2025 10:59
@gitstart-app gitstart-app bot marked this pull request as ready for review March 11, 2025 20:11
Comment on lines 72 to 87
8000
if addressLine1 != "" {
city := models.ExtractNamespacedMetadata(addressMetadata, client.ColumnAddressCityMetadataKey)

if city == "" {
return ErrMissingMetadataAddressCity
}

if country == "" {
if isCountryInMetadata {
return ErrMissingMetadataCountry
} else {
return ErrMissingCountry
}
}

}

if addressLine1 != "" {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if addressLine1 != "" {
city := models.ExtractNamespacedMetadata(addressMetadata, client.ColumnAddressCityMetadataKey)
if city == "" {
return ErrMissingMetadataAddressCity
}
if country == "" {
if isCountryInMetadata {
return ErrMissingMetadataCountry
} else {
return ErrMissingCountry
}
}
}
if addressLine1 != "" {
return nil
}
if addressLine1 != "" {
city := models.ExtractNamespacedMetadata(addressMetadata, client.ColumnAddressCityMetadataKey)
if city == "" {
return ErrMissingMetadataAddressCity
}
if country == "" {
if isCountryInMetadata {
return ErrMissingMetadataCountry
} else {
return ErrMissingCountry
}
}
return nil
}

@gitstart-formance
Copy link

Column api uses is_incoming flag to check if the payout is a credit or debit. However, ACH transfers with type DEBIT have is_incoming set to false, even though this operation adds money to the source account.
In addition we noticed that when some error occurs, it doesn't show up on the error column on payment_adjustment table, even though it appears in the workflow. For example, for a SWIFT payment that requires routingNumberType to be BIC, if we use ABA, it throws an error that doesn't appear in the payment_adjustment table.

@laouji
Copy link
Contributor
laouji commented Mar 25, 2025

Column api uses is_incoming flag to check if the payout is a credit or debit. However, ACH transfers with type DEBIT have is_incoming set to false, even though this operation adds money to the source account.

ACH is a specific type of bank transfer where the initiator of the transaction is not necessarily the debtor. The two combinations are possible:

  • Account A (debtor) pushes money to Account B (creditor) -> could be seen as "incoming" from Account B's perspective since A initiated
  • Account A (creditor) pulls money from Account B (debtor) -> could be seen as "incoming" from Account B's perspective since A initiated

The most important thing is that we add money when we expect it to be added and subtract it when it should be subtracted. Could you double check that the Column SDK is handling both cases correctly? If you think not we will have to file a bug report with them.

In addition we noticed that when some error occurs, it doesn't show up on the error column on payment_adjustment table, even though it appears in the workflow. For example, for a SWIFT payment that requires routingNumberType to be BIC, if we use ABA, it throws an error that doesn't appear in the payment_adjustment table.

Are you able to find the error in the logs? Would be easier for me to help you debug if you could tell me the error message you observed.

@gitstart-formance
Copy link

The most important thing is that we add money when we expect it to be added and subtract it when it should be subtracted. Could you double check that the Column SDK is handling both cases correctly? If you think not we will have to file a bug report with them.

Thanks for the clarification, yes the amount is being added and subtracted correctly.

Are you able to find the error in the logs? Would be easier for me to help you debug if you could tell me the error message you observed.

Thanks! we found some. We will forward them to you.

}

func (p *Plugin) initWebhookConfig() map[client.EventCategory]webhookConfig {
p.webhookConfigs = map[client.EventCategory]webhookConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the increase PR, we want to have all payments, which means we want to have the pending ones, the rejecting ones, the canceled ones etc... You need to handle the other webhooks from the list of events here: https://column.com/docs/workingwithapi/events-and-webhooks#all-event-types

Copy link
Contributor
@laouji laouji left a comment

Choose a reason for hiding this comment

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

My comments have been addressed.

@paul-nicolas paul-nicolas merged commit e678660 into main Apr 10, 2025
9 checks passed
@paul-nicolas paul-nicolas deleted the LNK-39 branch April 10, 2025 12:44
Copy link
Contributor Author
gitstart-app bot commented Apr 25, 2025

We have prepared a new estimate of 185 credits for this pull request.
🟡 By merging this PR you agree to this new estimate. If you disagree, click here.

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

Successfully merging this pull request may close these issues.

3 participants
0