feat(dashboard,core-flows,js-sdk,types): ability to mark payment as paid (#8679)

* feat(core-flows): create or update payment collections in RMA flows

* chore: change ui to pick payment link from unpaid payment collection

* Apply suggestions from code review

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* chore: fix mathbn

* feat(dashboard,core-flows,js-sdk,types): ability to mark payment as paid

* chore: add captured bt

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2024-08-20 22:58:28 +02:00
committed by GitHub
co-authored by Carlos R. L. Rodrigues
parent 99eca64c20
commit 8bd284779e
12 changed files with 273 additions and 6 deletions
@@ -0,0 +1,32 @@
import { markPaymentCollectionAsPaid } from "@medusajs/core-flows"
import { HttpTypes } from "@medusajs/types"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../../types/routing"
import { refetchEntity } from "../../../../utils/refetch-entity"
import { AdminMarkPaymentCollectionPaidType } from "../../validators"
export const POST = async (
req: AuthenticatedMedusaRequest<AdminMarkPaymentCollectionPaidType>,
res: MedusaResponse<HttpTypes.AdminPaymentCollectionResponse>
) => {
const { id } = req.params
await markPaymentCollectionAsPaid(req.scope).run({
input: {
...req.body,
payment_collection_id: id,
captured_by: req.auth_context.actor_id,
},
})
const paymentCollection = await refetchEntity(
"payment_collection",
id,
req.scope,
req.remoteQueryConfig.fields
)
res.status(200).json({ payment_collection: paymentCollection })
}
@@ -5,6 +5,7 @@ import * as queryConfig from "./query-config"
import {
AdminCreatePaymentCollection,
AdminGetPaymentCollectionParams,
AdminMarkPaymentCollectionPaid,
} from "./validators"
export const adminPaymentCollectionsMiddlewares: MiddlewareRoute[] = [
@@ -19,6 +20,17 @@ export const adminPaymentCollectionsMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["POST"],
matcher: "/admin/payment-collections/:id/mark-as-paid",
middlewares: [
validateAndTransformBody(AdminMarkPaymentCollectionPaid),
validateAndTransformQuery(
AdminGetPaymentCollectionParams,
queryConfig.retrievePaymentCollectionTransformQueryConfig
),
],
},
{
method: ["DELETE"],
matcher: "/admin/payment-collections/:id",
@@ -3,7 +3,11 @@ export const defaultPaymentCollectionFields = [
"currency_code",
"amount",
"status",
"authorized_amount",
"captured_amount",
"refunded_amount",
"*payment_sessions",
"*payments",
]
export const retrievePaymentCollectionTransformQueryConfig = {
@@ -15,3 +15,12 @@ export const AdminCreatePaymentCollection = z
amount: z.number(),
})
.strict()
export type AdminMarkPaymentCollectionPaidType = z.infer<
typeof AdminMarkPaymentCollectionPaid
>
export const AdminMarkPaymentCollectionPaid = z
.object({
order_id: z.string(),
})
.strict()