feat: Refund payment (#6610)
Essentially the same as #6601 but for refunds
This commit is contained in:
@@ -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: [],
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user