feat(medusa): Payment Collection endpoints (#2525)
This commit is contained in:
1 parent
27184f3878
commit
755ba90c05
58 files changed
+1190
-484
No files matched your search
@@ -18,3 +18,4 @@ export * from "./simple-price-list-factory"
|
||||
export * from "./simple-batch-job-factory"
|
||||
export * from "./simple-sales-channel-factory"
|
||||
export * from "./simple-custom-shipping-option-factory"
|
||||
export * from "./simple-payment-collection-factory"
|
||||
@@ -31,6 +31,7 @@ export type LineItemFactoryData = {
|
||||
tax_lines?: TaxLineFactoryData[]
|
||||
adjustments: LineItemAdjustmentFactoryData[]
|
||||
includes_tax?: boolean
|
||||
order_edit_id?: string
|
||||
}
|
||||
|
||||
export const simpleLineItemFactory = async (
|
||||
@@ -72,6 +73,7 @@ export const simpleLineItemFactory = async (
|
||||
returned_quantity: data.returned_quantity || null,
|
||||
adjustments: data.adjustments,
|
||||
includes_tax: data.includes_tax,
|
||||
order_edit_id: data.order_edit_id,
|
||||
})
|
||||
|
||||
const line = await manager.save(toSave)
|
||||
|
||||
@@ -8,6 +8,7 @@ export type OrderEditFactoryData = {
|
||||
order_id?: string
|
||||
internal_note?: string
|
||||
declined_reason?: string
|
||||
payment_collection_id?: string
|
||||
confirmed_at?: Date | string
|
||||
confirmed_by?: string
|
||||
created_at?: Date | string
|
||||
@@ -46,6 +47,7 @@ export const simpleOrderEditFactory = async (
|
||||
created_by: data.created_by,
|
||||
confirmed_at: data.confirmed_at,
|
||||
confirmed_by: data.confirmed_by,
|
||||
payment_collection_id: data.payment_collection_id,
|
||||
})
|
||||
|
||||
return await manager.save<OrderEdit>(orderEdit)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Connection } from "typeorm"
|
||||
|
||||
import { simpleRegionFactory } from "./simple-region-factory"
|
||||
import { simplePaymentFactory } from "./simple-payment-factory"
|
||||
import { Payment, PaymentCollection } from "@medusajs/medusa"
|
||||
|
||||
export const simplePaymentCollectionFactory = async (
|
||||
connection: Connection,
|
||||
data: Partial<PaymentCollection> = {}
|
||||
): Promise<PaymentCollection> => {
|
||||
const manager = connection.manager
|
||||
|
||||
const defaultData = {
|
||||
currency_code: data.currency_code ?? "usd",
|
||||
}
|
||||
|
||||
if (!data.region && !data.region_id) {
|
||||
data.region = await simpleRegionFactory(connection, {
|
||||
id: data.region_id || "test-region",
|
||||
currency_code: defaultData.currency_code,
|
||||
})
|
||||
data.region_id = data.region.id
|
||||
}
|
||||
|
||||
if (data.payments?.length) {
|
||||
const payments: Payment[] = []
|
||||
for (const payment of data.payments) {
|
||||
payment.currency_code = payment.currency_code ?? defaultData.currency_code
|
||||
|
||||
const savedPayment = await simplePaymentFactory(
|
||||
connection,
|
||||
payment as any
|
||||
)
|
||||
payments.push(savedPayment)
|
||||
}
|
||||
|
||||
data.payments = payments
|
||||
}
|
||||
|
||||
const obj = {
|
||||
...defaultData,
|
||||
...data,
|
||||
}
|
||||
|
||||
const payCol = manager.create<PaymentCollection>(PaymentCollection, obj)
|
||||
|
||||
return await manager.save<PaymentCollection>(payCol)
|
||||
}
|
||||
Reference in new issue
Block a user