chore(order): link order and payment collection (#7334)
This commit is contained in:
@@ -1897,6 +1897,23 @@ medusaIntegrationTestRunner({
|
|||||||
line_item_id: cart.items[0].id,
|
line_item_id: cart.items[0].id,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const fullOrder = await api.get(
|
||||||
|
`/admin/orders/${response.data.order.id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
const fullOrderDetail = fullOrder.data.order
|
||||||
|
|
||||||
|
expect(fullOrderDetail).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
payment_collections: [
|
||||||
|
expect.objectContaining({
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 106,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should throw an error when payment collection isn't created", async () => {
|
it("should throw an error when payment collection isn't created", async () => {
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ medusaIntegrationTestRunner({
|
|||||||
status: "pending",
|
status: "pending",
|
||||||
version: 1,
|
version: 1,
|
||||||
display_id: 1,
|
display_id: 1,
|
||||||
|
payment_collections: [],
|
||||||
summary: expect.objectContaining({
|
summary: expect.objectContaining({
|
||||||
// TODO: add all summary fields
|
// TODO: add all summary fields
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
} from "@medusajs/workflows-sdk"
|
} from "@medusajs/workflows-sdk"
|
||||||
import { useRemoteQueryStep } from "../../../common"
|
import { useRemoteQueryStep } from "../../../common"
|
||||||
|
import { linkOrderAndPaymentCollectionsStep } from "../../../order/steps"
|
||||||
import { authorizePaymentSessionStep } from "../../../payment/steps/authorize-payment-session"
|
import { authorizePaymentSessionStep } from "../../../payment/steps/authorize-payment-session"
|
||||||
import { createOrderFromCartStep, validateCartPaymentsStep } from "../steps"
|
import { createOrderFromCartStep, validateCartPaymentsStep } from "../steps"
|
||||||
import { reserveInventoryStep } from "../steps/reserve-inventory"
|
import { reserveInventoryStep } from "../steps/reserve-inventory"
|
||||||
@@ -70,6 +71,19 @@ export const completeCartWorkflow = createWorkflow(
|
|||||||
list: false,
|
list: false,
|
||||||
}).config({ name: "final-cart" })
|
}).config({ name: "final-cart" })
|
||||||
|
|
||||||
return createOrderFromCartStep({ cart: finalCart })
|
const order = createOrderFromCartStep({ cart: finalCart })
|
||||||
|
|
||||||
|
const linkOrderPaymentCollection = transform({ order, cart }, (data) => ({
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
order_id: data.order.id,
|
||||||
|
payment_collection_id: data.cart.payment_collection.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}))
|
||||||
|
|
||||||
|
linkOrderAndPaymentCollectionsStep(linkOrderPaymentCollection)
|
||||||
|
|
||||||
|
return order
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from "./create-orders"
|
export * from "./create-orders"
|
||||||
export * from "./get-item-tax-lines"
|
export * from "./get-item-tax-lines"
|
||||||
|
export * from "./link-order-payment-collection"
|
||||||
export * from "./set-tax-lines-for-items"
|
export * from "./set-tax-lines-for-items"
|
||||||
export * from "./update-tax-lines"
|
export * from "./update-tax-lines"
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||||
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
|
type StepInput = {
|
||||||
|
links: {
|
||||||
|
order_id: string
|
||||||
|
payment_collection_id: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const linkOrderAndPaymentCollectionsStepId =
|
||||||
|
"link-order-payment-collection"
|
||||||
|
export const linkOrderAndPaymentCollectionsStep = createStep(
|
||||||
|
linkOrderAndPaymentCollectionsStepId,
|
||||||
|
async (data: StepInput, { container }) => {
|
||||||
|
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||||
|
|
||||||
|
const links = data.links.map((d) => ({
|
||||||
|
[Modules.ORDER]: { order_id: d.order_id },
|
||||||
|
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
|
||||||
|
}))
|
||||||
|
|
||||||
|
await remoteLink.create(links)
|
||||||
|
|
||||||
|
return new StepResponse(void 0, data)
|
||||||
|
},
|
||||||
|
async (data, { container }) => {
|
||||||
|
if (!data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||||
|
|
||||||
|
const links = data.links.map((d) => ({
|
||||||
|
[Modules.ORDER]: { order_id: d.order_id },
|
||||||
|
[Modules.PAYMENT]: { payment_collection_id: d.payment_collection_id },
|
||||||
|
}))
|
||||||
|
|
||||||
|
await remoteLink.dismiss(links)
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -160,7 +160,7 @@ export class RemoteJoiner {
|
|||||||
|
|
||||||
// add aliases
|
// add aliases
|
||||||
const isReadOnlyDefinition =
|
const isReadOnlyDefinition =
|
||||||
service.serviceName === undefined || service.isReadOnlyLink
|
!isDefined(service.serviceName) || service.isReadOnlyLink
|
||||||
if (!isReadOnlyDefinition) {
|
if (!isReadOnlyDefinition) {
|
||||||
service.alias ??= []
|
service.alias ??= []
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ export class RemoteJoiner {
|
|||||||
uniqueIds = Array.from(new Set(uniqueIds.flat()))
|
uniqueIds = Array.from(new Set(uniqueIds.flat()))
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueIds = uniqueIds.filter((id) => id !== undefined)
|
uniqueIds = uniqueIds.filter((id) => isDefined(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relationship) {
|
if (relationship) {
|
||||||
@@ -478,7 +478,7 @@ export class RemoteJoiner {
|
|||||||
|
|
||||||
const curPath: string[] = [BASE_PATH].concat(alias.location)
|
const curPath: string[] = [BASE_PATH].concat(alias.location)
|
||||||
for (const prop of propPath) {
|
for (const prop of propPath) {
|
||||||
if (currentItems === undefined) {
|
if (!isDefined(currentItems)) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,7 +500,9 @@ export class RemoteJoiner {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
locationItem[alias.property] = alias.isList
|
locationItem[alias.property] = alias.isList
|
||||||
? [currentItems]
|
? isDefined(currentItems)
|
||||||
|
? [currentItems]
|
||||||
|
: []
|
||||||
: currentItems
|
: currentItems
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,18 +647,18 @@ export class RemoteJoiner {
|
|||||||
if (Array.isArray(item[field])) {
|
if (Array.isArray(item[field])) {
|
||||||
item[relationship.alias] = item[field].map((id) => {
|
item[relationship.alias] = item[field].map((id) => {
|
||||||
if (relationship.isList && !Array.isArray(relatedDataMap[id])) {
|
if (relationship.isList && !Array.isArray(relatedDataMap[id])) {
|
||||||
relatedDataMap[id] =
|
relatedDataMap[id] = isDefined(relatedDataMap[id])
|
||||||
relatedDataMap[id] !== undefined ? [relatedDataMap[id]] : []
|
? [relatedDataMap[id]]
|
||||||
|
: []
|
||||||
}
|
}
|
||||||
|
|
||||||
return relatedDataMap[id]
|
return relatedDataMap[id]
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (relationship.isList && !Array.isArray(relatedDataMap[itemKey])) {
|
if (relationship.isList && !Array.isArray(relatedDataMap[itemKey])) {
|
||||||
relatedDataMap[itemKey] =
|
relatedDataMap[itemKey] = isDefined(relatedDataMap[itemKey])
|
||||||
relatedDataMap[itemKey] !== undefined
|
? [relatedDataMap[itemKey]]
|
||||||
? [relatedDataMap[itemKey]]
|
: []
|
||||||
: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item[relationship.alias] = relatedDataMap[itemKey]
|
item[relationship.alias] = relatedDataMap[itemKey]
|
||||||
|
|||||||
@@ -68,18 +68,16 @@ export const LINKS = {
|
|||||||
Modules.SALES_CHANNEL,
|
Modules.SALES_CHANNEL,
|
||||||
"sales_channel_id"
|
"sales_channel_id"
|
||||||
),
|
),
|
||||||
|
|
||||||
// Internal services
|
|
||||||
ProductShippingProfile: composeLinkName(
|
|
||||||
Modules.PRODUCT,
|
|
||||||
"variant_id",
|
|
||||||
"shippingProfileService",
|
|
||||||
"profile_id"
|
|
||||||
),
|
|
||||||
ProductSalesChannel: composeLinkName(
|
ProductSalesChannel: composeLinkName(
|
||||||
Modules.PRODUCT,
|
Modules.PRODUCT,
|
||||||
"product_id",
|
"product_id",
|
||||||
Modules.SALES_CHANNEL,
|
Modules.SALES_CHANNEL,
|
||||||
"sales_channel_id"
|
"sales_channel_id"
|
||||||
),
|
),
|
||||||
|
OrderPaymentCollection: composeLinkName(
|
||||||
|
Modules.ORDER,
|
||||||
|
"order_id",
|
||||||
|
Modules.PAYMENT,
|
||||||
|
"payment_collection_id"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const defaultAdminRetrieveOrderFields = [
|
|||||||
"*shipping_methods",
|
"*shipping_methods",
|
||||||
"*shipping_methods.tax_lines",
|
"*shipping_methods.tax_lines",
|
||||||
"*shipping_methods.adjustments",
|
"*shipping_methods.adjustments",
|
||||||
|
"*payment_collections",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const retrieveTransformQueryConfig = {
|
export const retrieveTransformQueryConfig = {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export const defaultStoreRetrieveOrderFields = [
|
|||||||
"*shipping_methods",
|
"*shipping_methods",
|
||||||
"*shipping_methods.tax_lines",
|
"*shipping_methods.tax_lines",
|
||||||
"*shipping_methods.adjustments",
|
"*shipping_methods.adjustments",
|
||||||
|
"*payment_collections",
|
||||||
]
|
]
|
||||||
|
|
||||||
export const retrieveTransformQueryConfig = {
|
export const retrieveTransformQueryConfig = {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
export * from "./cart-payment-collection"
|
export * from "./cart-payment-collection"
|
||||||
export * from "./cart-promotion"
|
export * from "./cart-promotion"
|
||||||
export * from "./fulfillment-set-location"
|
export * from "./fulfillment-set-location"
|
||||||
|
export * from "./order-payment-collection"
|
||||||
export * from "./order-promotion"
|
export * from "./order-promotion"
|
||||||
export * from "./order-region"
|
export * from "./order-region"
|
||||||
export * from "./product-sales-channel"
|
export * from "./product-sales-channel"
|
||||||
export * from "./product-shipping-profile"
|
|
||||||
export * from "./product-variant-inventory-item"
|
export * from "./product-variant-inventory-item"
|
||||||
export * from "./product-variant-price-set"
|
export * from "./product-variant-price-set"
|
||||||
export * from "./publishable-api-key-sales-channel"
|
export * from "./publishable-api-key-sales-channel"
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
|
import { LINKS } from "@medusajs/utils"
|
||||||
|
|
||||||
|
export const OrderPaymentCollection: ModuleJoinerConfig = {
|
||||||
|
serviceName: LINKS.OrderPaymentCollection,
|
||||||
|
isLink: true,
|
||||||
|
databaseConfig: {
|
||||||
|
tableName: "order_payment_collection",
|
||||||
|
idPrefix: "capaycol",
|
||||||
|
},
|
||||||
|
alias: [
|
||||||
|
{
|
||||||
|
name: ["order_payment_collection", "order_payment_collections"],
|
||||||
|
args: {
|
||||||
|
entity: "LinkOrderPaymentCollection",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
primaryKeys: ["id", "order_id", "payment_collection_id"],
|
||||||
|
relationships: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.ORDER,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "order_id",
|
||||||
|
alias: "order",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.PAYMENT,
|
||||||
|
primaryKey: "id",
|
||||||
|
foreignKey: "payment_collection_id",
|
||||||
|
alias: "payment_collection",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
{
|
||||||
|
serviceName: Modules.ORDER,
|
||||||
|
fieldAlias: {
|
||||||
|
payment_collections: {
|
||||||
|
path: "payment_collections_link.payment_collection",
|
||||||
|
isList: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.OrderPaymentCollection,
|
||||||
|
primaryKey: "order_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "payment_collections_link",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
serviceName: Modules.PAYMENT,
|
||||||
|
fieldAlias: {
|
||||||
|
order: "order_link.order",
|
||||||
|
},
|
||||||
|
relationship: {
|
||||||
|
serviceName: LINKS.OrderPaymentCollection,
|
||||||
|
primaryKey: "payment_collection_id",
|
||||||
|
foreignKey: "id",
|
||||||
|
alias: "order_link",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
|
||||||
import { LINKS } from "@medusajs/utils"
|
|
||||||
|
|
||||||
export const ProductShippingProfile: ModuleJoinerConfig = {
|
|
||||||
serviceName: LINKS.ProductShippingProfile,
|
|
||||||
isLink: true,
|
|
||||||
databaseConfig: {
|
|
||||||
tableName: "product_shipping_profile",
|
|
||||||
idPrefix: "psprof",
|
|
||||||
},
|
|
||||||
alias: [
|
|
||||||
{
|
|
||||||
name: "product_shipping_profile",
|
|
||||||
args: {
|
|
||||||
entity: "LinkProductShippingProfile",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
primaryKeys: ["id", "product_id", "profile_id"],
|
|
||||||
relationships: [
|
|
||||||
{
|
|
||||||
serviceName: Modules.PRODUCT,
|
|
||||||
primaryKey: "id",
|
|
||||||
foreignKey: "product_id",
|
|
||||||
alias: "product",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
serviceName: "shippingProfileService",
|
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "id",
|
|
||||||
foreignKey: "profile_id",
|
|
||||||
alias: "profile",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
extends: [
|
|
||||||
{
|
|
||||||
serviceName: Modules.PRODUCT,
|
|
||||||
fieldAlias: {
|
|
||||||
profile: "shipping_profile.profile",
|
|
||||||
},
|
|
||||||
relationship: {
|
|
||||||
serviceName: LINKS.ProductShippingProfile,
|
|
||||||
primaryKey: "product_id",
|
|
||||||
foreignKey: "id",
|
|
||||||
alias: "shipping_profile",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
serviceName: "shippingProfileService",
|
|
||||||
relationship: {
|
|
||||||
serviceName: LINKS.ProductShippingProfile,
|
|
||||||
isInternalService: true,
|
|
||||||
primaryKey: "profile_id",
|
|
||||||
foreignKey: "id",
|
|
||||||
alias: "product_link",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user