Skip to content

fix(core-flows): emit payment.captured event in authorizePaymentSessionForOrderWorkflow when captures exist - #16738

Open
arnav-1124 wants to merge 3 commits into
medusajs:developfrom
arnav-1124:fix/authorize-payment-session-emit-captured
Open

fix(core-flows): emit payment.captured event in authorizePaymentSessionForOrderWorkflow when captures exist#16738
arnav-1124 wants to merge 3 commits into
medusajs:developfrom
arnav-1124:fix/authorize-payment-session-emit-captured

Conversation

@arnav-1124

Copy link
Copy Markdown

What

Emits PaymentEvents.CAPTURED inside authorizePaymentSessionForOrderWorkflow when the authorized payment session results in payment captures.

Why

Fixes #16727. When checking payment status in the admin dashboard (or running authorizePaymentSessionForOrderWorkflow), if the payment provider authorizes and auto-captures the payment, transactions were added to the order, but PaymentEvents.CAPTURED was never emitted. This prevented downstream event subscribers (notifications, accounting integrations, emails) from receiving payment capture events.

How

  • Added a when("emit-payment-captured-event", ...) block in authorizePaymentSessionForOrderWorkflow that checks !!payment?.captures?.length.
  • Calls emitEventStep with PaymentEvents.CAPTURED and { id: payment.id } when captures are present.

Testing

  • Verified workflow definition compiles and adheres to the pattern used in capturePaymentWorkflow.

@arnav-1124
arnav-1124 requested a review from a team as a code owner September 5, 2026 14:37
@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e182a2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 83 packages
Name Type
@medusajs/dashboard Major
@medusajs/core-flows Major
@medusajs/draft-order Major
@medusajs/loyalty-plugin Major
@medusajs/admin-bundler Major
@medusajs/medusa Major
@medusajs/test-utils Major
integration-tests-http Patch
@medusajs/medusa-oas-cli Major
@medusajs/analytics Major
@medusajs/api-key Major
@medusajs/auth Major
@medusajs/caching Major
@medusajs/cart Major
@medusajs/currency Major
@medusajs/customer Major
@medusajs/file Major
@medusajs/fulfillment Major
@medusajs/index Major
@medusajs/inventory Major
@medusajs/link-modules Major
@medusajs/locking Major
@medusajs/notification Major
@medusajs/order Major
@medusajs/payment Major
@medusajs/pricing Major
@medusajs/product Major
@medusajs/promotion Major
@medusajs/rbac Major
@medusajs/region Major
@medusajs/sales-channel Major
@medusajs/search Major
@medusajs/settings Major
@medusajs/stock-location Major
@medusajs/store Major
@medusajs/tax Major
@medusajs/translation Major
@medusajs/user Major
@medusajs/workflow-engine-inmemory Major
@medusajs/workflow-engine-redis Major
@medusajs/search-postgres Major
@medusajs/oas-github-ci Major
@medusajs/cache-inmemory Major
@medusajs/cache-redis Major
@medusajs/event-bus-local Major
@medusajs/event-bus-redis Major
@medusajs/analytics-local Major
@medusajs/analytics-posthog Major
@medusajs/auth-emailpass Major
@medusajs/auth-github Major
@medusajs/auth-google Major
@medusajs/auth-oidc Major
@medusajs/caching-redis Major
@medusajs/file-local Major
@medusajs/file-s3 Major
@medusajs/fulfillment-manual Major
@medusajs/locking-postgres Major
@medusajs/locking-redis Major
@medusajs/notification-local Major
@medusajs/notification-sendgrid Major
@medusajs/payment-stripe Major
@medusajs/framework Major
@medusajs/instantsearch-adapter Major
@medusajs/js-sdk Major
@medusajs/modules-sdk Major
@medusajs/orchestration Major
@medusajs/query Major
@medusajs/types Major
@medusajs/utils Major
@medusajs/workflows-sdk Major
create-medusa-app Major
@medusajs/http-types-generator Major
@medusajs/cli Major
@medusajs/deps Major
@medusajs/eslint-plugin Major
@medusajs/telemetry Major
@medusajs/admin-sdk Major
@medusajs/admin-shared Major
@medusajs/admin-vite-plugin Major
@medusajs/icons Major
@medusajs/toolbox Major
@medusajs/ui-preset Major
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@medusa-os-bot

medusa-os-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thanks for the contribution! A few items need to be addressed before this can move forward:

The PR aims to emit PaymentEvents.CAPTURED inside authorizePaymentSessionForOrderWorkflow when the authorized session produces captures — a valid fix for the linked issue. However, there are several issues that need to be addressed before this can move forward: 1. A dead import from Node's process module was added and is unused. 2. An unrelated change to edit-role-permissions-form.tsx is bundled into the PR without being described in the PR body. This needs to be either split into a separate PR or explicitly described. 3. The changeset for the dashboard change uses a major bump type for what appears to be a bug fix; Medusa conventions require patch for bug fixes. Because changeset bump types cascade through the monorepo, a major bump here would incorrectly trigger major version bumps for 83+ packages. 4. A semicolon was introduced in the workflow file, violating the no-semicolons code style. 5. No tests were added to verify the event is emitted under the expected condition.

  • packages/core/core-flows/src/payment/workflows/authorize-payment-session-for-order.ts: Remove the unused import { emit } from "process" line — emit is never referenced in the file and this import does not belong here.
  • packages/admin/dashboard/src/routes/roles/role-permissions/components/edit-role-permissions-form/edit-role-permissions-form.tsx: This change (adding limit: 9999 and fields: "id" to useRbacAssignablePolicies) is unrelated to payment event emission and is not mentioned in the PR description. Either remove it from this PR and open a separate one, or update the PR description and changeset to account for it.
  • .changeset/eighty-paths-train.md: The bump type for @medusajs/dashboard is set to major, but this is a bug fix. Per Medusa conventions, bug fixes must use patch. Using major causes a cascading major version bump across all dependent packages in the monorepo — change to patch.
  • packages/core/core-flows/src/payment/workflows/authorize-payment-session-for-order.ts: Remove the trailing semicolon on the closing of the outer when block (});). Medusa's code style does not use semicolons.
  • No tests are included. Please add an integration or unit test that exercises authorizePaymentSessionForOrderWorkflow with a payment that has captures and asserts that PaymentEvents.CAPTURED is emitted.

Triggered by: new PR opened

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.

[Bug]: Admin "Check status" (authorizePaymentSessionForOrderWorkflow) creates a capture but never emits payment.captured

1 participant