8000 fix(currencycloud): fixes after full testing by paul-nicolas · Pull Request #297 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(currencycloud): fixes after full testing #297

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
Jan 28, 2025
Merged

Conversation

paul-nicolas
Copy link
Contributor

No description provided.

@paul-nicolas paul-nicolas requested a review from a team as a code owner January 28, 2025 09:20
Copy link
Contributor
coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request introduces modifications to the CurrencyCloud plugin's payment and payout handling. Changes include updating the Transaction struct with new fields RelatedEntityType and RelatedEntityID, refactoring the matchTransactionType function to include more granular payment type classification, and modifying the PayoutRequest structure by removing the OnBehalfOf field and adding a Reason field. These updates enhance the contextual information and flexibility of payment and payout processing within the plugin.

Changes

File Change Summary
internal/connectors/plugins/public/currencycloud/client/payouts.go - Removed OnBehalfOf field from PayoutRequest
- Added Reason field to PayoutRequest
- Added PaymentType field to PayoutResponse
internal/connectors/plugins/public/currencycloud/client/transactions.go - Added RelatedEntityType and RelatedEntityID fields to Transaction struct
internal/connectors/plugins/public/currencycloud/payments.go - Updated matchTransactionType function signature to include RelatedEntityType
- Modified payment reference logic
internal/connectors/plugins/public/currencycloud/payouts.go - Removed contact ID retrieval in createPayout
- Added Reason to PayoutRequest
internal/connectors/plugins/public/currencycloud/payouts_test.go - Removed test case for contact ID error
- Updated test cases to use Reason instead of OnBehalfOf
internal/connectors/plugins/public/currencycloud/payments_test.go - Added new test function TestMatchTransactionType for matchTransactionType

Possibly related PRs

  • fix: (v2) ensure connector install v2 response is compatible to fctl #235: The changes in the main PR regarding the PayoutRequest and PayoutResponse structures, particularly the addition of the Reason field, relate to the modifications in the ConnectorInstallResponse type in this PR, which also involves changes to response structures in the API.
  • fix(storage): de-duplicate payments when updating db #286: The updates to the payment handling logic in the main PR, specifically the handling of adjustments and the introduction of new fields, are relevant to the changes made in this PR that focus on de-duplicating payments during database updates, ensuring that refunds are processed correctly without causing errors.

Suggested labels

build-images

Suggested reviewers

  • laouji

Poem

🐰 A Rabbit's Ode to Payment Flows 🌈

Transactions dance, with entities new,
Payouts whisper their reasons true,
No more "on behalf of" in sight,
Currencies leap with rabbit delight!

Code hops forward, clean and bright! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.07%. Comparing base (78e2b50) to head (4c03e05).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ors/plugins/public/currencycloud/client/payouts.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #297      +/-   ##
==========================================
+ Coverage   73.05%   73.07%   +0.01%     
==========================================
  Files         537      537              
  Lines       27115    27126      +11     
==========================================
+ Hits        19810    19822      +12     
- Misses       6238     6239       +1     
+ Partials     1067     1065       -2     

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

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: 1

🧹 Nitpick comments (2)
internal/connectors/plugins/public/currencycloud/payouts.go (1)

45-47: Consider differentiating between Reference and Reason

Currently, Description is used for both Reference and Reason fields. These fields typically serve different purposes:

  • Reference: A unique identifier for the transaction
  • Reason: The purpose or context of the payment

Consider using more specific fields:

-		Reference:       pi.Description,
-		Reason:          pi.Description,
+		Reference:       pi.Reference,
+		Reason:          pi.Description,
internal/connectors/plugins/public/currencycloud/client/transactions.go (1)

23-24: LGTM! Consider adding field documentation.

The new fields enhance transaction context and follow existing conventions. Consider adding documentation comments to explain the purpose and expected values of these fields.

 type Transaction struct {
        ID                string    `json:"id"`
        AccountID         string    `json:"account_id"`
        Currency          string    `json:"currency"`
        Type              string    `json:"type"`
        Status            string    `json:"status"`
        CreatedAt         time.Time `json:"created_at"`
        UpdatedAt         time.Time `json:"updated_at"`
        Action            string    `json:"action"`
+       // RelatedEntityType specifies the type of entity this transaction is related to (e.g., "payment", "transfer")
        RelatedEntityType string    `json:"related_entity_type"`
+       // RelatedEntityID contains the unique identifier of the related entity
        RelatedEntityID   string    `json:"related_entity_id"`
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f93a59 and 559f0d5.

📒 Files selected for processing (5)
  • internal/connectors/plugins/public/currencycloud/client/payouts.go (1 hunks)
  • internal/connectors/plugins/public/currencycloud/client/transactions.go (1 hunks)
  • internal/connectors/plugins/public/currencycloud/payments.go (2 hunks)
  • internal/connectors/plugins/public/currencycloud/payouts.go (1 hunks)
  • internal/connectors/plugins/public/currencycloud/payouts_test.go (2 hunks)
🔇 Additional comments (5)
internal/connectors/plugins/public/currencycloud/client/payouts.go (2)

20-20: LGTM: Addition of Reason field to PayoutRequest

The addition of the Reason field provides better context for payouts.


29-30: Consider making payment_type configurable

The payment_type is hardcoded as "regular". This might be too restrictive if CurrencyCloud supports other payment types.

Run this script to check supported payment types:

internal/connectors/plugins/public/currencycloud/payouts_test.go (1)

112-113: LGTM: Test cases updated correctly

The test cases have been properly updated to reflect the changes in the PayoutRequest structure, including the new Reason field and removal of OnBehalfOf.

Also applies to: 141-142

internal/connectors/plugins/public/currencycloud/payments.go (2)

121-126: LGTM! Clean implementation of reference handling.

Good implementation of fallback logic for payment reference, prioritizing RelatedEntityID while maintaining backward compatibility with transaction ID.


148-148: LGTM! Function signature enhancement improves type classification.

The addition of entityType parameter allows for more precise payment type determination.

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: 0

🧹 Nitpick comments (2)
internal/connectors/plugins/public/currencycloud/payments_test.go (2)

390-430: Enhance test coverage with additional test cases.

The test cases are well-structured but could be more comprehensive. Consider adding:

  1. Edge cases with empty strings for both entityType and transactionType
  2. Additional entity types that might be handled by the function
  3. A description field in the test struct to document the purpose of each test case

Apply this diff to enhance the test cases:

 tests := []struct {
+        name              string
         entityType          string
         transactionType     string
         expectedPaymentType models.PaymentType
 }{
         {
+                name:              "inbound funds credit should be payin",
                 entityType:          "inbound_funds",
                 transactionType:     "credit",
                 expectedPaymentType: models.PAYMENT_TYPE_PAYIN,
         },
+        {
+                name:              "empty entity type with credit should default to payin",
+                entityType:          "",
+                transactionType:     "credit",
+                expectedPaymentType: models.PAYMENT_TYPE_PAYIN,
+        },
+        {
+                name:              "empty transaction type should default to other",
+                entityType:          "payment",
+                transactionType:     "",
+                expectedPaymentType: models.PAYMENT_TYPE_OTHER,
+        },
         // ... existing test cases ...
 }

432-439: Improve test implementation for better debugging and maintainability.

The test implementation is good but could be enhanced for better debugging and maintainability.

Apply this diff to improve the test implementation:

 for _, test := range tests {
-        t.Run(test.entityType+"-"+test.transactionType, func(t *testing.T) {
+        t.Run(test.name, func(t *testing.T) {
                 t.Parallel()
 
                 paymentType := matchTransactionType(test.entityType, test.transactionType)
-                require.Equal(t, test.expectedPaymentType, paymentType)
+                require.Equal(t, test.expectedPaymentType, paymentType,
+                        "expected payment type %s for entityType=%q and transactionType=%q",
+                        test.expectedPaymentType, test.entityType, test.transactionType)
         })
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 559f0d5 and 4c03e05.

📒 Files selected for processing (1)
  • internal/connectors/plugins/public/currencycloud/payments_test.go (1 hunks)

@paul-nicolas paul-nicolas merged commit 1841401 into main Jan 28, 2025
9 checks passed
@paul-nicolas paul-nicolas deleted the fix/currencycloud branch January 28, 2025 10:23
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