Files
medusa-store/integration-tests/factories/simple-payment-factory.ts.txt
Riqwan Thamir 0573bb924a chore: Remove typeORM (#9005)
* chore: rename js files to txt

* chore: rename ts files to txt

* chore: delete environment helpers

* chore: convert global setup & teardown to txt

* chore: rename helper js/ts files to txt

* chore: rename seeder js/ts files to txt

* chore: remove typeorm

* chore: reintroduce used helpers
2024-09-05 15:45:30 +02:00

44 lines
999 B
Plaintext

import { DataSource } from "typeorm"
import { Payment } from "@medusajs/medusa"
export type PaymentFactoryData = {
provider_id?: string
order?: string
cart?: string
data?: any
amount?: number
currency_code?: string
captured?: Date | boolean
}
export const simplePaymentFactory = async (
dataSource: DataSource,
data: PaymentFactoryData,
_?: number
): Promise<Payment> => {
const manager = dataSource.manager
let captured_at = data.captured
if (typeof captured_at === "boolean") {
if (captured_at) {
captured_at = new Date()
} else {
captured_at = null
}
} else if (typeof captured_at === "undefined") {
captured_at = null
}
const address = manager.create(Payment, {
provider_id: data.provider_id ?? "test-pay",
order_id: data.order,
cart_id: data.cart,
data: data.data ?? {},
amount: data.amount ?? 1000,
currency_code: data.currency_code ?? "usd",
captured_at,
})
return await manager.save(address)
}