|
1
|
import { model } from "@medusajs/framework/utils" |
|
2
|
import Capture from "./capture" |
|
3
|
import PaymentCollection from "./payment-collection" |
|
4
|
import PaymentSession from "./payment-session" |
|
5
|
import Refund from "./refund" |
|
6
|
|
|
7
|
// TODO: We should remove the `Payment` model and use the `PaymentSession` model instead. |
|
8
|
// We just need to move the refunds, captures, canceled_at, and captured_at to it. |
|
9
|
const Payment = model |
|
10
|
.define("Payment", { |
|
11
|
id: model.id({ prefix: "pay" }).primaryKey(), |
|
12
|
amount: model.bigNumber(), |
|
13
|
currency_code: model.text(), |
|
14
|
provider_id: model.text(), |
|
15
|
data: model.json().nullable(), |
|
16
|
metadata: model.json().nullable(), |
|
17
|
captured_at: model.dateTime().nullable(), |
|
18
|
canceled_at: model.dateTime().nullable(), |
|
19
|
payment_collection: model.belongsTo(() => PaymentCollection, { |
|
20
|
mappedBy: "payments", |
|
21
|
}), |
|
22
|
payment_session: model.belongsTo(() => PaymentSession, { |
|
23
|
mappedBy: "payment", |
|
24
|
}), |
|
25
|
refunds: model.hasMany(() => Refund, { |
|
26
|
mappedBy: "payment", |
|
27
|
}), |
|
28
|
captures: model.hasMany(() => Capture, { |
|
29
|
mappedBy: "payment", |
|
30
|
}), |
|
31
|
}) |
|
32
|
.cascades({ |
|
33
|
delete: ["refunds", "captures"], |
|
34
|
}) |
|
35
|
.indexes([ |
|
36
|
{ |
|
37
|
name: "IDX_payment_provider_id", |
|
38
|
on: ["provider_id"], |
|
39
|
}, |
|
40
|
{ |
|
41
|
name: "IDX_payment_payment_collection_id", |
|
42
|
on: ["payment_collection_id"], |
|
43
|
}, |
|
44
|
{ |
|
45
|
name: "IDX_payment_payment_session_id", |
|
46
|
on: ["payment_session_id"], |
|
47
|
}, |
|
48
|
]) |
|
49
|
|
|
50
|
export default Payment |