1 import { StepResponse } from "@medusajs/framework/workflows-sdk"
2 import { createOrderCreditLinesWorkflow } from "@medusajs/medusa/core-flows"
3 import { refundCreditLinesWorkflow } from "../orders/workflows/refund-credit-lines"
4
5 ;(createOrderCreditLinesWorkflow.hooks as any).creditLinesCreated(
6 async (data, stepContext) => {
7 const { container, ...sharedContext } = stepContext
8 const { credit_lines: createdCreditLines } = data
9
10 const transaction = await refundCreditLinesWorkflow.run({
11 input: {
12 order_id: data.order_id,
13 credit_lines: createdCreditLines,
14 },
15 container,
16 context: { ...sharedContext },
17 throwOnError: true,
18 })
19
20 const { result } = transaction
21
22 return new StepResponse(result, stepContext.transactionId)
23 },
24 async (transactionId, stepContext) => {
25 if (!transactionId) {
26 return
27 }
28
29 const { container, ...sharedContext } = stepContext
30
31 await refundCreditLinesWorkflow(container).cancel({
32 transactionId,
33 container,
34 context: { ...sharedContext },
35 })
36 }
37 )