fix(core-flows): emit payment.captured event on order payment session authorization - #16741
Conversation
🦋 Changeset detectedLatest commit: ad919d4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 83 packages
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 |
|
Thanks for the contribution! We need more information before reviewing this further. The PR author (vjymisal0) is an external contributor. The PR attempts to fix a missing payment.captured event emission in the order payment session authorization workflow, which corresponds to a valid open bug report. However, the PR body does not follow the required pull request template — the What, Why, How, and Testing sections are all absent. The body instead uses custom 'Problem' and 'Solution' headings and provides no information on how the change can be tested by a reviewer. Heads up: PR #16738 already references issue #16727 and was opened one day earlier (2026-09-05 vs 2026-09-06); if #16738 is merged first, this PR may be closed as a duplicate. Triggered by: new PR opened |
|
Thanks for the contribution! A few items need to be addressed before this can move forward: The PR template is now complete with all four required sections — the previous review's template compliance issue has been addressed. The workflow change itself is structurally correct: the new when block follows the existing pattern in the file, uses the correct emitEventStep call, and the condition (payment.captures?.length || payment.captured_at) accurately captures the cases where a capture has occurred. No security or performance concerns. The changeset is present and correctly formatted. One required change remains: the added test file imports PaymentEvents and PaymentSessionStatus from @medusajs/framework/utils but neither symbol appears in any test assertion. The two tests only verify that the workflow export exists and has the expected name — they do not exercise the behavioral change this PR introduces. Specifically, there are no tests verifying that the payment.captured event is emitted when payment.captures is non-empty or payment.captured_at is set, nor that the event is not emitted when neither condition holds. The unused imports suggest that event-behavior tests were intended but not finished.
Triggered by: new commit pushed |
|
Updated this one too. The unused import is gone, and the captured-payment event condition now has direct coverage for both capture paths ( |
|
Thanks for the contribution! Initial automated review looks good. The PR adds conditional emission of the payment.captured event inside the authorize-payment-session-for-order workflow, to cover the case where the payment provider marks a payment as captured immediately upon authorization. This addresses a real gap: event subscribers for PaymentEvents.CAPTURED were not notified in this flow. All previous review concerns have been addressed: - The PR template now contains all four required sections. - The unused PaymentSessionStatus import has been removed from the test file. - PaymentEvents is now used in test assertions. - Behavioral tests for paymentCapturedEventData cover both capture paths (captures array, captured_at) and the no-capture case (returns null for empty captures and for undefined payment). The implementation is correct. The when().then() block follows the existing pattern in the same file and in capture-payment.ts: the when predicate receives actual resolved payment values (correctly gating on whether captures or captured_at are present), while inside then(), calling paymentCapturedEventData with the WorkflowData proxy at composition time produces {eventName: PaymentEvents.CAPTURED, data: {id: payment.id}} — the same structure used in capture-payment.ts — which the workflow engine resolves at runtime. The changeset is present and correctly scoped to @medusajs/core-flows as a patch. Triggered by: new commit pushed |
What
Emit payment.captured event during order payment session authorization workflow (�uthorizePaymentSessionForOrderWorkflow) when payment is captured.
Why
When an order payment session is authorized and has existing captures or is marked captured (payment.captures or payment.captured_at), downstream event subscribers (notifications, invoicing, third-party integrations) expecting PaymentEvents.CAPTURED (payment.captured) are not notified.
How
Testing
Closes #16727