fix(core-flows): capture before order created (#9980)
What: When `autocapture` is enabled, the webhook is processed before the order was created. The payment processing workflows were merged into a single one FIXES: SUP-118, SUP-9 https://github.com/medusajs/medusa/issues/9998
This commit is contained in:
@@ -123,6 +123,7 @@ describe("LocalEventBusService", () => {
|
||||
data: { test: "1234" },
|
||||
metadata: { eventGroupId: "test" },
|
||||
name: "test-event",
|
||||
options: {},
|
||||
})
|
||||
|
||||
jest.clearAllMocks()
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "@medusajs/framework/types"
|
||||
import { AbstractEventBusModuleService } from "@medusajs/framework/utils"
|
||||
import { EventEmitter } from "events"
|
||||
import { setTimeout } from "timers/promises"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
type InjectedDependencies = {
|
||||
@@ -69,7 +70,10 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
)
|
||||
}
|
||||
|
||||
await this.groupOrEmitEvent(eventData)
|
||||
await this.groupOrEmitEvent({
|
||||
...eventData,
|
||||
options,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +90,13 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
await this.groupEvent(eventGroupId, eventData)
|
||||
} else {
|
||||
const { options, ...eventBody } = eventData
|
||||
this.eventEmitter_.emit(eventData.name, eventBody)
|
||||
|
||||
const options_ = options as { delay: number }
|
||||
const delay = options?.delay ? setTimeout : async () => {}
|
||||
|
||||
delay(options_?.delay).then(() =>
|
||||
this.eventEmitter_.emit(eventData.name, eventBody)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +118,12 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
for (const event of groupedEvents) {
|
||||
const { options, ...eventBody } = event
|
||||
|
||||
this.eventEmitter_.emit(event.name, eventBody)
|
||||
const options_ = options as { delay: number }
|
||||
const delay = options?.delay ? setTimeout : async () => {}
|
||||
|
||||
delay(options_?.delay).then(() =>
|
||||
this.eventEmitter_.emit(event.name, eventBody)
|
||||
)
|
||||
}
|
||||
|
||||
await this.clearGroupedEvents(eventGroupId)
|
||||
|
||||
Reference in New Issue
Block a user