From 64c5019b3be66be3113a99eb6cc4f84f25aa808e Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 28 Oct 2025 11:09:24 +0200 Subject: [PATCH] chore: fixes to http and request types for payments (#13830) --- .../core/types/src/http/payment/admin/payloads.ts | 9 ++++----- .../core/types/src/http/payment/store/queries.ts | 3 ++- .../types/src/http/refund-reason/admin/queries.ts | 9 ++------- packages/core/types/src/http/refund-reason/common.ts | 12 ++++-------- .../payment-collections/[id]/mark-as-paid/route.ts | 6 ++++-- .../src/api/admin/payment-collections/route.ts | 8 +++++--- .../src/api/admin/payments/[id]/capture/route.ts | 6 ++++-- .../src/api/admin/payments/[id]/refund/route.ts | 6 ++++-- .../src/api/admin/refund-reasons/[id]/route.ts | 8 +++++--- .../src/api/admin/refund-reasons/middlewares.ts | 3 ++- .../medusa/src/api/admin/refund-reasons/route.ts | 6 ++++-- .../src/api/admin/refund-reasons/validators.ts | 8 +++++++- .../[id]/payment-sessions/route.ts | 5 ++++- .../src/api/store/payment-collections/route.ts | 5 ++++- 14 files changed, 55 insertions(+), 39 deletions(-) diff --git a/packages/core/types/src/http/payment/admin/payloads.ts b/packages/core/types/src/http/payment/admin/payloads.ts index 2a53d8a735..dd0cab0fe3 100644 --- a/packages/core/types/src/http/payment/admin/payloads.ts +++ b/packages/core/types/src/http/payment/admin/payloads.ts @@ -15,11 +15,11 @@ export interface AdminRefundPayment { /** * The ID of the refund's reason. */ - refund_reason_id?: string | null + refund_reason_id?: string /** * A note to attach to the refund. */ - note?: string | null + note?: string } export interface AdminCreatePaymentCollection { @@ -28,10 +28,9 @@ export interface AdminCreatePaymentCollection { */ order_id: string /** - * The payment collection's amount. If not specified, - * the order's total is used as the amount instead. + * The payment collection's amount. */ - amount?: number + amount: number } export interface AdminMarkPaymentCollectionAsPaid { diff --git a/packages/core/types/src/http/payment/store/queries.ts b/packages/core/types/src/http/payment/store/queries.ts index 4be032e09e..40ef6825d9 100644 --- a/packages/core/types/src/http/payment/store/queries.ts +++ b/packages/core/types/src/http/payment/store/queries.ts @@ -1,9 +1,10 @@ +import { FindParams } from "../../common" import { BasePaymentCollectionFilters, BasePaymentSessionFilters, } from "../common" -export interface StorePaymentProviderFilters { +export interface StorePaymentProviderFilters extends FindParams { /** * The ID of the region to retrieve its payment providers. */ diff --git a/packages/core/types/src/http/refund-reason/admin/queries.ts b/packages/core/types/src/http/refund-reason/admin/queries.ts index 9a3291dcf7..977f96df0e 100644 --- a/packages/core/types/src/http/refund-reason/admin/queries.ts +++ b/packages/core/types/src/http/refund-reason/admin/queries.ts @@ -1,14 +1,9 @@ -import { BaseFilterable, OperatorMap } from "../../../dal" +import { BaseFilterable } from "../../../dal" import { SelectParams } from "../../common" import { BaseRefundReasonListParams } from "../common" export interface AdminRefundReasonListParams extends BaseRefundReasonListParams, - BaseFilterable { - /** - * Apply filters on the refund reason's deletion date. - */ - deleted_at?: OperatorMap -} + BaseFilterable {} export interface AdminRefundReasonParams extends SelectParams {} diff --git a/packages/core/types/src/http/refund-reason/common.ts b/packages/core/types/src/http/refund-reason/common.ts index f34070487b..3e06e10115 100644 --- a/packages/core/types/src/http/refund-reason/common.ts +++ b/packages/core/types/src/http/refund-reason/common.ts @@ -47,14 +47,6 @@ export interface BaseRefundReasonListParams extends FindParams { * Filter by refund reason ID(s). */ id?: string | string[] - /** - * Filter by label(s). - */ - label?: string | OperatorMap - /** - * Filter by description(s). - */ - description?: string | OperatorMap /** * Filter by parent refund reason ID(s). */ @@ -67,4 +59,8 @@ export interface BaseRefundReasonListParams extends FindParams { * Filter by update date. */ updated_at?: OperatorMap + /** + * Apply filters on the refund reason's deletion date. + */ + deleted_at?: OperatorMap } diff --git a/packages/medusa/src/api/admin/payment-collections/[id]/mark-as-paid/route.ts b/packages/medusa/src/api/admin/payment-collections/[id]/mark-as-paid/route.ts index bf117ed2b3..1db682705c 100644 --- a/packages/medusa/src/api/admin/payment-collections/[id]/mark-as-paid/route.ts +++ b/packages/medusa/src/api/admin/payment-collections/[id]/mark-as-paid/route.ts @@ -5,10 +5,12 @@ import { MedusaResponse, refetchEntity, } from "@medusajs/framework/http" -import { AdminMarkPaymentCollectionPaidType } from "../../validators" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminMarkPaymentCollectionAsPaid, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/payment-collections/route.ts b/packages/medusa/src/api/admin/payment-collections/route.ts index 68c789a31f..dd4cd91ea4 100644 --- a/packages/medusa/src/api/admin/payment-collections/route.ts +++ b/packages/medusa/src/api/admin/payment-collections/route.ts @@ -5,14 +5,16 @@ import { MedusaResponse, refetchEntity, } from "@medusajs/framework/http" -import { AdminCreatePaymentCollectionType } from "./validators" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreatePaymentCollection, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { result } = await createOrderPaymentCollectionWorkflow(req.scope).run({ - input: req.body, + input: req.validatedBody, }) const paymentCollection = await refetchEntity({ diff --git a/packages/medusa/src/api/admin/payments/[id]/capture/route.ts b/packages/medusa/src/api/admin/payments/[id]/capture/route.ts index f1b97b6a0d..bb5ee067ed 100644 --- a/packages/medusa/src/api/admin/payments/[id]/capture/route.ts +++ b/packages/medusa/src/api/admin/payments/[id]/capture/route.ts @@ -4,11 +4,13 @@ import { MedusaResponse, } from "@medusajs/framework/http" import { refetchPayment } from "../../helpers" -import { AdminCreatePaymentCaptureType } from "../../validators" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCapturePayment, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/payments/[id]/refund/route.ts b/packages/medusa/src/api/admin/payments/[id]/refund/route.ts index 86845dfbdf..a81e77571a 100644 --- a/packages/medusa/src/api/admin/payments/[id]/refund/route.ts +++ b/packages/medusa/src/api/admin/payments/[id]/refund/route.ts @@ -4,11 +4,13 @@ import { MedusaResponse, } from "@medusajs/framework/http" import { refetchPayment } from "../../helpers" -import { AdminCreatePaymentRefundType } from "../../validators" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminRefundPayment, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/refund-reasons/[id]/route.ts b/packages/medusa/src/api/admin/refund-reasons/[id]/route.ts index 6629cbd4df..f108ed1b5d 100644 --- a/packages/medusa/src/api/admin/refund-reasons/[id]/route.ts +++ b/packages/medusa/src/api/admin/refund-reasons/[id]/route.ts @@ -8,10 +8,9 @@ import { MedusaResponse, refetchEntity, } from "@medusajs/framework/http" -import { AdminUpdatePaymentRefundReasonType } from "../validators" export const GET = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest, res: MedusaResponse ) => { const refund_reason = await refetchEntity({ @@ -25,7 +24,10 @@ export const GET = async ( } export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminUpdateRefundReason, + HttpTypes.AdminRefundReasonParams + >, res: MedusaResponse ) => { const { id } = req.params diff --git a/packages/medusa/src/api/admin/refund-reasons/middlewares.ts b/packages/medusa/src/api/admin/refund-reasons/middlewares.ts index e364b195b1..65435e6e1d 100644 --- a/packages/medusa/src/api/admin/refund-reasons/middlewares.ts +++ b/packages/medusa/src/api/admin/refund-reasons/middlewares.ts @@ -6,6 +6,7 @@ import { import * as queryConfig from "./query-config" import { AdminCreatePaymentRefundReason, + AdminGetRefundReasonParams, AdminGetRefundReasonsParams, AdminUpdatePaymentRefundReason, } from "./validators" @@ -38,7 +39,7 @@ export const adminRefundReasonsRoutesMiddlewares: MiddlewareRoute[] = [ middlewares: [ validateAndTransformBody(AdminUpdatePaymentRefundReason), validateAndTransformQuery( - AdminGetRefundReasonsParams, + AdminGetRefundReasonParams, queryConfig.retrieveTransformQueryConfig ), ], diff --git a/packages/medusa/src/api/admin/refund-reasons/route.ts b/packages/medusa/src/api/admin/refund-reasons/route.ts index 68e988841b..a1c66cf8cc 100644 --- a/packages/medusa/src/api/admin/refund-reasons/route.ts +++ b/packages/medusa/src/api/admin/refund-reasons/route.ts @@ -6,7 +6,6 @@ import { refetchEntity, } from "@medusajs/framework/http" import { - AdminCreateRefundReason, HttpTypes, PaginatedResponse, RefundReasonResponse, @@ -34,7 +33,10 @@ export const GET = async ( } export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.AdminCreateRefundReason, + HttpTypes.AdminRefundReasonParams + >, res: MedusaResponse ) => { const { diff --git a/packages/medusa/src/api/admin/refund-reasons/validators.ts b/packages/medusa/src/api/admin/refund-reasons/validators.ts index f549f9ec4f..fdead308c5 100644 --- a/packages/medusa/src/api/admin/refund-reasons/validators.ts +++ b/packages/medusa/src/api/admin/refund-reasons/validators.ts @@ -1,5 +1,5 @@ import { z } from "zod" -import { createFindParams, createOperatorMap } from "../../utils/validators" +import { createFindParams, createOperatorMap, createSelectParams } from "../../utils/validators" export type AdminCreatePaymentRefundReasonType = z.infer< typeof AdminCreatePaymentRefundReason @@ -41,3 +41,9 @@ export const AdminGetRefundReasonsParams = createFindParams({ export type AdminGetRefundReasonsParamsType = z.infer< typeof AdminGetRefundReasonsParams > + +export const AdminGetRefundReasonParams = createSelectParams() + +export type AdminGetRefundReasonParamsType = z.infer< + typeof AdminGetRefundReasonParams +> \ No newline at end of file diff --git a/packages/medusa/src/api/store/payment-collections/[id]/payment-sessions/route.ts b/packages/medusa/src/api/store/payment-collections/[id]/payment-sessions/route.ts index fb430b60a6..91b9bdf442 100644 --- a/packages/medusa/src/api/store/payment-collections/[id]/payment-sessions/route.ts +++ b/packages/medusa/src/api/store/payment-collections/[id]/payment-sessions/route.ts @@ -7,7 +7,10 @@ import { refetchPaymentCollection } from "../../helpers" import { HttpTypes } from "@medusajs/framework/types" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.StoreInitializePaymentSession, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const collectionId = req.params.id diff --git a/packages/medusa/src/api/store/payment-collections/route.ts b/packages/medusa/src/api/store/payment-collections/route.ts index a41fc2364a..089357357e 100644 --- a/packages/medusa/src/api/store/payment-collections/route.ts +++ b/packages/medusa/src/api/store/payment-collections/route.ts @@ -11,7 +11,10 @@ import { import { Modules } from "@medusajs/utils" export const POST = async ( - req: AuthenticatedMedusaRequest, + req: AuthenticatedMedusaRequest< + HttpTypes.StoreCreatePaymentCollection, + HttpTypes.SelectParams + >, res: MedusaResponse ) => { const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)