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
@@ -0,0 +1,42 @@
import { refundPaymentWorkflow } from "@medusajs/core-flows"
import { Modules } from "@medusajs/modules-sdk"
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../../types/routing"
import { defaultAdminPaymentFields } from "../../query-config"
export const POST = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const { id } = req.params
const { errors } = await refundPaymentWorkflow(req.scope).run({
input: {
payment_id: id,
created_by: req.auth?.actor_id,
},
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
const query = remoteQueryObjectFromString({
entryPoint: Modules.PAYMENT,
variables: { id },
fields: defaultAdminPaymentFields,
})
const [payment] = await remoteQuery(query)
res.status(200).json({ payment })
}
@@ -35,10 +35,9 @@ export const adminPaymentRoutesMiddlewares: MiddlewareRoute[] = [
matcher: "/admin/payments/:id/capture",
middlewares: [],
},
// TODO: Add in follow-up PR
// {
// method: ["POST"],
// matcher: "/admin/payments/:id/refund",
// middlewares: [],
// },
{
method: ["POST"],
matcher: "/admin/payments/:id/refund",
middlewares: [],
},
]