Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-comics-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/core-flows": patch
---

fix(core-flows): process payment capture condition
25 changes: 14 additions & 11 deletions packages/core/core-flows/src/payment/workflows/process-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { WebhookActionResult } from "@medusajs/types"
import { PaymentActions } from "@medusajs/utils"
import { createWorkflow, when } from "@medusajs/workflows-sdk"
import { completeCartWorkflow } from "../../cart/workflows/complete-cart"
import { useQueryGraphStep } from "../../common"
import { authorizePaymentSessionStep } from "../steps"
import { capturePaymentWorkflow } from "./capture-payment"
import { useQueryGraphStep } from "../../common"

interface ProcessPaymentWorkflowInput extends WebhookActionResult {}

Expand Down Expand Up @@ -53,7 +53,7 @@ export const processPaymentWorkflow = createWorkflow(
})
})

when({ input }, ({ input }) => {
when({ input, paymentData }, ({ input, paymentData }) => {
return (
input.action === PaymentActions.SUCCESSFUL && !!paymentData.data.length
)
Expand All @@ -66,15 +66,18 @@ export const processPaymentWorkflow = createWorkflow(
})
})

when({ input }, ({ input }) => {
// Authorize payment session if no Cart is linked to the payment
// When associated with a Cart, the complete cart workflow will handle the authorization
return (
!cartPaymentCollection.data.length &&
input.action === PaymentActions.AUTHORIZED &&
!!input.data?.session_id
)
}).then(() => {
when(
{ input, cartPaymentCollection },
({ input, cartPaymentCollection }) => {
Copy link
Member

Choose a reason for hiding this comment

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

It is also like that line 42, so probably it 👍

// Authorize payment session if no Cart is linked to the payment
// When associated with a Cart, the complete cart workflow will handle the authorization
return (
!cartPaymentCollection.data.length &&
input.action === PaymentActions.AUTHORIZED &&
!!input.data?.session_id
)
}
).then(() => {
authorizePaymentSessionStep({
id: input.data!.session_id,
context: {},
Expand Down
Loading