|
1
|
import { StepResponse } from "@medusajs/framework/workflows-sdk" |
|
2
|
import { completeCartWorkflow } from "@medusajs/medusa/core-flows" |
|
3
|
import { confirmCartCreditLinesWorkflow } from "../carts/workflows/confirm-cart-credit-lines" |
|
4
|
|
|
5
|
;(completeCartWorkflow.hooks as any).beforePaymentAuthorization( |
|
6
|
async (data, stepContext) => { |
|
7
|
const { container, ...sharedContext } = stepContext |
|
8
|
const { |
|
9
|
input: { id: cart_id }, |
|
10
|
} = data as { input: { id: string } } |
|
11
|
|
|
12
|
const transaction = await confirmCartCreditLinesWorkflow.run({ |
|
13
|
input: { cart_id }, |
|
14
|
container, |
|
15
|
context: { ...sharedContext, preventReleaseEvents: true }, |
|
16
|
}) |
|
17
|
|
|
18
|
const { result } = transaction |
|
19
|
|
|
20
|
return new StepResponse(result, stepContext.transactionId) |
|
21
|
}, |
|
22
|
async (transactionId, stepContext) => { |
|
23
|
if (!transactionId) { |
|
24
|
return |
|
25
|
} |
|
26
|
|
|
27
|
const { container, ...sharedContext } = stepContext |
|
28
|
|
|
29
|
await confirmCartCreditLinesWorkflow(container).cancel({ |
|
30
|
transactionId, |
|
31
|
container, |
|
32
|
context: { ...sharedContext }, |
|
33
|
}) |
|
34
|
} |
|
35
|
) |