1 import { model, PaymentCollectionStatus } from "@medusajs/framework/utils"
2 import Payment from "./payment"
3 import PaymentProvider from "./payment-provider"
4 import PaymentSession from "./payment-session"
5
6 const PaymentCollection = model
7 .define("PaymentCollection", {
8 id: model.id({ prefix: "pay_col" }).primaryKey(),
9 currency_code: model.text(),
10 amount: model.bigNumber(),
11 authorized_amount: model.bigNumber().nullable(),
12 captured_amount: model.bigNumber().nullable(),
13 refunded_amount: model.bigNumber().nullable(),
14 completed_at: model.dateTime().nullable(),
15 status: model
16 .enum(PaymentCollectionStatus)
17 .default(PaymentCollectionStatus.NOT_PAID),
18 metadata: model.json().nullable(),
19 payment_providers: model.manyToMany(() => PaymentProvider, {
20 mappedBy: "payment_collections",
21 }),
22 payment_sessions: model.hasMany(() => PaymentSession, {
23 mappedBy: "payment_collection",
24 }),
25 payments: model.hasMany(() => Payment, {
26 mappedBy: "payment_collection",
27 }),
28 })
29 .cascades({
30 delete: ["payment_sessions", "payments"],
31 })
32
33 export default PaymentCollection