Skip to content

Conversation

martijnvdbrug
Copy link
Collaborator

@martijnvdbrug martijnvdbrug commented Jun 20, 2025

Description

Migrated the Mollie plugin from using the Orders API to the Payments API, because the orders API is deprecated. See the Mollie docs for more info.

Breaking changes

  • Plugin consumers should install @mollie/api-client@4.3.3

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Summary by CodeRabbit

  • New Features

    • Added support for specifying immediate or manual capture and locale during Mollie payment intent creation.
    • Enhanced test coverage for manual capture payment flows and locale handling.
  • Bug Fixes

    • Improved alignment with Mollie's payment API, ensuring correct usage of payment IDs and resource paths.
    • Corrected refund and payment settlement logic to use Mollie payments instead of orders.
  • Documentation

    • Updated setup and usage instructions for Mollie integration, clarifying capture options and API changes.
  • Refactor

    • Centralized and streamlined mock data for Mollie tests.
    • Simplified and improved payment metadata typing and helper functions.
    • Shifted integration logic from Mollie orders to Mollie payments for improved accuracy and maintainability.
  • Chores

    • Updated Mollie API client dependency to version 4.x.
    • Removed unused code and improved import organization.

Copy link

vercel bot commented Jun 20, 2025

@martijnvdbrug is attempting to deploy a commit to the Vendure Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

Walkthrough

The codebase has been refactored to migrate the Mollie payment integration from using Mollie's Orders API to the Payments API. All relevant logic, type definitions, helpers, and test fixtures have been updated accordingly. The Mollie API client dependency has been upgraded to v4, and tests and documentation have been revised to reflect these changes.

Changes

Files / Groups Change Summary
src/mollie/mollie.service.ts, src/mollie/mollie.handler.ts, src/mollie/mollie.helpers.ts, src/mollie/api-extensions.ts, src/mollie/types.ts Refactored all Mollie integration logic to use the Payments API instead of the Orders API. Updated types, helper functions, and handler logic. Introduced new metadata interfaces and removed order-specific logic. Added/updated GraphQL fields for payment intent input. Removed deprecated or unnecessary functions.
src/mollie/mollie.controller.ts Changed webhook handler to use paymentId instead of orderId for status updates, aligning with the Payments API.
src/mollie/index.ts Updated exports: removed getLocale export, reordered exports for clarity.
src/mollie/mollie.plugin.ts Corrected import paths, reordered API extension imports, and updated documentation to reflect the move to the Payments API and new plugin setup steps.
e2e/mollie-payment.e2e-spec.ts, e2e/fixtures/mollie-mock-data.ts, e2e/mollie-dev-server.ts Updated and centralized test fixtures to use the Payments API. Refactored tests to mock and assert against payment endpoints and payloads. Improved coverage for manual capture and pay-later flows.
e2e/stripe-payment.e2e-spec.ts Minor refactor: made the Stripe requestOptions test synchronous (no functional change).
package.json Upgraded @mollie/api-client peer and dev dependency to v4.x.
src/stripe/metadata-sanitize.ts Minor refactor to simplify string length check logic (no functional change).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant VendureServer
    participant MollieAPI

    Client->>VendureServer: createMolliePaymentIntent(input)
    VendureServer->>MollieAPI: Create Payment (Payments API)
    MollieAPI-->>VendureServer: Payment Created (paymentId, status, etc.)
    VendureServer-->>Client: Payment Intent Result (redirect URL, paymentId)

    MollieAPI-)VendureServer: Webhook (paymentId, status update)
    VendureServer->>VendureServer: handleMollieStatusUpdate(paymentId)
    VendureServer->>MollieAPI: Fetch Payment Details
    MollieAPI-->>VendureServer: Payment Details (status, metadata)
    VendureServer->>VendureServer: Update Order/Payment State
Loading

Assessment against linked issues

Objective Addressed Explanation
Refactor Mollie integration to use Payments API instead of Orders API (#2921)
Remove all order-specific logic and types, update helpers and handlers for Payments API (#2921)
Update tests and fixtures to use Payments API endpoints and payloads (#2921)
Upgrade @mollie/api-client to v4 and update code for breaking changes (#3087)
Remove deprecated payment methods and ensure compatibility with new client (#3087)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found. All modifications are directly related to the objectives of migrating to the Mollie Payments API and upgrading the Mollie client to v4.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-20T12_05_16_744Z-debug-0.log


📜 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 60714ad and 899246e.

📒 Files selected for processing (1)
  • packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts (23 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit tests (20.x)
  • GitHub Check: unit tests (22.x)
  • GitHub Check: publish_install (ubuntu-latest, 22.x)
  • GitHub Check: publish_install (ubuntu-latest, 20.x)
✨ 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.
    • 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? Create a ticket on our support page 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 docstrings to generate docstrings for this 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.

'and you need to manually settle payments to get paid.',
},
],
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Autocapture is now handled by Mollie, and we can pass it in via the createMolliePaymentIntent mutation.

@dlhck
Copy link
Collaborator

dlhck commented Jun 20, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 20, 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.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/payments-plugin/src/mollie/mollie.plugin.ts (1)

82-82: Documentation contradicts the API migration.

The comment states "This plugin uses the Order API from Mollie, not the Payments API" but this PR migrates to the Payments API. This documentation needs to be updated.

- * This plugin uses the Order API from Mollie, not the Payments API.
+ * This plugin uses the Payments API from Mollie.
🧹 Nitpick comments (3)
packages/payments-plugin/e2e/mollie-dev-server.ts (2)

102-107: Locale parameter addition aligns with PR objectives.

The explicit locale specification ('nl_NL') correctly implements the migration away from locale guessing based on order country, as mentioned in the PR description.

Consider adding a comment explaining why immediateCapture is commented out:

+            // immediateCapture: true, // TODO: Enable for auto-capture testing
-            // immediateCapture: true,

111-126: Enhanced test scenario for payment intent handling.

The additional test logic with a second payment intent and delay provides better coverage for the payment-based workflow.

Consider adding a comment explaining the test scenario purpose:

+    // Test scenario: Create multiple payment intents for the same order to verify payment handling
     // Add another item to the order
packages/payments-plugin/src/mollie/mollie.service.ts (1)

208-213: Consider enhancing error message for missing checkout URL.

The error message could be more descriptive to help with debugging.

 const molliePayment = await mollieClient.payments.create(paymentInput);
 Logger.info(`Created Mollie payment ${String(molliePayment.id)} for order ${order.code}`, loggerCtx);
 const url = molliePayment.getCheckouturl("");
 if (!url) {
-    throw Error('Unable to getCheckouturl("") from Mollie payment');
+    throw Error(`Unable to getCheckouturl("") from Mollie payment ${molliePayment.id} for order ${order.code}. Payment status: ${molliePayment.status}`);
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bcc3335 and 60714ad.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (14)
  • packages/payments-plugin/e2e/fixtures/mollie-mock-data.ts (1 hunks)
  • packages/payments-plugin/e2e/mollie-dev-server.ts (2 hunks)
  • packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts (24 hunks)
  • packages/payments-plugin/e2e/stripe-payment.e2e-spec.ts (1 hunks)
  • packages/payments-plugin/package.json (2 hunks)
  • packages/payments-plugin/src/mollie/api-extensions.ts (3 hunks)
  • packages/payments-plugin/src/mollie/index.ts (1 hunks)
  • packages/payments-plugin/src/mollie/mollie.controller.ts (2 hunks)
  • packages/payments-plugin/src/mollie/mollie.handler.ts (3 hunks)
  • packages/payments-plugin/src/mollie/mollie.helpers.ts (4 hunks)
  • packages/payments-plugin/src/mollie/mollie.plugin.ts (5 hunks)
  • packages/payments-plugin/src/mollie/mollie.service.ts (10 hunks)
  • packages/payments-plugin/src/mollie/types.ts (1 hunks)
  • packages/payments-plugin/src/stripe/metadata-sanitize.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts

[error] 339-339: Unsafe usage of optional chaining.

If it short-circuits with 'undefined' the evaluation will throw TypeError here:

(lint/correctness/noUnsafeOptionalChaining)

🔇 Additional comments (34)
packages/payments-plugin/src/stripe/metadata-sanitize.ts (1)

23-23: Remove redundant type assertion
The preceding typeof metadata[keyName] !== 'string' guard already narrows the value to a string, so accessing .length directly is safe and the explicit cast can be dropped to simplify the expression.

packages/payments-plugin/e2e/stripe-payment.e2e-spec.ts (1)

255-255: Verify if this change is intentionally part of the Mollie migration PR.

This change converts the requestOptions function from async to synchronous, which is technically correct since it doesn't perform any async operations. However, this appears unrelated to the Mollie API migration described in the PR objectives.

Likely an incorrect or invalid review comment.

packages/payments-plugin/src/mollie/types.ts (1)

1-10: Well-structured interface for the payment-centric approach.

The MolliePaymentMetadata interface appropriately reflects the migration from Mollie orders to payments. The type definitions are clear and the status field correctly represents payment states.

packages/payments-plugin/package.json (2)

31-31: Dependency upgrade aligns with PR objectives.

The update to Mollie API client v4.x correctly implements the breaking change mentioned in the PR description, requiring plugin consumers to install @mollie/api-client@4.3.3.


50-50: Dev dependency version is appropriate.

The specific version ^4.3.3 provides good compatibility while allowing patch updates.

packages/payments-plugin/src/mollie/mollie.controller.ts (2)

2-2: Import reordering is cosmetic.

The import statement was reordered without functional changes.


32-32: Correct migration from orderId to paymentId.

This change properly reflects the shift from Mollie orders to payments API. The webhook now correctly passes the payment ID to the service layer.

packages/payments-plugin/e2e/mollie-dev-server.ts (1)

19-19: Clean import simplification.

Removing unused coupon creation helpers improves code clarity.

packages/payments-plugin/e2e/fixtures/mollie-mock-data.ts (1)

1-81: LGTM! Well-structured mock data for comprehensive testing.

The mock data file provides realistic and comprehensive test fixtures that properly mirror Mollie's API response structure, including HAL-formatted links and proper data types. This centralized approach improves test maintainability.

packages/payments-plugin/src/mollie/api-extensions.ts (2)

26-37: LGTM! Well-documented schema extensions for enhanced payment control.

The new immediateCapture and locale fields provide important functionality for the Payments API migration. The documentation clearly explains the 28-day expiration for manual capture and provides helpful links to Mollie's documentation.


57-57: Clean template literal formatting improvement.

The formatting change to use template literals for schema extensions improves code readability.

Also applies to: 88-88

packages/payments-plugin/src/mollie/index.ts (1)

1-3: Clean export restructuring aligns with API migration.

The reordering of exports and removal of getLocale export correctly reflects the migration away from automatic locale detection to explicit locale specification in the new API.

packages/payments-plugin/src/mollie/mollie.plugin.ts (5)

1-1: Fixed import path removes erroneous path segment.

The import path correction properly removes the incorrect src segment from the ListParameters import.


11-11: Clean import order improvement.

Swapping the order to import admin extensions before shop extensions provides a more logical organization.


107-110: Setup instructions properly updated for the new API.

The removal of the database migration step and renumbering of setup instructions correctly reflects the migration to the Payments API.


121-125: Enhanced mutation example with new optional parameters.

The expanded GraphQL mutation example properly documents the new locale and immediateCapture parameters with helpful comments explaining their optional nature.


173-181: Improved pay-later payment documentation.

The clarified explanation of immediate vs manual capture, including the 28-day expiration warning and link to Mollie documentation, provides valuable guidance for developers.

packages/payments-plugin/src/mollie/mollie.helpers.ts (4)

1-3: Import changes correctly reflect migration to Payments API.

The updated imports properly shift from order-related types to payment-specific types, maintaining compatibility with global types like Amount and Address.


10-25: Address mapping function properly updated for Payments API context.

The function logic remains correct while the return type annotation and documentation accurately reflect the migration to payment-specific types.


28-79: Excellent refactoring to payment lines with proper negative price handling.

The function rename and property changes correctly align with the Payments API. The addition of type: 'store_credit' for negative unit prices (surcharges and already paid amounts) is a smart solution to ensure Mollie accepts negative values. The consistent use of description instead of name follows the payment API schema.


81-106: Currency and tax calculation utilities correctly unchanged.

These utility functions handle mathematical operations independent of the API context, so keeping them unchanged is appropriate and maintains consistency in amount handling across the migration.

packages/payments-plugin/src/mollie/mollie.handler.ts (3)

88-109: Well-implemented capture polling with retry logic.

The implementation correctly handles asynchronous capture operations with a reasonable retry strategy (10 attempts × 500ms = 5 seconds total). The error handling differentiates between failed captures and timeouts, providing clear error messages.


52-77: Correct implementation of payment creation with new metadata structure.

The method properly validates the payment status and uses the new MolliePaymentMetadata type with the correct paymentId field instead of orderId.


114-124: Proper migration to Payments API for refunds.

The refund logic correctly uses the Payments API endpoints and maintains proper error handling.

packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts (4)

10-10: Good refactoring to centralize mock data.

Moving mock data to a dedicated fixture file and using it consistently throughout tests improves maintainability and reduces duplication.

Also applies to: 34-34, 80-80


223-244: Well-structured test validations for payment request.

The test properly validates all critical fields of the Mollie payment request including description, redirectUrl, locale, and captureMode. The assertion that default captureMode is 'automatic' aligns with the expected behavior.


466-486: Good test coverage for duplicate payment scenario.

The test properly validates error handling when an order is paid multiple times with different transaction IDs. The error message includes both order code and payment ID which aids in debugging.


552-645: Comprehensive test coverage for manual capture flow.

The new test suite thoroughly covers the manual capture functionality including:

  • Creating payment intent with immediateCapture: false
  • Handling authorized payments
  • Settlement via mutation with proper capture API mocking

This aligns well with the PR objective of supporting pay-later payment methods.

packages/payments-plugin/src/mollie/mollie.service.ts (6)

2-7: Proper type updates for Payments API migration.

The import and type changes correctly reflect the migration from Orders API to Payments API, including the new MolliePaymentMetadata type and updated OrderStatusInput interface.

Also applies to: 40-42, 44-47


94-105: Good addition of payment method eligibility check.

The eligibility check prevents creating payment intents with ineligible payment methods, providing better error handling upfront.


240-252: Excellent handling of language context preservation.

The code properly extracts and preserves the original languageCode from payment metadata, ensuring the correct language context is maintained throughout the order processing flow.


275-295: Comprehensive error handling for payment edge cases.

The implementation properly handles duplicate payments and payments for cancelled orders with clear error messages that include relevant IDs for debugging.


350-389: Well-structured payment metadata handling.

The addPayment method properly constructs and stores comprehensive Mollie payment metadata, which will be useful for debugging and payment tracking.


469-492: Efficient order fetching with proper relation loading.

The getOrder method properly handles both explicit order ID and active order scenarios while loading all necessary relations upfront, preventing N+1 query issues.

Copy link

vercel bot commented Jun 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Jun 20, 2025 0:06am

@martijnvdbrug martijnvdbrug requested a review from dlhck June 20, 2025 12:05
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
9.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@casperiv0 casperiv0 left a comment

Choose a reason for hiding this comment

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

Good stuff!

@michaelbromley michaelbromley merged commit d0db5cb into vendure-ecommerce:minor Jun 20, 2025
35 of 37 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2025
@michaelbromley
Copy link
Member

Thank you @martijnvdbrug 🙏

@martijnvdbrug martijnvdbrug deleted the feat/mollie-payments-api branch June 20, 2025 16:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants