feat: Refund payment (#6610)

Essentially the same as #6601 but for refunds
This commit is contained in:
Oli Juhl
2024-03-07 12:34:36 +00:00
committed by GitHub
parent 7dee1a3fd3
commit e5cbe28d54
10 changed files with 246 additions and 37 deletions
@@ -1 +1,3 @@
export * from "./capture-payment"
export * from "./refund-payment"
@@ -0,0 +1,23 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IPaymentModuleService } from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type StepInput = {
payment_id: string
created_by?: string
amount?: number
}
export const refundPaymentStepId = "refund-payment-step"
export const refundPaymentStep = createStep(
refundPaymentStepId,
async (input: StepInput, { container }) => {
const paymentModule = container.resolve<IPaymentModuleService>(
ModuleRegistrationName.PAYMENT
)
const payment = await paymentModule.refundPayment(input)
return new StepResponse(payment)
}
)
@@ -1 +1,3 @@
export * from "./capture-payment"
export * from "./refund-payment"
@@ -0,0 +1,17 @@
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { refundPaymentStep } from "../steps/refund-payment"
export const refundPaymentWorkflowId = "refund-payment-workflow"
export const refundPaymentWorkflow = createWorkflow(
refundPaymentWorkflowId,
(
input: WorkflowData<{
payment_id: string
created_by?: string
amount?: number
}>
) => {
const payment = refundPaymentStep(input)
return payment
}
)