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

feat: Moov connector for Payments #425

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

feat: Moov connector for Payments #425

wants to merge 1 commit into from

Conversation

gitstart-app[bot]
Copy link
Contributor
@gitstart-app gitstart-app bot commented Apr 25, 2025

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


This PR implements a new Moov connector for the Payments service, enabling integration with the Moov payment platform.

The connector supports:

  • Fetching accounts, wallets, bank accounts, and transfers
  • 8000
  • Creating transfers between wallets
  • Creating payouts from wallets to bank accounts
  • State management for incremental data fetching
  • Metadata handling for Moov-specific data

The implementation uses the Moov Go SDK and follows the established patterns in the Formance codebase, particularly the Stripe connector.

Key files:

  • client/client.go - Client implementation that wraps the Moov SDK
  • client/metadata.go - Metadata key definitions
  • plugin.go - Main plugin implementation
  • workflow.go - Workflow definition
  • accounts.go, wallets.go, bank_accounts.go, payments.go - Data fetching implementations
  • transfers.go, payouts.go - Payment creation implementations

Copy link
Contributor Author
gitstart-app bot commented Apr 25, 2025

This PR is estimated to cost 10 credits.
🟡 By merging this PR you agree to this estimate. If you disagree, click here.

Copy link
Contributor
coderabbitai bot commented Apr 25, 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.


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in this 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 Author
gitstart-app bot commented Apr 25, 2025

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

@gitstart-app gitstart-app bot marked this pull request as ready for review June 10, 2025 18:20
@gitstart-app gitstart-app bot requested a review from a team as a code owner June 10, 2025 18:20
@gitstart-app gitstart-app bot marked this pull request as draft June 10, 2025 22:02
@gitstart-app gitstart-app bot changed the title Moov connector for Payments feat: Moov connector for Payments Jun 11, 2025
@gitstart-app gitstart-app bot marked this pull request as ready for review June 11, 2025 14:01
Copy link
codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 57.21562% with 504 lines in your changes missing coverage. Please review.

Project coverage is 63.27%. Comparing base (b2172f0) to head (a131008).

Files with missing lines Patch % Lines
...ors/plugins/public/moov/client/client_generated.go 0.00% 144 Missing ⚠️
...l/connectors/plugins/public/moov/client/payouts.go 0.00% 66 Missing ⚠️
.../connectors/plugins/public/moov/client/payments.go 0.00% 57 Missing ⚠️
...al/connectors/plugins/public/moov/client/client.go 0.00% 47 Missing ⚠️
internal/connectors/plugins/public/moov/utils.go 84.33% 36 Missing and 11 partials ⚠️
.../connectors/plugins/public/moov/client/timeline.go 0.00% 32 Missing ⚠️
internal/storage/error.go 0.00% 17 Missing ⚠️
...l/connectors/plugins/public/moov/client/wallets.go 0.00% 16 Missing ⚠️
internal/connectors/plugins/public/moov/plugin.go 81.92% 12 Missing and 3 partials ⚠️
...nternal/connectors/plugins/public/moov/payments.go 89.09% 8 Missing and 4 partials ⚠️
... and 8 more

❗ There is a different number of reports uploaded between BASE (b2172f0) and HEAD (a131008). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (b2172f0) HEAD (a131008)
3 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
- Coverage   69.65%   63.27%   -6.39%     
==========================================
  Files         627      645      +18     
  Lines       32208    33385    +1177     
==========================================
- Hits        22436    21123    -1313     
- Misses       8558    11133    +2575     
+ Partials     1214     1129      -85     

☔ 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.

@gitstart-formance
Copy link

Summary of Implementation Choices

  1. We are handling all external accounts to external account payment as Payout.
  2. While testing payouts, we noticed that when the source account is an internal account and the destination account is an external account, the system throws an error that appears in the workflow. However, this error does not occur when both the source and destination accounts are external or source is external and destination is an internal account.
    Here is the error:
{
  "message": "activity error",
  "source": "GoSDK",
  "cause": {
    "message": "not found",
    "source": "GoSDK",
    "cause": {
      "message": "not found",
      "source": "GoSDK",
      "applicationFailureInfo": {
        "type": "fundamental"
      }
    },
    "applicationFailureInfo": {
      "type": "STORAGE",
      "nonRetryable": true
    }
  },
  "activityFailureInfo": {
    "scheduledEventId": "23",
    "startedEventId": "24",
    "identity": "267@dc56a64c1844@",
    "activityType": {
      "name": "StorageBankAccountsGet"
    },
    "activityId": "23",
    "retryState": "RETRY_STATE_NON_RETRYABLE_FAILURE"
  }
}

After some investigation, we found that the error is being handled in internal/connectors/engine/workflow/utils.go on line 182 with the following check: errors.Is(err, storage.ErrNotFound). The system is supposed to ignore the "not found" error, but the issue here is that it is not ignoring "not found" errors originating from temporal.ApplicationError.
To fix this, we modified internal/storage/error.go to add this check in the checkWorkflowStorageNotFound function, and updated the utils.go file to use storage.IsStorageNotFound(err).

This change correctly handles the error as intended.

func checkWorkflowStorageNotFound(target error) bool {
// Check if the target is directly an ApplicationError with STORAGE type
var appErr *temporal.ApplicationError
if errors.As(target, &appErr) && appErr.Type() == "STORAGE" && strings.Contains(appErr.Error(), "not found") {
return true
}
var actErr *temporal.ActivityError
if errors.As(target, &actErr) {
unwrapped := actErr.Unwrap()
if unwrapped != nil {
var innerAppErr *temporal.ApplicationError
if errors.As(unwrapped, &innerAppErr) && innerAppErr.Type() == "STORAGE" && strings.Contains(innerAppErr.Error(), "not found") {
return true
}
}
}
return false
}
func IsStorageNotFound(err error) bool {
return errors.Is(err, ErrNotFound) || checkWorkflowStorageNotFound(err)
}

if err != nil {
8000 if storage.IsStorageNotFound(err) {
return nil
}
return err
}

  1. Due to how the Moov API works, in order to keep polling for the latest payments using the startDateTime parameter, we are using the createdOn timestamp of the most recent payment as the new startDateTime. However, since the startDateTime parameter in Moov is inclusive, Moov always returns at least one payment, which is the most recent payment from the previous poll. As a result, after fetching payments, the last page will always contain one payment with the same transferID as the previous latest payment.
  2. Card and Apple Pay payments are not created by the connector, but they are also polled by the workflow. Therefore, we are not filtering them out; instead, we are storing them as transactions with the status UNKNOWN.

type Config struct {
PublicKey string `json:"publicKey" validate:"required"`
PrivateKey string `json:"privateKey" validate:"required"`
Endpoint string `json:"endpoint" validate:"required"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to validate that this is a real url. If it is parsed as a URL you can also more easily trim the url scheme below.

Comment on lines 111 to 113
endpoint: endpoint,
publicKey: publicKey,
secretKey: secretKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why persist these values in memory if we've already passed the credentials to the moov client?

endpoint: endpoint,
publicKey: publicKey,
secretKey: secretKey,
accountID: accountID,
Copy link
Contributor

Choose a reason for hiding this comment

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

where is accountID actually used?

Choose a reason for hiding this comment

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

When using the SDK, you are required to pass the ID of the Moov merchant account as accountID in order to fetch transfer options and create a transfer.

go.mod Outdated
@@ -31,6 +32,7 @@ require (
github.com/jackc/pgx/v5 v5.7.5
github.com/jackc/pgxlisten v0.0.0-20241005155529-9d952acd6a6c
github.com/lib/pq v1.10.9
github.com/moovfinancial/moov-go v0.12.0
Copy link
Contributor

Choose a reason for hiding this comment

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

There's already a v0.19.0 available. Let's upgrade if possible?

package client

const (
moovMetadataSpecNamespace = "com.moov.spec/"
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
moovMetadataSpecNamespace = "com.moov.spec/"
moovMetadataSpecNamespace = "io.moov.spec/"

}

// PaymentMethodMap maps payment method types to their details
var PaymentMethodMap = map[PaymentMethodType]PaymentMethodInfo{
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 think there is any reason to store these locally. If they add payment limits or change them it becomes unmaintainable. I think it's better to allow users to set arbitrarily high amounts and simply handle the errors that come back from the API if possible.


// Sales tax metadata keys
MoovSalesTaxAmountCurrencyMetadataKey = moovMetadataSpecNamespace + "salesTaxAmountCurrency"
MoovSalesTaxAmountValueMetadataKey = moovMetadataSpecNamespace + "salesTaxAmountvalue"
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
MoovSalesTaxAmountValueMetadataKey = moovMetadataSpecNamespace + "salesTaxAmountvalue"
MoovSalesTaxAmountValueMetadataKey = moovMetadataSpecNamespace + "salesTaxAmountValue"

Comment on lines 213 to 219
if transfer.FacilitatorFee != nil {
metadata[client.MoovFacilitatorFeeTotalMetadataKey] = fmt.Sprintf("%d", transfer.FacilitatorFee.Total)
metadata[client.MoovFacilitatorFeeTotalDecimalMetadataKey] = transfer.FacilitatorFee.TotalDecimal
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like these do not get set correctly in polled payments even when facilitator fees are present. See for example payment with reference 1241b8f1-f357-4794-babd-9afc3068a378 which has a fee of -$0.50

Choose a reason for hiding this comment

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

For this payment, the FacilitatorFee is indeed 0 USD, as confirmed from the raw data retrieved from the API. However, since other keys capture Moov-related fees, we’ll add metadata fields, moovFee and moovFeeDecimal to properly reflect these values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's interesting... because I created the payment via payments service by setting the Facilitator fee in metadata (eg. "com.moov.spec/facilitatorFeeTotal":"50"). I would assume that metadata tag sets the Facillitator fee and not some other arbitrary fee type?

Can you check what is happening there?

Choose a reason for hiding this comment

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

Sure we can take a look, perhaps you can also share a sample of the request body you used in creating this transaction?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was something like this:

{
  "reference":"transfer_250620_1823",
  "connectorID":"eyJQcm92aWRlciI6Im1vb3YiLCJSZWZlcmVuY2UiOiIxYjM2MTU3Yi1iODEzLTQ4OWYtYjQxYS1mMjA4NjliMzUwMGIifQ",
  "type":"PAYOUT",
  "description":"mooov payout with sales tax",
  "asset":"USD/2",
  "amount":411,
  "destinationAccountID":"eyJDb25uZWN0b3JJRCI6eyJQcm92aWRlciI6Im1vb3YiLCJSZWZlcmVuY2UiOiIxYjM2MTU3Yi1iODEzLTQ4OWYtYjQxYS1mMjA4NjliMzUwMGIifSwiUmVmZXJlbmNlIjoiZmE1M2Y5YTMtYjEyYS00NTU5LTg0MGItNTkwYjVjZjhlNWVlIn0",
  "sourceAccountID":"eyJDb25uZWN0b3JJRCI6eyJQcm92aWRlciI6Im1vb3YiLCJSZWZlcmVuY2UiOiIxYjM2MTU3Yi1iODEzLTQ4OWYtYjQxYS1mMjA4NjliMzUwMGIifSwiUmVmZXJlbmNlIjoiOTY4NjA5YjgtMjg4MC00MDI3LWI4ZmYtOTgzYjQ3MWVkNTk2In0",
  "metadata":{
    "com.moov.spec/sourcePaymentMethodId":"93a34443-4998-471b-8e63-2a979c75957c",
    "com.moov.spec/sourcePaymentMethodType":"moov-wallet",
    "com.moov.spec/sourceWalletId":"968609b8-2880-4027-b8ff-983b471ed596",
    "com.moov.spec/destinationPaymentMethodId":"e92254fe-d4df-447f-a741-8658fa8b7d17",
    "com.moov.spec/destinationPaymentMethodType":"rtp-credit",
    "com.moov.spec/salesTaxAmountvalue":"51",
    "com.moov.spec/salesTaxAmountCurrency":"USD/2",
    "com.moov.spec/facilitatorFeeTotal":"50"
  }
}

@gitstart-app gitstart-app bot marked this pull request as draft June 30, 2025 15:22
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.

2 participants
0