The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
fix(core): report split order payment status on admin and store order routes (#1458)
Viktor Holik9a87390fac3a
diff --git a/integration-tests/helpers/split-order-checkout.ts b/integration-tests/helpers/split-order-checkout.tsnew file mode 100644index 000000000..dfa1f453e--- /dev/null+++ b/integration-tests/helpers/split-order-checkout.ts@@ -0,0 +1,243 @@+import { MedusaContainer } from "@medusajs/framework/types"+import { ContainerRegistrationKeys } from "@medusajs/framework/utils"+import { MercurModules, SellerStatus } from "@mercurjs/types"++import { createVendorProduct } from "./create-product"+import { createSellerUser } from "./create-seller-user"++let prerequisiteCounter = 0++export const approveSeller = async (+ container: MedusaContainer,+ sellerId: string+) => {+ const sellerModule: any = container.resolve(MercurModules.SELLER)+ await sellerModule.updateSellers({+ id: sellerId,+ status: SellerStatus.OPEN,+ })+}++export const seedSellerOfferWithShipping = async (opts: {+ container: MedusaContainer+ api: any+ salesChannelId: string+ email: string+ name: string+ stocked: number+ offerPrice: number+}) => {+ const { container, api, salesChannelId } = opts++ const result = await createSellerUser(container, {+ email: opts.email,+ name: opts.name,+ })+ await approveSeller(container, (result.seller as any).id)+ const headers = result.headers+ const tag = `_${opts.name}_${Date.now()}_${++prerequisiteCounter}`++ const stockLocation = (+ await api.post(`/vendor/stock-locations`, { name: `Warehouse${tag}` }, headers)+ ).data.stock_location++ await api.post(+ `/vendor/stock-locations/${stockLocation.id}/fulfillment-sets`,+ { name: `FS${tag}`, type: "shipping" },+ headers+ )+ const fulfillmentSet = (+ await api.get(+ `/vendor/stock-locations/${stockLocation.id}?fields=*fulfillment_sets`,+ headers+ )+ ).data.stock_location.fulfillment_sets[0]+ const serviceZone = (+ await api.post(+ `/vendor/fulfillment-sets/${fulfillmentSet.id}/service-zones`,+ {+ name: `SZ${tag}`,+ geo_zones: [{ type: "country", country_code: "us" }],+ },+ headers+ )+ ).data.fulfillment_set.service_zones.find((z: any) => z.name === `SZ${tag}`)+ const shippingProfile = (+ await api.post(+ `/vendor/shipping-profiles`,+ { name: `SP${tag}`, type: "default" },+ headers+ )+ ).data.shipping_profile++ await api.post(+ `/vendor/stock-locations/${stockLocation.id}/fulfillment-providers`,+ { add: ["manual_manual"] },+ headers+ )+ await api.post(+ `/vendor/stock-locations/${stockLocation.id}/sales-channels`,+ { add: [salesChannelId] },+ headers+ )+ await api.post(+ `/vendor/shipping-options`,+ {+ name: `Ship${tag}`,+ service_zone_id: serviceZone.id,+ shipping_profile_id: shippingProfile.id,+ provider_id: "manual_manual",+ price_type: "flat",+ type: {+ label: "Standard",+ description: "Standard",+ code: "standard",+ },+ prices: [{ currency_code: "usd", amount: 500 }],+ rules: [+ {+ attribute: "enabled_in_store",+ value: "true",+ operator: "eq",+ },+ ],+ },+ headers+ )++ const product = await createVendorProduct(api, headers, {+ title: `Prod${tag}`,+ sku: `V${tag}`,+ })++ await api.post(+ `/vendor/sales-channels/${salesChannelId}/products`,+ { add: [product.id] },+ headers+ )++ const offer = (+ await api.post(+ `/vendor/offers`,+ {+ sku: `OF${tag}`,+ variant_id: product.variants[0].id,+ shipping_profile_id: shippingProfile.id,+ inventory_items: [+ {+ title: `Inv${tag}`,+ required_quantity: 1,+ stock_levels: [+ {+ location_id: stockLocation.id,+ stocked_quantity: opts.stocked,+ },+ ],+ },+ ],+ prices: [{ amount: opts.offerPrice, currency_code: "usd" }],+ },+ headers+ )+ ).data.offer++ return { sellerId: result.seller.id, headers, offer }+}++export const completeSplitOrderCheckout = async (opts: {+ container: MedusaContainer+ api: any+ storeHeaders: any+ regionId: string+ salesChannelId: string+ offerId: string+ /**+ * Must be the authenticated customer's own email. Medusa's+ * findOrCreateCustomerStep treats a customer without `has_account` as a+ * guest, so a different email on the cart moves it to a freshly created+ * guest customer — and the resulting orders stop belonging to the buyer.+ */+ email: string+}) => {+ const { container, api, storeHeaders } = opts++ const cart = (+ await api.post(+ `/store/carts`,+ {+ region_id: opts.regionId,+ sales_channel_id: opts.salesChannelId,+ currency_code: "usd",+ },+ storeHeaders+ )+ ).data.cart++ await api.post(+ `/store/carts/${cart.id}/line-items`,+ { offer_id: opts.offerId, quantity: 1 },+ storeHeaders+ )++ const address = {+ first_name: "Buyer",+ last_name: "Test",+ address_1: "123 Main St",+ city: "New York",+ country_code: "us",+ postal_code: "10001",+ }++ await api.post(+ `/store/carts/${cart.id}`,+ {+ email: opts.email,+ shipping_address: address,+ billing_address: address,+ },+ storeHeaders+ )++ const shippingOptionsResp = await api.get(+ `/store/shipping-options?cart_id=${cart.id}`,+ storeHeaders+ )+ const allOptions = Object.values(+ shippingOptionsResp.data.shipping_options as Record<string, any[]>+ ).flat()+ for (const opt of allOptions) {+ await api.post(+ `/store/carts/${cart.id}/shipping-methods`,+ { option_id: opt.id },+ storeHeaders+ )+ }++ const paymentCollection = (+ await api.post(+ `/store/payment-collections`,+ { cart_id: cart.id },+ storeHeaders+ )+ ).data.payment_collection+ await api.post(+ `/store/payment-collections/${paymentCollection.id}/payment-sessions`,+ { provider_id: "pp_system_default" },+ storeHeaders+ )++ const completeResp = await api.post(+ `/store/carts/${cart.id}/complete`,+ {},+ storeHeaders+ )+ const orderGroupId = completeResp.data.order_group.id+ const query = container.resolve(ContainerRegistrationKeys.QUERY)+ const { data: orderGroup } = await query.graph({+ entity: "order_group",+ filters: { id: orderGroupId },+ fields: ["id", "orders.id"],+ })++ return (orderGroup[0] as any).orders[0]+}diff --git a/integration-tests/http/order/admin/order-payment-status.spec.ts b/integration-tests/http/order/admin/order-payment-status.spec.tsnew file mode 100644index 000000000..9faf2e8cf--- /dev/null+++ b/integration-tests/http/order/admin/order-payment-status.spec.ts@@ -0,0 +1,142 @@+import { medusaIntegrationTestRunner } from "@medusajs/test-utils"+import {+ IRegionModuleService,+ ISalesChannelModuleService,+ MedusaContainer,+} from "@medusajs/framework/types"+import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"+import { createCustomerUser } from "../../../helpers/create-customer-user"+import {+ adminHeaders,+ createAdminUser,+ generatePublishableKey,+ generateStoreHeaders,+} from "../../../helpers/create-admin-user"+import {+ completeSplitOrderCheckout,+ seedSellerOfferWithShipping,+} from "../../../helpers/split-order-checkout"++jest.setTimeout(120000)++/**+ * Issue #1419 — `/admin/orders(/:id)` are stock Medusa routes, so the split+ * order payment status fix from #1387 did not reach them: the shared payment+ * collection lives on the cart, never on the order link, so Medusa's+ * aggregation falls back to `not_paid`.+ */+medusaIntegrationTestRunner({+ testSuite: ({ getContainer, api, dbConnection }) => {+ describe("Admin - Order payment status (cart payment collection)", () => {+ let appContainer: MedusaContainer+ let sellerSeed: any+ let storeHeaders: any+ let customerEmail: string+ let region: any+ let salesChannel: any++ beforeAll(async () => {+ appContainer = getContainer()+ })++ beforeEach(async () => {+ await createAdminUser(dbConnection, adminHeaders, appContainer)++ const customerResult = await createCustomerUser(appContainer, {+ email: "[email protected]",+ first_name: "Payment",+ last_name: "Buyer",+ })+ customerEmail = customerResult.customer.email!+ const apiKey = await generatePublishableKey(appContainer)+ const baseStoreHeaders = generateStoreHeaders({+ publishableKey: apiKey,+ })+ storeHeaders = {+ headers: {+ ...baseStoreHeaders.headers,+ ...customerResult.headers.headers,+ },+ }++ const salesChannelModule =+ appContainer.resolve<ISalesChannelModuleService>(+ Modules.SALES_CHANNEL+ )+ salesChannel = await salesChannelModule.createSalesChannels({+ name: "Admin Payment Channel",+ })++ const regionModule = appContainer.resolve<IRegionModuleService>(+ Modules.REGION+ )+ region = await regionModule.createRegions({+ name: "Admin Payment Region",+ currency_code: "usd",+ countries: ["us"],+ })++ const link = appContainer.resolve(ContainerRegistrationKeys.LINK)+ await link.create({+ [Modules.REGION]: { region_id: region.id },+ [Modules.PAYMENT]: {+ payment_provider_id: "pp_system_default",+ },+ })++ sellerSeed = await seedSellerOfferWithShipping({+ container: appContainer,+ api,+ salesChannelId: salesChannel.id,+ email: "[email protected]",+ name: "AdminPaymentS1",+ stocked: 20,+ offerPrice: 2500,+ })+ })++ const checkout = () =>+ completeSplitOrderCheckout({+ container: appContainer,+ api,+ storeHeaders,+ regionId: region.id,+ salesChannelId: salesChannel.id,+ offerId: sellerSeed.offer.id,+ email: customerEmail,+ })++ it("GET /admin/orders/:id surfaces the cart payment collection and an authorized payment_status", async () => {+ const order = await checkout()++ const { data } = await api.get(+ `/admin/orders/${order.id}`,+ adminHeaders+ )++ expect(data.order.payment_collections).toHaveLength(1)+ expect(data.order.payment_collections[0].amount).toBeGreaterThan(+ 0+ )+ expect(["authorized", "captured"]).toContain(+ data.order.payment_status+ )+ expect(data.order.cart).toBeUndefined()+ })++ it("GET /admin/orders list surfaces payment_collections and payment_status", async () => {+ const order = await checkout()++ const { data } = await api.get(`/admin/orders`, adminHeaders)++ const listed = data.orders.find((o: any) => o.id === order.id)+ expect(listed).toBeDefined()+ expect(listed.payment_collections).toHaveLength(1)+ expect(["authorized", "captured"]).toContain(+ listed.payment_status+ )+ expect(listed.cart).toBeUndefined()+ })+ })+ },+})diff --git a/integration-tests/http/order/store/order-payment-status.spec.ts b/integration-tests/http/order/store/order-payment-status.spec.tsnew file mode 100644index 000000000..62a86d242--- /dev/null+++ b/integration-tests/http/order/store/order-payment-status.spec.ts@@ -0,0 +1,137 @@+import { medusaIntegrationTestRunner } from "@medusajs/test-utils"+import {+ IRegionModuleService,+ ISalesChannelModuleService,+ MedusaContainer,+} from "@medusajs/framework/types"+import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"+import { createCustomerUser } from "../../../helpers/create-customer-user"+import {+ generatePublishableKey,+ generateStoreHeaders,+} from "../../../helpers/create-admin-user"+import {+ completeSplitOrderCheckout,+ seedSellerOfferWithShipping,+} from "../../../helpers/split-order-checkout"++jest.setTimeout(120000)++/**+ * Issue #1419 — the storefront reads the same split orders through the stock+ * `/store/orders(/:id)` routes, which also missed the #1387 fix and reported+ * `not_paid` for a fully authorized checkout.+ */+medusaIntegrationTestRunner({+ testSuite: ({ getContainer, api }) => {+ describe("Store - Order payment status (cart payment collection)", () => {+ let appContainer: MedusaContainer+ let sellerSeed: any+ let storeHeaders: any+ let customerEmail: string+ let region: any+ let salesChannel: any++ beforeAll(async () => {+ appContainer = getContainer()+ })++ beforeEach(async () => {+ const customerResult = await createCustomerUser(appContainer, {+ email: "[email protected]",+ first_name: "Payment",+ last_name: "Buyer",+ })+ customerEmail = customerResult.customer.email!+ const apiKey = await generatePublishableKey(appContainer)+ const baseStoreHeaders = generateStoreHeaders({+ publishableKey: apiKey,+ })+ storeHeaders = {+ headers: {+ ...baseStoreHeaders.headers,+ ...customerResult.headers.headers,+ },+ }++ const salesChannelModule =+ appContainer.resolve<ISalesChannelModuleService>(+ Modules.SALES_CHANNEL+ )+ salesChannel = await salesChannelModule.createSalesChannels({+ name: "Store Payment Channel",+ })++ const regionModule = appContainer.resolve<IRegionModuleService>(+ Modules.REGION+ )+ region = await regionModule.createRegions({+ name: "Store Payment Region",+ currency_code: "usd",+ countries: ["us"],+ })++ const link = appContainer.resolve(ContainerRegistrationKeys.LINK)+ await link.create({+ [Modules.REGION]: { region_id: region.id },+ [Modules.PAYMENT]: {+ payment_provider_id: "pp_system_default",+ },+ })++ sellerSeed = await seedSellerOfferWithShipping({+ container: appContainer,+ api,+ salesChannelId: salesChannel.id,+ email: "[email protected]",+ name: "StorePaymentS1",+ stocked: 20,+ offerPrice: 2500,+ })+ })++ const checkout = () =>+ completeSplitOrderCheckout({+ container: appContainer,+ api,+ storeHeaders,+ regionId: region.id,+ salesChannelId: salesChannel.id,+ offerId: sellerSeed.offer.id,+ email: customerEmail,+ })++ it("GET /store/orders/:id surfaces the cart payment collection and an authorized payment_status", async () => {+ const order = await checkout()++ const { data } = await api.get(+ `/store/orders/${order.id}`,+ storeHeaders+ )++ expect(data.order.payment_collections).toHaveLength(1)+ expect(data.order.payment_collections[0].amount).toBeGreaterThan(+ 0+ )+ expect(["authorized", "captured"]).toContain(+ data.order.payment_status+ )+ expect(data.order.cart).toBeUndefined()+ })++ it("GET /store/orders list surfaces payment_collections and payment_status", async () => {+ const order = await checkout()++ const { data } = await api.get(`/store/orders`, storeHeaders)++ const listed = data.orders.find((o: any) => o.id === order.id)+ expect(listed).toBeDefined()+ expect(listed.payment_collections).toHaveLength(1)+ expect(["authorized", "captured"]).toContain(+ listed.payment_status+ )+ expect(listed.cart).toBeUndefined()+ })+ })+ },+})diff --git a/integration-tests/http/order/vendor/order-payment-status.spec.ts b/integration-tests/http/order/vendor/order-payment-status.spec.tsindex fc81016cf..f814ea753 100644--- a/integration-tests/http/order/vendor/order-payment-status.spec.ts+++ b/integration-tests/http/order/vendor/order-payment-status.spec.ts@@ -5,14 +5,15 @@ import {MedusaContainer,} from "@medusajs/framework/types"import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"-import { MercurModules, SellerStatus } from "@mercurjs/types"-import { createSellerUser } from "../../../helpers/create-seller-user"import { createCustomerUser } from "../../../helpers/create-customer-user"-import { createVendorProduct } from "../../../helpers/create-product"import {generatePublishableKey,generateStoreHeaders,} from "../../../helpers/create-admin-user"+import {+ completeSplitOrderCheckout,+ seedSellerOfferWithShipping,+} from "../../../helpers/split-order-checkout"jest.setTimeout(120000)@@ -24,250 +25,15 @@ jest.setTimeout(120000)* `payment_status`, otherwise the badge stays `not_paid` even though checkout* authorized the payment.*/--const approveSeller = async (- container: MedusaContainer,- sellerId: string-) => {- const sellerModule: any = container.resolve(MercurModules.SELLER)- await sellerModule.updateSellers({- id: sellerId,- status: SellerStatus.OPEN,- })-}-medusaIntegrationTestRunner({testSuite: ({ getContainer, api }) => {describe("Vendor - Order payment status (cart payment collection)", () => {let appContainer: MedusaContainerlet sellerSeed: anylet storeHeaders: any+ let customerEmail: stringlet region: anylet salesChannel: any- let prerequisiteCounter = 0-- const seedSellerOfferWithShipping = async (opts: {- email: string- name: string- stocked: number- offerPrice: number- }) => {- const result = await createSellerUser(appContainer, {- email: opts.email,- name: opts.name,- })- await approveSeller(appContainer, (result.seller as any).id)- const headers = result.headers- const tag = `_${opts.name}_${Date.now()}_${++prerequisiteCounter}`-- const stockLocation = (- await api.post(- `/vendor/stock-locations`,- { name: `Warehouse${tag}` },- headers- )- ).data.stock_location-- await api.post(- `/vendor/stock-locations/${stockLocation.id}/fulfillment-sets`,- { name: `FS${tag}`, type: "shipping" },- headers- )- const fulfillmentSet = (- await api.get(- `/vendor/stock-locations/${stockLocation.id}?fields=*fulfillment_sets`,- headers- )- ).data.stock_location.fulfillment_sets[0]- const serviceZone = (- await api.post(- `/vendor/fulfillment-sets/${fulfillmentSet.id}/service-zones`,- {- name: `SZ${tag}`,- geo_zones: [{ type: "country", country_code: "us" }],- },- headers- )- ).data.fulfillment_set.service_zones.find(- (z: any) => z.name === `SZ${tag}`- )- const shippingProfile = (- await api.post(- `/vendor/shipping-profiles`,- { name: `SP${tag}`, type: "default" },- headers- )- ).data.shipping_profile-- await api.post(- `/vendor/stock-locations/${stockLocation.id}/fulfillment-providers`,- { add: ["manual_manual"] },- headers- )- await api.post(- `/vendor/stock-locations/${stockLocation.id}/sales-channels`,- { add: [salesChannel.id] },- headers- )- await api.post(- `/vendor/shipping-options`,- {- name: `Ship${tag}`,- service_zone_id: serviceZone.id,- shipping_profile_id: shippingProfile.id,- provider_id: "manual_manual",- price_type: "flat",- type: {- label: "Standard",- description: "Standard",- code: "standard",- },- prices: [{ currency_code: "usd", amount: 500 }],- rules: [- {- attribute: "enabled_in_store",- value: "true",- operator: "eq",- },- ],- },- headers- )-- const product = await createVendorProduct(api, headers, {- title: `Prod${tag}`,- sku: `V${tag}`,- })-- await api.post(- `/vendor/sales-channels/${salesChannel.id}/products`,- { add: [product.id] },- headers- )-- const offer = (- await api.post(- `/vendor/offers`,- {- sku: `OF${tag}`,- variant_id: product.variants[0].id,- shipping_profile_id: shippingProfile.id,- inventory_items: [- {- title: `Inv${tag}`,- required_quantity: 1,- stock_levels: [- {- location_id: stockLocation.id,- stocked_quantity: opts.stocked,- },- ],- },- ],- prices: [- {- amount: opts.offerPrice,- currency_code: "usd",- },- ],- },- headers- )- ).data.offer-- return { sellerId: result.seller.id, headers, offer }- }-- const completeCartCheckout = async (offerId: string) => {- const cart = (- await api.post(- `/store/carts`,- {- region_id: region.id,- sales_channel_id: salesChannel.id,- currency_code: "usd",- },- storeHeaders- )- ).data.cart-- await api.post(- `/store/carts/${cart.id}/line-items`,- { offer_id: offerId, quantity: 1 },- storeHeaders- )-- await api.post(- `/store/carts/${cart.id}`,- {- email: "[email protected]",- shipping_address: {- first_name: "Buyer",- last_name: "Test",- address_1: "123 Main St",- city: "New York",- country_code: "us",- postal_code: "10001",- },- billing_address: {- first_name: "Buyer",- last_name: "Test",- address_1: "123 Main St",- city: "New York",- country_code: "us",- postal_code: "10001",- },- },- storeHeaders- )-- const shippingOptionsResp = await api.get(- `/store/shipping-options?cart_id=${cart.id}`,- storeHeaders- )- const allOptions = Object.values(- shippingOptionsResp.data.shipping_options as Record<- string,- any[]- >- ).flat()- for (const opt of allOptions) {- await api.post(- `/store/carts/${cart.id}/shipping-methods`,- { option_id: opt.id },- storeHeaders- )- }-- const paymentCollection = (- await api.post(- `/store/payment-collections`,- { cart_id: cart.id },- storeHeaders- )- ).data.payment_collection- await api.post(- `/store/payment-collections/${paymentCollection.id}/payment-sessions`,- { provider_id: "pp_system_default" },- storeHeaders- )-- const completeResp = await api.post(- `/store/carts/${cart.id}/complete`,- {},- storeHeaders- )- const orderGroupId = completeResp.data.order_group.id- const query = appContainer.resolve(- ContainerRegistrationKeys.QUERY- )- const { data: orderGroup } = await query.graph({- entity: "order_group",- filters: { id: orderGroupId },- fields: ["id", "orders.id"],- })- return (orderGroup[0] as any).orders[0]- }beforeAll(async () => {appContainer = getContainer()@@ -279,6 +45,7 @@ medusaIntegrationTestRunner({first_name: "Payment",last_name: "Buyer",})+ customerEmail = customerResult.customer.email!const apiKey = await generatePublishableKey(appContainer)const baseStoreHeaders = generateStoreHeaders({publishableKey: apiKey,@@ -316,6 +83,9 @@ medusaIntegrationTestRunner({})sellerSeed = await seedSellerOfferWithShipping({+ container: appContainer,+ api,+ salesChannelId: salesChannel.id,email: "[email protected]",name: "PaymentS1",stocked: 20,@@ -323,8 +93,19 @@ medusaIntegrationTestRunner({})})+ const checkout = () =>+ completeSplitOrderCheckout({+ container: appContainer,+ api,+ storeHeaders,+ regionId: region.id,+ salesChannelId: salesChannel.id,+ offerId: sellerSeed.offer.id,+ email: customerEmail,+ })+it("GET /vendor/orders/:id surfaces the cart payment collection and an authorized payment_status", async () => {- const order = await completeCartCheckout(sellerSeed.offer.id)+ const order = await checkout()const { data } = await api.get(`/vendor/orders/${order.id}`,@@ -343,7 +124,7 @@ medusaIntegrationTestRunner({})it("GET /vendor/orders list surfaces payment_collections and payment_status", async () => {- const order = await completeCartCheckout(sellerSeed.offer.id)+ const order = await checkout()const { data } = await api.get(`/vendor/orders`,diff --git a/packages/cli/routes-manifest.json b/packages/cli/routes-manifest.jsonindex 655cb19bc..bfd2e7c75 100644--- a/packages/cli/routes-manifest.json+++ b/packages/cli/routes-manifest.json@@ -105,7 +105,7 @@"/admin/order-groups": "typeof import(\"@mercurjs/core/api/admin/order-groups/route\")","/admin/order-groups/:id": "typeof import(\"@mercurjs/core/api/admin/order-groups/[id]/route\")","/admin/orders": "typeof import(\"@mercurjs/core/api/admin/orders/route\")",- "/admin/orders/:id": "typeof import(\"@medusajs/medusa/api/admin/orders/[id]/route\")",+ "/admin/orders/:id": "typeof import(\"@mercurjs/core/api/admin/orders/[id]/route\")","/admin/orders/:id/archive": "typeof import(\"@medusajs/medusa/api/admin/orders/[id]/archive/route\")","/admin/orders/:id/cancel": "typeof import(\"@medusajs/medusa/api/admin/orders/[id]/cancel/route\")","/admin/orders/:id/changes": "typeof import(\"@medusajs/medusa/api/admin/orders/[id]/changes/route\")",@@ -343,8 +343,8 @@"/store/offers/:id": "typeof import(\"@mercurjs/core/api/store/offers/[id]/route\")","/store/order-groups": "typeof import(\"@mercurjs/core/api/store/order-groups/route\")","/store/order-groups/:id": "typeof import(\"@mercurjs/core/api/store/order-groups/[id]/route\")",- "/store/orders": "typeof import(\"@medusajs/medusa/api/store/orders/route\")",- "/store/orders/:id": "typeof import(\"@medusajs/medusa/api/store/orders/[id]/route\")",+ "/store/orders": "typeof import(\"@mercurjs/core/api/store/orders/route\")",+ "/store/orders/:id": "typeof import(\"@mercurjs/core/api/store/orders/[id]/route\")","/store/orders/:id/transfer/accept": "typeof import(\"@medusajs/medusa/api/store/orders/[id]/transfer/accept/route\")","/store/orders/:id/transfer/cancel": "typeof import(\"@medusajs/medusa/api/store/orders/[id]/transfer/cancel/route\")","/store/orders/:id/transfer/decline": "typeof import(\"@medusajs/medusa/api/store/orders/[id]/transfer/decline/route\")",diff --git a/packages/core/src/api/admin/orders/[id]/route.ts b/packages/core/src/api/admin/orders/[id]/route.tsnew file mode 100644index 000000000..7adc6b17f--- /dev/null+++ b/packages/core/src/api/admin/orders/[id]/route.ts@@ -0,0 +1,32 @@+import { getOrderDetailWorkflow } from "@medusajs/core-flows"+import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"+import { HttpTypes } from "@medusajs/types"++import {+ normalizeOrderPaymentCollections,+ withCartPaymentCollectionFields,+} from "../../../utils/split-order-payment-status"++// Only GET is overridden. Medusa resolves duplicate routes per method, so the+// stock POST would keep working on its own — but the generated route manifest+// maps a path to a single module, so it has to be re-exported here for the+// typed client to keep seeing it.+export { POST } from "@medusajs/medusa/api/admin/orders/[id]/route"++export const GET = async (+ req: AuthenticatedMedusaRequest,+ res: MedusaResponse<HttpTypes.AdminOrderResponse>+) => {+ const workflow = getOrderDetailWorkflow(req.scope)+ const { result } = await workflow.run({+ input: {+ fields: withCartPaymentCollectionFields(req.queryConfig.fields),+ order_id: req.params.id,+ version: (req.validatedQuery as { version?: number }).version,+ },+ })++ normalizeOrderPaymentCollections(result as never)++ res.json({ order: result as HttpTypes.AdminOrderResponse["order"] })+}diff --git a/packages/core/src/api/admin/orders/route.ts b/packages/core/src/api/admin/orders/route.tsindex cfd5fba85..8a0db0add 100644--- a/packages/core/src/api/admin/orders/route.ts+++ b/packages/core/src/api/admin/orders/route.ts@@ -1,5 +1,44 @@-import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework";-import { HttpTypes } from "@medusajs/types";-import { AdminGetOrdersParamsType } from "./validators";+import { getOrdersListWorkflow } from "@medusajs/core-flows"+import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"+import { OrderDTO } from "@medusajs/framework/types"+import { HttpTypes } from "@medusajs/types"-export declare const GET: (req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>, res: MedusaResponse<HttpTypes.AdminOrderListResponse>) => Promise<void>;+import {+ normalizeOrderPaymentCollections,+ withCartPaymentCollectionFields,+} from "../../utils/split-order-payment-status"+import { AdminGetOrdersParamsType } from "./validators"++// Overrides the stock Medusa route to surface the split order payment+// collection, which lives on the cart rather than on the order link.+export const GET = async (+ req: AuthenticatedMedusaRequest<AdminGetOrdersParamsType>,+ res: MedusaResponse<HttpTypes.AdminOrderListResponse>+) => {+ const variables = {+ filters: {+ ...req.filterableFields,+ is_draft_order: false,+ },+ ...req.queryConfig.pagination,+ }++ const workflow = getOrdersListWorkflow(req.scope)+ const { result } = await workflow.run({+ input: {+ fields: withCartPaymentCollectionFields(req.queryConfig.fields),+ variables,+ },+ })++ const { rows, metadata } = result as { rows: OrderDTO[]; metadata: any }++ rows.forEach((order) => normalizeOrderPaymentCollections(order as never))++ res.json({+ orders: rows as unknown as HttpTypes.AdminOrderListResponse["orders"],+ count: metadata.count,+ offset: metadata.skip,+ limit: metadata.take,+ })+}diff --git a/packages/core/src/api/store/orders/[id]/route.ts b/packages/core/src/api/store/orders/[id]/route.tsnew file mode 100644index 000000000..a6f68f227--- /dev/null+++ b/packages/core/src/api/store/orders/[id]/route.ts@@ -0,0 +1,26 @@+import { getOrderDetailWorkflow } from "@medusajs/core-flows"+import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"+import { HttpTypes } from "@medusajs/types"++import {+ normalizeOrderPaymentCollections,+ withCartPaymentCollectionFields,+} from "../../../utils/split-order-payment-status"++export const GET = async (+ req: AuthenticatedMedusaRequest,+ res: MedusaResponse<HttpTypes.StoreOrderResponse>+) => {+ const workflow = getOrderDetailWorkflow(req.scope)+ const { result } = await workflow.run({+ input: {+ fields: withCartPaymentCollectionFields(req.queryConfig.fields),+ order_id: req.params.id,+ filters: { is_draft_order: false },+ },+ })++ normalizeOrderPaymentCollections(result as never)++ res.json({ order: result as HttpTypes.StoreOrderResponse["order"] })+}diff --git a/packages/core/src/api/store/orders/route.ts b/packages/core/src/api/store/orders/route.tsnew file mode 100644index 000000000..4f2554dfc--- /dev/null+++ b/packages/core/src/api/store/orders/route.ts@@ -0,0 +1,44 @@+import { getOrdersListWorkflow } from "@medusajs/core-flows"+import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework"+import { OrderDTO } from "@medusajs/framework/types"+import { HttpTypes } from "@medusajs/types"++import {+ normalizeOrderPaymentCollections,+ withCartPaymentCollectionFields,+} from "../../utils/split-order-payment-status"++// Overrides the stock Medusa route to surface the split order payment+// collection, which lives on the cart rather than on the order link.+export const GET = async (+ req: AuthenticatedMedusaRequest,+ res: MedusaResponse<HttpTypes.StoreOrderListResponse>+) => {+ const variables = {+ filters: {+ ...req.filterableFields,+ is_draft_order: false,+ customer_id: req.auth_context.actor_id,+ },+ ...req.queryConfig.pagination,+ }++ const workflow = getOrdersListWorkflow(req.scope)+ const { result } = await workflow.run({+ input: {+ fields: withCartPaymentCollectionFields(req.queryConfig.fields),+ variables,+ },+ })++ const { rows, metadata } = result as { rows: OrderDTO[]; metadata: any }++ rows.forEach((order) => normalizeOrderPaymentCollections(order as never))++ res.json({+ orders: rows as unknown as HttpTypes.StoreOrderListResponse["orders"],+ count: metadata.count,+ offset: metadata.skip,+ limit: metadata.take,+ })+}diff --git a/packages/core/src/api/utils/index.ts b/packages/core/src/api/utils/index.tsindex 235ed7ef2..cc0cb3bc2 100644--- a/packages/core/src/api/utils/index.ts+++ b/packages/core/src/api/utils/index.ts@@ -10,3 +10,4 @@ export * from "./format-product-attributes"export * from "./product-attribute-fields"export * from "./filter-attributes-by-category-link"export * from "./offers"+export * from "./split-order-payment-status"diff --git a/packages/core/src/api/utils/split-order-payment-status.ts b/packages/core/src/api/utils/split-order-payment-status.tsnew file mode 100644index 000000000..702625c38--- /dev/null+++ b/packages/core/src/api/utils/split-order-payment-status.ts@@ -0,0 +1,53 @@+import type { OrderDetailDTO } from "@medusajs/framework/types"+import { deduplicate } from "@medusajs/framework/utils"++import { getLastPaymentStatus } from "../../workflows/order-group/utils/aggregate-status"++type OrderWithCartPaymentCollection = {+ cart?: { payment_collection?: unknown } | null+ payment_collections?: unknown[]+ payment_status?: string+}++// The shared cart payment collection is reached through the cart, not linked+// to the order. These fields must always be loaded so the routes can normalize+// them back onto `payment_collections` and recompute `payment_status` — even+// when the client sends an absolute `fields=` list that would otherwise replace+// the route defaults.+const CART_PAYMENT_COLLECTION_FIELDS = [+ "cart.payment_collection.*",+ "cart.payment_collection.payments.*",+ "cart.payment_collection.payments.refunds.*",+ "cart.payment_collection.payments.refunds.refund_reason.*",+ "cart.payment_collection.payment_sessions.*",+]++export const withCartPaymentCollectionFields = (fields: string[]): string[] => {+ return deduplicate([...fields, ...CART_PAYMENT_COLLECTION_FIELDS])+}++// The shared cart payment collection is fetched via `cart.payment_collection`+// (it is not linked directly to an order). Expose it back on the order under+// `payment_collections` so consumers keep the familiar shape, and recompute+// `payment_status` from it — Medusa's aggregation reads the linked payment+// collections, which are always empty for split orders under the cart-path model.+export const normalizeOrderPaymentCollections = <+ T extends OrderWithCartPaymentCollection+>(+ order: T+): T => {+ const paymentCollection = order.cart?.payment_collection++ delete order.cart++ if (!paymentCollection) {+ return order+ }++ order.payment_collections = [paymentCollection]+ order.payment_status = getLastPaymentStatus(+ order as unknown as OrderDetailDTO+ )++ return order+}diff --git a/packages/core/src/api/vendor/orders/helpers.ts b/packages/core/src/api/vendor/orders/helpers.tsindex ef8a8c2c9..b89c9f1b1 100644--- a/packages/core/src/api/vendor/orders/helpers.ts+++ b/packages/core/src/api/vendor/orders/helpers.ts@@ -1,59 +1,13 @@import { MedusaContainer } from "@medusajs/framework"-import type { OrderDetailDTO } from "@medusajs/framework/types"import {ContainerRegistrationKeys,MedusaError,} from "@medusajs/framework/utils"-import { deduplicate } from "@medusajs/framework/utils"--import { getLastPaymentStatus } from "../../../workflows/order-group/utils/aggregate-status"--type OrderWithCartPaymentCollection = {- cart?: { payment_collection?: unknown } | null- payment_collections?: unknown[]- payment_status?: string-}--// The shared cart payment collection is reached through the cart, not linked-// to the order. These fields must always be loaded so the routes can normalize-// them back onto `payment_collections` and recompute `payment_status` — even-// when the client sends an absolute `fields=` list that would otherwise replace-// the route defaults.-const CART_PAYMENT_COLLECTION_FIELDS = [- "cart.payment_collection.*",- "cart.payment_collection.payments.*",- "cart.payment_collection.payments.refunds.*",- "cart.payment_collection.payments.refunds.refund_reason.*",- "cart.payment_collection.payment_sessions.*",-]--export const withCartPaymentCollectionFields = (- fields: string[]-): string[] => {- return deduplicate([...fields, ...CART_PAYMENT_COLLECTION_FIELDS])-}--// The shared cart payment collection is fetched via `cart.payment_collection`-// (it is not linked directly to an order). Expose it back on the order under-// `payment_collections` so consumers keep the familiar shape, and recompute-// `payment_status` from it — Medusa's aggregation reads the linked payment-// collections, which are always empty for split orders under the cart-path model.-export const normalizeOrderPaymentCollections = <- T extends OrderWithCartPaymentCollection->(- order: T-): T => {- const paymentCollection = order.cart?.payment_collection- order.payment_collections = paymentCollection ? [paymentCollection] : []- delete order.cart-- order.payment_status = getLastPaymentStatus(- order as unknown as OrderDetailDTO- )-- return order-}+export {+ normalizeOrderPaymentCollections,+ withCartPaymentCollectionFields,+} from "../../utils/split-order-payment-status"export const validateSellerOrder = async (scope: MedusaContainer,