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

feat: (payments) add stripe v3 connector #1724

Merged
merged 13 commits into from
Sep 30, 2024

Conversation

laouji
Copy link

@laouji laouji commented Sep 26, 2024

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. 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.

Walkthrough

The changes introduce a Stripe payment connector to the payments module, enhancing the system's ability to manage payment-related operations. Key additions include methods for fetching accounts, balances, external accounts, and payments, as well as configuration and error handling functionalities. The implementation includes unit tests to ensure the reliability of the new features and a structured workflow for task management.

Changes

File Path Change Summary
components/payments/Earthfile Added a new target generate for building the payments component, including installation of OpenJDK 11 and the go.uber.org/mock/mockgen package.
components/payments/internal/api/backend/backend_generated.go Updated method signatures in MockBackendMockRecorder from interface{} to any.
components/payments/internal/connectors/plugins/public/stripe/accounts.go Introduced functionality for managing accounts via Stripe API, including state management and account fetching logic.
components/payments/internal/connectors/plugins/public/stripe/balances.go Added a method for fetching account balances from the Stripe API.
components/payments/internal/connectors/plugins/public/stripe/client/* Multiple files added for client-side interactions with the Stripe API, including methods for retrieving accounts, balances, external accounts, and payments.
components/payments/internal/connectors/plugins/public/stripe/plugin.go Implemented the main Stripe plugin structure, including installation and client management methods.
components/payments/internal/connectors/plugins/public/stripe/workflow.go Defined a workflow for managing payment-related tasks, establishing a hierarchy for fetching accounts, balances, payments, and external accounts.
components/payments/internal/connectors/plugins/public/stripe/*_test.go Introduced unit tests for various functionalities of the Stripe plugin, ensuring comprehensive coverage of the new features.

Assessment against linked issues

Objective Addressed Explanation
Payments v3.X: add Stripe Connector (ENG-1369)

Suggested reviewers

  • flemzord

Poem

In a world of payments, swift and bright,
A Stripe connector hops into the light.
With accounts and balances, all in a row,
Fetching and testing, watch the progress flow!
A rabbit's delight in code so neat,
Hopping along to make transactions sweet! 🐇✨


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.

@laouji laouji changed the title feat(payments) add stripe v3 connector feat: (payments) add stripe v3 connector Sep 26, 2024
@laouji laouji force-pushed the feat/payments-v3-stripe branch 2 times, most recently from e5cff0a to fded87d Compare September 26, 2024 14:11
@laouji laouji marked this pull request as ready for review September 26, 2024 14:20
@laouji laouji requested a review from a team as a code owner September 26, 2024 14:20
@laouji
Copy link
Author

laouji commented Sep 26, 2024

@coderabbitai summary

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

✅ Actions performed

Summary regeneration triggered.

&expandSourceRefundPaymentIntent,
}

itr := c.balanceTransactionClient.List(&stripe.BalanceTransactionListParams{
Copy link
Contributor

Choose a reason for hiding this comment

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

Since balance transactions are ordered starting from the most recent transactions, are we sure that the backward fetching is handled correctly and all adjustments are inserted correctly ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we're gonna have a problem, since the balance transactions are started from the most recent, you will fetch the whole history without problems, but when new payments are coming you will never fetch them since they are on the other side of the list

Copy link
Author

Choose a reason for hiding this comment

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

Ok I see now that the original implementation was using created[lt] to fetch balance transactions. Will see how I can replicate that with the SDK.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated it to fetch transactions, accounts and external accounts in ASC order

)

// root account reference is internal so we don't pass it to Stripe API clients
func resolveAccount(ref *string) *string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to pass a pointer here for the reference ?

Copy link
Author

Choose a reason for hiding this comment

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

I don't need to. We can change it to a simple string if you prefer.

More just stylistic because the v2 implementation was passing around a potentially nillable account to methods like Translate that behave slightly different depending on whether an account was specified or not. So I am treating from.Reference from the cache as something that we expect might be nil across the board (as opposed to having empty string checks).

Copy link
Author

Choose a reason for hiding this comment

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

I reduced the number of pointers to strings

needed := req.PageSize - len(accounts)

newState := AccountsState{
InitFinished: oldState.InitFinished,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not setting the LastID with the oldstate LastID ?

If the call to return accounts returns none (for example last page, but empty), you will reset the state and refetch everything since the LastID on the next call will be empty

Copy link
Author

Choose a reason for hiding this comment

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

Oops. Good catch.

Copy link
Author

Choose a reason for hiding this comment

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

This is addressed

@laouji laouji merged commit 0c7ff8b into feat/payments-v3 Sep 30, 2024
9 checks passed
@laouji laouji deleted the feat/payments-v3-stripe branch September 30, 2024 08:27
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.

2 participants