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

fix(*): payment initiations fixes #374

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 2 commits into from
Mar 24, 2025
Merged

Conversation

paul-nicolas
Copy link
Contributor
@paul-nicolas paul-nicolas commented Mar 21, 2025

Fixes

ScheduledAt new adjustments

Context

When creating a transfer/payout with a scheduled at in the future, we were creating the temporal workflow with the corresponding delay. But the corresponding transfer/payout was not in processing mode, and was still in waiting for validation.

What's new

I replaced the delay on the temporal workflow by a workflow.Sleep (and added some tests)
I added a new adjustment status called "SCHEDULED_FOR_PROCESSING" which will tell the client that their approval was done and that the payment is now in waiting mode

To keep the compatibility with the V2 api, this status is replaced by a PROCESSING status when getting adjustments with the v2 API

image image

Blocking call when creating a transfer/payout in v2 with a scheduled at

Context

In the previous version of payments, we were not waiting for results when a client was creating a transfer/payout in the future thanks to the scheduledAt.

What's new

This PR introduces a fix for that, hence not waiting for temporal workflow to finish if we have a scheduledAt in the future

Related Payments of transfer in v2

What's new

This is a fix for the v2 openapi, the related payment status should be a PaymentStatus and not a TransferInitiationStatus

Fixes PMNT-71
Fixes PMNT-73
Fixes PMNT-74

Copy link
Contributor
coderabbitai bot commented Mar 21, 2025

Walkthrough

This pull request makes several adjustments across the codebase by removing unused fields (like isgomock) from various mock types, and by eliminating the startDelay parameter from multiple payment initiation functions and their tests. It also adds new logic to handle scheduled payments in transfer and payout workflows by checking future ScheduledAt timestamps, adding corresponding adjustments, and delaying execution accordingly. Additionally, minor signature tweaks and status translation updates have been introduced, alongside new tests to validate the scheduling functionality.

Changes

File(s) Summary of Changes
internal/api/backend/backend_generated.go, internal/connectors/engine/activities/schedule_client_generated.go, internal/connectors/engine/plugins/plugin_generated.go Removed unused isgomock fields from mock structures.
internal/api/services/payment_initiations_approve.go, internal/api/services/payment_initiations_create.go, internal/api/services/payment_initiations_retry.go, internal/connectors/engine/engine.go, internal/connectors/engine/engine_generated.go Eliminated startDelay parameter and its associated logic from function signatures and method calls.
internal/api/services/payment_initiations_approve_test.go, internal/api/services/payment_initiations_create_test.go, internal/api/services/payment_initiations_retry_test.go Updated tests to reflect revised parameter values and removal of startDelay.
internal/api/v2/handler_transfer_initiations_get.go, internal/api/v2/handler_transfer_initiations_list.go Added and modified logic to translate and filter adjustment statuses, ensuring unsupported statuses are not sent.
internal/connectors/engine/workers.go Replaced the unused ctx parameter with an underscore in the onStartPlugin method signature.
internal/connectors/engine/workflow/create_payout.go, internal/connectors/engine/workflow/create_transfer.go Introduced conditional logic to handle scheduled payment initiations by creating adjustments and sleeping until the scheduled time.
internal/connectors/engine/workflow/create_payout_test.go, internal/connectors/engine/workflow/create_transfer_test.go Added new tests for workflows that process scheduled payouts and transfers.
internal/models/payment_initiation_adjusments_status.go Added a new constant PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING and updated status conversion methods accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Workflow
    participant Engine
    participant Plugin

    Client->>Workflow: Initiate Payment (with ScheduledAt)
    Workflow->>Workflow: Check if ScheduledAt > current time
    alt Payment is Scheduled
        Workflow->>Workflow: Add Adjustment (SCHEDULED_FOR_PROCESSING)
        Workflow->>Workflow: Sleep until ScheduledAt
    end
    Workflow->>Engine: Call CreateTransfer/CreatePayout (no startDelay)
    Engine->>Plugin: Execute Payment Operation
    Plugin-->>Engine: Return Result
    Engine-->>Workflow: Return Task/Result
    Workflow-->>Client: Confirm Payment Processed
Loading

Assessment against linked issues

Objective Addressed Explanation
Add new adjustment status for scheduled payments (PMNT-71)
Do not wait for transfer/payout results for future-scheduled payments (PMNT-73)
Fix OpenAPI v2 for transfer initiation related payments status (PMNT-74) The changes do not explicitly address the OpenAPI v2 status representation.

Possibly related PRs

  • formancehq/payments#274: Involves removal of the isgomock field from mock structs, aligning with similar changes in this PR.
  • formancehq/payments#250: Also removes the unused isgomock field and adjusts mock interfaces, demonstrating consistent code-level updates.
  • formancehq/payments#251: Mirrors the removal of the isgomock field from the MockBackend struct, reinforcing the simplification effort across components.

Suggested labels

build-images

Poem

I'm a little rabbit, hopping through code so neat,
Cleaning out unused fields with every little beat.
No more isgomock to clutter our space,
And scheduled payments now set the pace.
With delays replaced by logic so bright,
I hop along, celebrating changes in code tonight!
🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f21afce and b3e53ff.

📒 Files selected for processing (2)
  • internal/connectors/engine/workflow/create_payout.go (1 hunks)
  • internal/connectors/engine/workflow/create_transfer.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/connectors/engine/workflow/create_payout.go
🧰 Additional context used
🧬 Code Definitions (1)
internal/connectors/engine/workflow/create_transfer.go (1)
internal/connectors/engine/workflow/create_payout.go (2) (2)
  • w (20-40)
  • w (42-209)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (1)
internal/connectors/engine/workflow/create_transfer.go (1)

55-79:

❓ Verification inconclusive

Implementation for handling scheduled transfers looks good!

The added functionality correctly handles transfers scheduled for a future date by:

  1. Setting an appropriate status adjustment (SCHEDULED_FOR_PROCESSING)
  2. Storing the scheduled time in the adjustment metadata
  3. Using workflow.Sleep to pause execution until the scheduled time

This implementation aligns with the PR objectives and is consistent with the approach used in create_payout.go.

Consider the implications of very long sleep durations if transfers can be scheduled far in the future. Does Temporal have any limitations on workflow.Sleep durations that might impact this implementation?


🏁 Script executed:

#!/bin/bash
# Look for any constraints or documentation around long workflow.Sleep durations in Temporal
rg -A 2 -B 2 "workflow\.Sleep" --glob "!*.go" --glob "*.md"

Length of output: 61


Scheduled Transfers: Verify Long Sleep Duration Constraints

The implementation for handling scheduled transfers is well done. It correctly:

  • Flags the payment initiation with a SCHEDULED_FOR_PROCESSING status.
  • Stores the scheduled time in the adjustment metadata.
  • Uses workflow.Sleep to pause execution until the scheduled time.

One point to note: our search through markdown documentation did not uncover any constraints on long workflow.Sleep durations. If transfers can be scheduled far in the future, please manually verify that Temporal imposes no limitations or unintended side effects when workflows sleep for extended periods.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@paul-nicolas paul-nicolas force-pushed the fix/payment-initiations-fixes branch 2 times, most recently from 55f901a to e222bf4 Compare March 21, 2025 13:53
@paul-nicolas paul-nicolas force-pushed the fix/payment-initiations-fixes branch from e222bf4 to f21afce Compare March 21, 2025 13:56
@paul-nicolas
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor
coderabbitai bot commented Mar 21, 2025
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

8000

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/connectors/engine/workflow/create_transfer.go (1)

55-76: Well-implemented scheduling logic for payment initiations.

The added code correctly checks if the payment is scheduled for the future and handles it appropriately by:

  1. Creating an adjustment with the new SCHEDULED_FOR_PROCESSING status
  2. Including the scheduled time in the metadata
  3. Using workflow.Sleep to pause execution until the scheduled time

This implementation aligns with the PR objectives by replacing the delay mechanism with a sleep function and introducing the new adjustment status.

However, I would suggest adding a comment explaining the purpose of this block to improve code readability:

+// If the payment is scheduled for a future time:
+// 1. Create an adjustment with SCHEDULED_FOR_PROCESSING status
+// 2. Sleep until the scheduled time before proceeding
 now := workflow.Now(ctx)
 if !pi.ScheduledAt.IsZero() && pi.ScheduledAt.After(now) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 09ec0e4 and f21afce.

⛔ Files ignored due to path filters (3)
  • openapi.yaml is excluded by !**/*.yaml
  • openapi/v1-2/v1-2.yaml is excluded by !**/*.yaml
  • openapi/v3/v3-schemas.yaml is excluded by !**/*.yaml
📒 Files selected for processing (19)
  • internal/api/backend/backend_generated.go (0 hunks)
  • internal/api/services/payment_initiations_approve.go (1 hunks)
  • internal/api/services/payment_initiations_approve_test.go (2 hunks)
  • internal/api/services/payment_initiations_create.go (1 hunks)
  • internal/api/services/payment_initiations_create_test.go (1 hunks)
  • internal/api/services/payment_initiations_retry.go (1 hunks)
  • internal/api/services/payment_initiations_retry_test.go (1 hunks)
  • internal/api/v2/handler_transfer_initiations_get.go (2 hunks)
  • internal/api/v2/handler_transfer_initiations_list.go (2 hunks)
  • internal/connectors/engine/activities/schedule_client_generated.go (0 hunks)
  • internal/connectors/engine/engine.go (3 hunks)
  • internal/connectors/engine/engine_generated.go (2 hunks)
  • internal/connectors/engine/plugins/plugin_generated.go (0 hunks)
  • internal/connectors/engine/workers.go (1 hunks)
  • internal/connectors/engine/workflow/create_payout.go (1 hunks)
  • internal/connectors/engine/workflow/create_payout_test.go (2 hunks)
  • internal/connectors/engine/workflow/create_transfer.go (1 hunks)
  • internal/connectors/engine/workflow/create_transfer_test.go (2 hunks)
  • internal/models/payment_initiation_adjusments_status.go (3 hunks)
💤 Files with no reviewable changes (3)
  • internal/connectors/engine/plugins/plugin_generated.go
  • internal/connectors/engine/activities/schedule_client_generated.go
  • internal/api/backend/backend_generated.go
🧰 Additional context used
🧬 Code Definitions (12)
internal/api/services/payment_initiations_create.go (2)
internal/api/services/payment_initiations_approve.go (1) (1)
  • s (14-64)
internal/api/services/payment_initiations_retry.go (2) (2)
  • s (13-54)
  • s (67-95)
internal/api/v2/handler_transfer_initiations_get.go (1)
internal/models/payment_initiation_adjusments_status.go (3) (3)
  • status (128-128)
  • PaymentInitiationAdjustmentStatus (10-10)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING (22-22)
internal/api/services/payment_initiations_approve.go (1)
internal/api/services/payment_initiations_create.go (1) (1)
  • s (9-46)
internal/api/services/payment_initiations_create_test.go (2)
internal/connectors/engine/workflow/create_transfer.go (1) (1)
  • CreateTransfer (14-18)
internal/connectors/engine/workflow/create_payout.go (1) (1)
  • CreatePayout (14-18)
internal/connectors/engine/workflow/create_transfer.go (2)
internal/models/payment_initiation_adjusments_status.go (2) (2)
  • err (129-129)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING (22-22)
internal/connectors/engine/workflow/create_payout.go (2) (2)
  • w (20-40)
  • w (42-206)
internal/api/services/payment_initiations_approve_test.go (2)
internal/api/services/payment_initiations_approve.go (1) (1)
  • s (14-64)
internal/api/services/payment_initiations_create.go (1) (1)
  • s (9-46)
internal/api/services/payment_initiations_retry.go (1)
internal/api/services/payment_initiations_create.go (1) (1)
  • s (9-46)
internal/connectors/engine/workflow/create_payout.go (1)
internal/connectors/engine/workflow/create_transfer.go (2) (2)
  • w (20-40)
  • w (42-208)
internal/api/services/payment_initiations_retry_test.go (2)
internal/connectors/engine/workflow/create_transfer.go (1) (1)
  • CreateTransfer (14-18)
internal/connectors/engine/workflow/create_payout.go (1) (1)
  • CreatePayout (14-18)
internal/connectors/engine/workflow/create_transfer_test.go (2)
internal/models/payment_initiation_adjusments_status.go (3) (3)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING (22-22)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSING (15-15)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED (16-16)
internal/connectors/engine/workflow/create_transfer.go (2) (2)
  • RunCreateTransfer (210-210)
  • CreateTransfer (14-18)
internal/connectors/engine/workflow/create_payout_test.go (3)
internal/models/payment_initiation_adjusments_status.go (3) (3)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING (22-22)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSING (15-15)
  • PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED (16-16)
internal/models/plugin.go (2) (2)
  • CreatePayoutRequest (181-183)
  • CreatePayoutResponse (185-192)
internal/connectors/engine/workflow/create_payout.go (2) (2)
  • RunCreatePayout (208-208)
  • CreatePayout (14-18)
internal/connectors/engine/engine_generated.go (2)
internal/connectors/engine/workflow/create_payout.go (1) (1)
  • CreatePayout (14-18)
internal/connectors/engine/workflow/create_transfer.go (1) (1)
  • CreateTransfer (14-18)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (31)
internal/connectors/engine/workers.go (1)

115-115: Good refactoring to remove unused parameter.

Renaming the unused context parameter to _ is a good practice that avoids linter warnings while making it clear that the parameter is intentionally unused.

internal/connectors/engine/workflow/create_payout.go (1)

55-76: Excellent implementation of payment scheduling feature.

This change implements the scheduled payments feature by checking for future ScheduledAt timestamps, creating a "SCHEDULED_FOR_PROCESSING" adjustment, and then using workflow.Sleep to delay execution until the scheduled time. The implementation aligns with the similar approach in the createTransfer method and properly handles all necessary metadata.

The new status clearly indicates that client approval has been received and the payment is waiting to be processed at the scheduled time.

internal/connectors/engine/engine.go (2)

47-47: Good API simplification by removing the startDelay parameter.

Removing the startDelay parameter from the interface methods is a good design decision since scheduling is now handled internally by the workflow using the ScheduledAt field on the payment initiation model. This change simplifies the API and makes it more intuitive for callers.

Also applies to: 51-51


516-516: Correctly implemented method signatures matching the interface changes.

The implementation methods have been properly updated to match the interface changes, removing the startDelay parameter. This maintains consistency across the codebase.

Also applies to: 634-634

internal/connectors/engine/engine_generated.go (1)

88-90: Successfully updated mock implementations to match the new method signatures.

The mock implementations have been properly updated to reflect the removal of the startDelay parameter from the CreateTransfer and CreatePayout methods. This ensures that tests using these mocks will continue to work with the updated API.

Also applies to: 97-99, 117-120, 126-129

internal/api/services/payment_initiations_retry.go (2)

40-40: Signature update correctly removes the startDelay parameter

The CreateTransfer method call has been updated to remove the startDelay parameter, aligning with the PR's approach of handling scheduled payments differently. This change is consistent with the modifications in other service methods.


46-46: Signature update correctly removes the startDelay parameter

Similar to the CreateTransfer method, the CreatePayout call has been updated to remove the startDelay parameter. This provides consistency across both payment initiation types.

internal/api/services/payment_initiations_create.go (2)

32-32: Signature update correctly removes the startDelay parameter

The CreateTransfer method call has been updated to remove the startDelay parameter, aligning with the PR's approach of handling scheduled payments within the workflow engine rather than at the API service level.


38-38: Signature update correctly removes the startDelay parameter

The CreatePayout method call has been updated to remove the startDelay parameter, consistent with the changes in CreateTransfer and maintaining uniformity across both payment types.

internal/api/v2/handler_transfer_initiations_list.go (2)

53-62: Status translation for V2 API backward compatibility

This change properly handles the new SCHEDULED_FOR_PROCESSING status by mapping it to PROCESSING for V2 API backward compatibility. The comment clearly explains the rationale, which aligns with the PR objectives of addressing the status discrepancy between API versions.

The implementation uses a straightforward switch statement to handle the specific case while defaulting to the original behavior for other statuses, maintaining compatibility without disrupting existing functionality.


64-64: Updated to use the translated status value

The status assignment has been correctly updated to use the newly computed status variable, ensuring the status translation logic is properly applied to the response.

internal/api/services/payment_initiations_create_test.go (2)

100-100: Test expectation updated to match new signature

The test mock expectation has been updated to match the new signature of CreateTransfer that no longer includes the startDelay parameter, replacing it with the attempt count parameter value of 1.


102-102: Test expectation updated to match new signature

The test mock expectation for CreatePayout has been updated to use the specific value of 1 for the attempt count parameter instead of gomock.Any(), aligning with the changes in the method signature and implementation.

internal/api/services/payment_initiations_approve_test.go (5)

44-45: Updated ScheduledAt for scheduled payment testing.

The test now uses a future time (current time + 1 hour) for the ScheduledAt field to properly test the scheduled payment functionality.


144-147: Correctly determine waitResult based on scheduling condition.

This change implements conditional logic to set waitResult based on whether the payment initiation is scheduled for the future, which aligns with the updated implementation in the PaymentInitiationsApprove function.


152-153: Updated CreateTransfer call to use dynamic waitResult parameter.

The test now correctly uses the waitResult variable based on scheduling conditions rather than a hardcoded value, ensuring that the test accurately reflects the production code behavior.


154-155: Updated CreatePayout call to use dynamic waitResult parameter.

Similar to the CreateTransfer update, this ensures consistent behavior for payouts by using the dynamic waitResult value determined by scheduling conditions.


159-159: Changed waitResult parameter in PaymentInitiationsApprove call from false to true.

This change ensures that the test verifies the correct handling of the waitResult parameter in the service method, allowing the test to validate that the method properly overrides this value when there's a scheduled date.

internal/connectors/engine/workflow/create_payout_test.go (2)

7-7: Added time package import.

Added import for the time package to support the new scheduled payout test functionality.


84-162: Added test for scheduled payout processing.

This new test validates the payment initiation workflow when a payout is scheduled for a future time. It ensures:

  1. The workflow correctly creates an adjustment with SCHEDULED_FOR_PROCESSING status initially
  2. After the scheduled time, it creates a PROCESSING adjustment
  3. Finally, it creates a PROCESSED adjustment when the payment completes
  4. The workflow handles the temporal sleep and transitions between states correctly

This comprehensively tests the new scheduled payment functionality, covering the entire state transition flow.

internal/api/services/payment_initiations_approve.go (3)

42-46: Improved handling of scheduled payments.

This change correctly determines that payments scheduled for the future should not wait for results, overriding any user-provided waitResult value. The code now:

  1. Checks if ScheduledAt is non-zero and in the future
  2. Sets waitResult = false in that case, since waiting isn't appropriate for scheduled payments
  3. Includes helpful comments explaining the rationale

This eliminates the previous complexity of manual delay calculations and simplifies the logic.


50-50: Removed startDelay parameter from CreateTransfer call.

The function now correctly passes the dynamic waitResult value to the engine, allowing the workflow to handle the scheduling internally rather than using a delay mechanism in the API service.


56-56: Removed startDelay parameter from CreatePayout call.

Similar to the CreateTransfer update, this change passes the dynamic waitResult value to the engine for payouts, maintaining consistent behavior between different payment types.

internal/api/v2/handler_transfer_initiations_get.go (3)

121-124: Added filtering for unsupported adjustment statuses in V2 API.

This change enhances the V2 API to handle compatibility with newer status types by:

  1. Calling the new translateStatus function to determine if an adjustment should be included
  2. Skipping adjustments that shouldn't be exposed in the V2 API

This maintains backward compatibility while allowing the internal system to use new status types.


128-128: Updated Status field to use translated value.

The code now uses the translated status from the translateStatus function rather than directly using the status string, ensuring consistent status representation in the API response.


141-151: Added translateStatus function to handle V2 API compatibility.

This new function ensures backward compatibility by:

  1. Taking a PaymentInitiationAdjustmentStatus as input
  2. Handling the new SCHEDULED_FOR_PROCESSING status which doesn't exist in V2
  3. Returning an appropriate status string and a boolean indicating whether to include the adjustment

This is a clean approach to maintain API compatibility while allowing the internal system to evolve with new status types.

internal/models/payment_initiation_adjusments_status.go (3)

22-22: Clean addition of new payment status constant.

The new constant, PAYMENT_INITIATION_ADJUSTMENT_STATUS_SCHEDULED_FOR_PROCESSING, correctly extends the existing enum type for payment initiation adjustment statuses.


43-44: Properly implemented String() method for the new status.

The method now correctly returns the string representation "SCHEDULED_FOR_PROCESSING" when the new status is encountered, maintaining consistency with the existing pattern.


69-70: Correctly updated status string parsing function.

The PaymentInitiationAdjustmentStatusFromString function properly handles the new "SCHEDULED_FOR_PROCESSING" string value and returns the corresponding enum value.

internal/api/services/payment_initiations_retry_test.go (1)

145-147: Correctly updated method signatures to remove the startDelay parameter.

The test cases have been properly updated to reflect the removal of the startDelay parameter from the CreateTransfer and CreatePayout methods, which aligns with the changes made in the workflow implementation.

internal/connectors/engine/workflow/create_transfer_test.go (1)

84-162: Comprehensive test for the new scheduling functionality.

This test thoroughly validates the scheduled payment implementation by:

  1. Setting up a payment initiation with a future scheduled time
  2. Verifying the creation of an adjustment with SCHEDULED_FOR_PROCESSING status
  3. Checking that all subsequent workflow steps execute correctly after the scheduled time

The test is well-structured and parallels the existing test case pattern while adding the necessary assertions for the new functionality.

Copy link
codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 69.62025% with 24 lines in your changes missing coverage. Please review.

Project coverage is 72.85%. Comparing base (09ec0e4) to head (b3e53ff).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...nternal/api/v2/handler_transfer_initiations_get.go 0.00% 13 Missing ⚠️
...ternal/api/v2/handler_transfer_initiations_list.go 55.55% 4 Missing ⚠️
...ternal/connectors/engine/workflow/create_payout.go 85.00% 2 Missing and 1 partial ⚠️
...rnal/connectors/engine/workflow/create_transfer.go 85.00% 2 Missing and 1 partial ⚠️
internal/connectors/engine/workers.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #374      +/-   ##
==========================================
- Coverage   72.87%   72.85%   -0.02%     
==========================================
  Files         531      531              
  Lines       25817    25873      +56     
==========================================
+ Hits        18813    18849      +36     
- Misses       5987     6006      +19     
- Partials     1017     1018       +1     

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

@paul-nicolas paul-nicolas marked this pull request as ready for review March 21, 2025 14:10
@paul-nicolas paul-nicolas requested a review from a team as a code owner March 21, 2025 14:10
@paul-nicolas paul-nicolas merged commit f93d58c into main Mar 24, 2025
7 of 9 checks passed
@paul-nicolas paul-nicolas deleted the fix/payment-initiations-fixes branch March 24, 2025 09:23
paul-nicolas added a commit that referenced this pull request Mar 24, 2025
* fix(*): payment initiations fixes

* add comments
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