chore(order): link order and payment collection (#7334)

This commit is contained in:
Carlos R. L. Rodrigues
2024-05-14 17:37:27 -03:00
committed by GitHub
parent 7a8937fcba
commit 70fd355e46
12 changed files with 161 additions and 80 deletions

View File

@@ -5,6 +5,7 @@ import {
transform,
} from "@medusajs/workflows-sdk"
import { useRemoteQueryStep } from "../../../common"
import { linkOrderAndPaymentCollectionsStep } from "../../../order/steps"
import { authorizePaymentSessionStep } from "../../../payment/steps/authorize-payment-session"
import { createOrderFromCartStep, validateCartPaymentsStep } from "../steps"
import { reserveInventoryStep } from "../steps/reserve-inventory"
@@ -70,6 +71,19 @@ export const completeCartWorkflow = createWorkflow(
list: false,
}).config({ name: "final-cart" })
return createOrderFromCartStep({ cart: finalCart })
const order = createOrderFromCartStep({ cart: finalCart })
const linkOrderPaymentCollection = transform({ order, cart }, (data) => ({
links: [
{
order_id: data.order.id,
payment_collection_id: data.cart.payment_collection.id,
},
],
}))
linkOrderAndPaymentCollectionsStep(linkOrderPaymentCollection)
return order
}
)

View File

@@ -1,4 +1,5 @@
export * from "./create-orders"
export * from "./get-item-tax-lines"
export * from "./link-order-payment-collection"
export * from "./set-tax-lines-for-items"
export * from "./update-tax-lines"

View File

@@ -0,0 +1,42 @@
import { Modules } from "@medusajs/modules-sdk"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type StepInput = {
links: {
order_id: string
payment_collection_id: string
}[]
}
export const linkOrderAndPaymentCollectionsStepId =
"link-order-payment-collection"
export const linkOrderAndPaymentCollectionsStep = createStep(
linkOrderAndPaymentCollectionsStepId,
async (data: StepInput, { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const links = data.links.map((d) => ({
[Modules.ORDER]: { order_id: d.order_id },
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
}))
await remoteLink.create(links)
return new StepResponse(void 0, data)
},
async (data, { container }) => {
if (!data) {
return
}
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
const links = data.links.map((d) => ({
[Modules.ORDER]: { order_id: d.order_id },
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
}))
await remoteLink.dismiss(links)
}
)