Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Payment module interface #6092

Merged
merged 41 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
824bcce
feat: Payment module package setup
fPolic Jan 11, 2024
c9f1858
fix: missing files
fPolic Jan 11, 2024
85e4e6c
fix: changesets
fPolic Jan 11, 2024
8a5888a
feat: Payment models
fPolic Jan 11, 2024
9e72d25
feat: migration
fPolic Jan 11, 2024
b601212
Merge branch 'develop' into feat/payment-module-models
fPolic Jan 11, 2024
1b882a9
feat: optional props, update fields
fPolic Jan 12, 2024
f2a4f45
fix: Refund/Capture delete, add indexes
fPolic Jan 12, 2024
00ee67c
chore: refactor
fPolic Jan 12, 2024
a7f74bd
fix: add missing indexes
fPolic Jan 12, 2024
aabe164
fix: partial feedback address
fPolic Jan 15, 2024
1d82294
fix: currency code
fPolic Jan 15, 2024
efdc59f
Merge branch 'develop' into feat/payment-module-models
fPolic Jan 15, 2024
5675203
wip: interface and types
fPolic Jan 15, 2024
fbd3fed
wip: service
fPolic Jan 15, 2024
89d6d7e
fix: add order_edit_id to Payment
fPolic Jan 15, 2024
66ec3d0
wip: session methods
fPolic Jan 15, 2024
1cc888d
feat: Sessions API update
fPolic Jan 16, 2024
fc6b177
chore: changeset
fPolic Jan 16, 2024
22254a2
fix: address feedback partial
fPolic Jan 16, 2024
bc7829d
fix: update models
fPolic Jan 16, 2024
eab0ca4
fix: serializer
fPolic Jan 16, 2024
67acdcd
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 16, 2024
33e5b7f
fix: Payment merge
fPolic Jan 16, 2024
dcdb6df
fix: `listPaymentCollections` shape
fPolic Jan 16, 2024
ca0d6f5
fix: method overloads
fPolic Jan 16, 2024
ef7f51a
fix: remove is selected
fPolic Jan 17, 2024
e4438ae
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 17, 2024
6341533
fix: region id
fPolic Jan 17, 2024
dfcb5e7
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 17, 2024
57b8896
fix: update DTO
fPolic Jan 17, 2024
aa1585b
feat: add region index
fPolic Jan 17, 2024
e7d8c53
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 17, 2024
d5af7cc
fix: add column type
fPolic Jan 18, 2024
a6aa09a
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 18, 2024
8154408
fix: change type
fPolic Jan 18, 2024
c332375
chore: update fields to new convention
fPolic Jan 18, 2024
af61195
Merge branch 'develop' into feat/payment-module-models
fPolic Jan 18, 2024
491848b
Merge branch 'develop' into feat/payment-module-models
fPolic Jan 18, 2024
8e4e6b0
Merge branch 'feat/payment-module-models' into feat/payment-module-in…
fPolic Jan 18, 2024
16945f4
Merge branch 'develop' into feat/payment-module-interfaces
fPolic Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-moons-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/types": patch
---

feat: Payment Module service interface
55 changes: 55 additions & 0 deletions packages/payment/src/models/capture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
BeforeCreate,
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"

import { generateEntityId } from "@medusajs/utils"
import Payment from "./payment"

type OptionalCaptureProps = "created_at"

@Entity({ tableName: "capture" })
export default class Capture {
[OptionalProps]?: OptionalCaptureProps

@PrimaryKey({ columnType: "text" })
id: string

@Property({
columnType: "numeric",
serializer: Number,
})
amount: number

@ManyToOne(() => Payment, {
onDelete: "cascade",
index: "IDX_capture_payment_id",
fieldName: "payment_id",
})
payment: Payment

@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date

@Property({ columnType: "text", nullable: true })
created_by?: string | null

@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "capt")
}

@OnInit()
onInit() {
this.id = generateEntityId(this.id, "capt")
}
}
6 changes: 6 additions & 0 deletions packages/payment/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { default as Capture } from "./capture"
export { default as Payment } from "./payment"
export { default as PaymentCollection } from "./payment-collection"
export { default as PaymentMethodToken } from "./payment-method-token"
export { default as PaymentProvider } from "./payment-provider"
export { default as PaymentSession } from "./payment-session"
export { default as Refund } from "./refund"
119 changes: 119 additions & 0 deletions packages/payment/src/models/payment-collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Enum,
Filter,
ManyToMany,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { DAL } from "@medusajs/types"

import {
DALUtils,
generateEntityId,
optionalNumericSerializer,
PaymentCollectionStatus,
} from "@medusajs/utils"
import PaymentProvider from "./payment-provider"
import PaymentSession from "./payment-session"
import Payment from "./payment"

type OptionalPaymentCollectionProps = "status" | DAL.EntityDateColumns

@Entity({ tableName: "payment_collection" })
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class PaymentCollection {
[OptionalProps]?: OptionalPaymentCollectionProps

@PrimaryKey({ columnType: "text" })
id: string

@Property({ columnType: "text" })
currency_code: string

@Property({
columnType: "numeric",
serializer: Number,
})
amount: number

@Property({
columnType: "numeric",
nullable: true,
serializer: optionalNumericSerializer,
})
authorized_amount?: number | null

@Property({
columnType: "numeric",
nullable: true,
serializer: optionalNumericSerializer,
})
refunded_amount?: number | null

@Property({ columnType: "text", nullable: true })
region_id?: string | null

@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date

@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date

@Property({
columnType: "timestamptz",
nullable: true,
index: "IDX_payment_collection_deleted_at",
})
deleted_at?: Date | null

@Property({
columnType: "timestamptz",
nullable: true,
})
completed_at?: Date | null

@Enum({
items: () => PaymentCollectionStatus,
default: PaymentCollectionStatus.NOT_PAID,
})
status: PaymentCollectionStatus = PaymentCollectionStatus.NOT_PAID

@ManyToMany(() => PaymentProvider)
payment_providers = new Collection<PaymentProvider>(this)

@OneToMany(() => PaymentSession, (ps) => ps.payment_collection, {
cascade: [Cascade.REMOVE],
})
payment_sessions = new Collection<PaymentSession>(this)

@OneToMany(() => Payment, (payment) => payment.payment_collection, {
cascade: [Cascade.REMOVE],
})
payments = new Collection<Payment>(this)

@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "pay_col")
}

@OnInit()
onInit() {
this.id = generateEntityId(this.id, "pay_col")
}
}
43 changes: 43 additions & 0 deletions packages/payment/src/models/payment-method-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
BeforeCreate,
Entity,
OnInit,
PrimaryKey,
Property,
} from "@mikro-orm/core"

import { generateEntityId } from "@medusajs/utils"

@Entity({ tableName: "payment_method_token" })
export default class PaymentMethodToken {
@PrimaryKey({ columnType: "text" })
id: string

@Property({ columnType: "text" })
provider_id: string

@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null

@Property({ columnType: "text" })
name: string

@Property({ columnType: "text", nullable: true })
type_detail?: string | null

@Property({ columnType: "text", nullable: true })
description_detail?: string | null

@Property({ columnType: "jsonb", nullable: true })
metadata?: Record<string, unknown> | null

@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "paymttok")
}

@OnInit()
onInit() {
this.id = generateEntityId(this.id, "paymttok")
}
}
14 changes: 14 additions & 0 deletions packages/payment/src/models/payment-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Entity, OptionalProps, PrimaryKey, Property } from "@mikro-orm/core"

@Entity({ tableName: "payment_provider" })
export default class PaymentProvider {
[OptionalProps]?: "is_enabled"

@PrimaryKey({ columnType: "text" })
id: string

@Property({
default: true,
})
is_enabled: boolean = true
}
72 changes: 72 additions & 0 deletions packages/payment/src/models/payment-session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
BeforeCreate,
Entity,
Enum,
ManyToOne,
OneToOne,
OnInit,
PrimaryKey,
Property,
} from "@mikro-orm/core"
import { generateEntityId, PaymentSessionStatus } from "@medusajs/utils"

import PaymentCollection from "./payment-collection"
import Payment from "./payment"

@Entity({ tableName: "payment_session" })
export default class PaymentSession {
@PrimaryKey({ columnType: "text" })
id: string

@Property({ columnType: "text" })
currency_code: string

@Property({
columnType: "numeric",
serializer: Number,
})
amount: number

@Property({ columnType: "text" })
provider_id: string

@Property({ columnType: "jsonb", nullable: true })
data?: Record<string, unknown> | null

@Enum({
items: () => PaymentSessionStatus,
})
status: PaymentSessionStatus

@Property({ columnType: "boolean", nullable: true })
is_selected?: boolean | null

@Property({
columnType: "timestamptz",
nullable: true,
})
authorized_at?: Date | null

@ManyToOne({
index: "IDX_payment_session_payment_collection_id",
fieldName: "payment_collection_id",
})
payment_collection!: PaymentCollection

@OneToOne({
entity: () => Payment,
mappedBy: (payment) => payment.session,
cascade: ["soft-remove"] as any,
})
payment!: Payment

@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "payses")
}

@OnInit()
onInit() {
this.id = generateEntityId(this.id, "payses")
}
}
Loading