Merge branch 'feat/payment-module-models' into feat/payment-module-interfaces
# Conflicts: # packages/payment/src/models/payment.ts
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import Payment from "./payment"
|
||||
|
||||
type OptionalCaptureProps = "created_by" | "created_at" | "completed_at"
|
||||
type OptionalCaptureProps = "created_at"
|
||||
|
||||
@Entity({ tableName: "capture" })
|
||||
export default class Capture {
|
||||
@@ -41,7 +41,7 @@ export default class Capture {
|
||||
created_at: Date
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
created_by: string | null
|
||||
created_by?: string | null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
|
||||
@@ -14,45 +14,17 @@ import {
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
|
||||
import { DALUtils, generateEntityId } from "@medusajs/utils"
|
||||
import {
|
||||
DALUtils,
|
||||
generateEntityId,
|
||||
optionalNumericSerializer,
|
||||
PaymentCollectionStatus,
|
||||
} from "@medusajs/utils"
|
||||
import PaymentProvider from "./payment-provider"
|
||||
import PaymentSession from "./payment-session"
|
||||
import Payment from "./payment"
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The payment collection's status.
|
||||
*/
|
||||
export enum PaymentCollectionStatus {
|
||||
/**
|
||||
* The payment collection isn't paid.
|
||||
*/
|
||||
NOT_PAID = "not_paid",
|
||||
/**
|
||||
* The payment collection is awaiting payment.
|
||||
*/
|
||||
AWAITING = "awaiting",
|
||||
/**
|
||||
* The payment collection is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* Some of the payments in the payment collection are authorized.
|
||||
*/
|
||||
PARTIALLY_AUTHORIZED = "partially_authorized",
|
||||
/**
|
||||
* The payment collection is canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
|
||||
type OptionalPaymentCollectionProps =
|
||||
| "authorized_amount"
|
||||
| "refunded_amount"
|
||||
| "region_id"
|
||||
| "completed_at"
|
||||
| DAL.SoftDeletableEntityDateColumns
|
||||
type OptionalPaymentCollectionProps = "status" | DAL.EntityDateColumns
|
||||
|
||||
@Entity({ tableName: "payment_collection" })
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
@@ -74,16 +46,16 @@ export default class PaymentCollection {
|
||||
@Property({
|
||||
columnType: "numeric",
|
||||
nullable: true,
|
||||
serializer: Number,
|
||||
serializer: optionalNumericSerializer,
|
||||
})
|
||||
authorized_amount: number | null
|
||||
authorized_amount?: number | null
|
||||
|
||||
@Property({
|
||||
columnType: "numeric",
|
||||
nullable: true,
|
||||
serializer: Number,
|
||||
serializer: optionalNumericSerializer,
|
||||
})
|
||||
refunded_amount: number | null
|
||||
refunded_amount?: number | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
region_id?: string | null
|
||||
@@ -108,13 +80,13 @@ export default class PaymentCollection {
|
||||
nullable: true,
|
||||
index: "IDX_payment_collection_deleted_at",
|
||||
})
|
||||
deleted_at: Date | null
|
||||
deleted_at?: Date | null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
completed_at: Date | null
|
||||
completed_at?: Date | null
|
||||
|
||||
@Enum({
|
||||
items: () => PaymentCollectionStatus,
|
||||
|
||||
@@ -2,23 +2,14 @@ import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
|
||||
type OptionalPaymentMethodTokenProps =
|
||||
| "data"
|
||||
| "type_detail"
|
||||
| "description_detail"
|
||||
| "metadata"
|
||||
|
||||
@Entity({ tableName: "payment_method_token" })
|
||||
export default class PaymentMethodToken {
|
||||
[OptionalProps]?: OptionalPaymentMethodTokenProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@@ -32,21 +23,21 @@ export default class PaymentMethodToken {
|
||||
name: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
type_detail: string | null
|
||||
type_detail?: string | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
description_detail: string | null
|
||||
description_detail?: string | null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata?: Record<string, unknown> | null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "paymt")
|
||||
this.id = generateEntityId(this.id, "paymttok")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "paymt")
|
||||
this.id = generateEntityId(this.id, "paymttok")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Entity, PrimaryKey, Property } from "@mikro-orm/core"
|
||||
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
|
||||
|
||||
|
||||
@@ -5,54 +5,16 @@ import {
|
||||
ManyToOne,
|
||||
OneToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import { DAL } from "@medusajs/types"
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import { generateEntityId, PaymentSessionStatus } from "@medusajs/utils"
|
||||
|
||||
import PaymentCollection from "./payment-collection"
|
||||
import Payment from "./payment"
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The status of a payment session.
|
||||
*/
|
||||
export enum PaymentSessionStatus {
|
||||
/**
|
||||
* The payment is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* The payment is pending.
|
||||
*/
|
||||
PENDING = "pending",
|
||||
/**
|
||||
* The payment requires an action.
|
||||
*/
|
||||
REQUIRES_MORE = "requires_more",
|
||||
/**
|
||||
* An error occurred while processing the payment.
|
||||
*/
|
||||
ERROR = "error",
|
||||
/**
|
||||
* The payment is canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
|
||||
type OptionalPaymentSessionProps =
|
||||
| "data"
|
||||
| "is_selected"
|
||||
| "authorized_at"
|
||||
| DAL.EntityDateColumns
|
||||
|
||||
@Entity({ tableName: "payment_session" })
|
||||
export default class PaymentSession {
|
||||
[OptionalProps]?: OptionalPaymentSessionProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@@ -77,13 +39,13 @@ export default class PaymentSession {
|
||||
status: PaymentSessionStatus
|
||||
|
||||
@Property({ columnType: "boolean", nullable: true })
|
||||
is_selected: boolean | null
|
||||
is_selected?: boolean | null
|
||||
|
||||
@Property({
|
||||
columnType: "timestamptz",
|
||||
nullable: true,
|
||||
})
|
||||
authorized_at: Date | null
|
||||
authorized_at?: Date | null
|
||||
|
||||
@ManyToOne({
|
||||
index: "IDX_payment_session_payment_collection_id",
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
OptionalProps,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
@@ -11,12 +10,8 @@ import {
|
||||
import { generateEntityId } from "@medusajs/utils"
|
||||
import Payment from "./payment"
|
||||
|
||||
type OptionalRefundProps = "created_by" | "completed_at"
|
||||
|
||||
@Entity({ tableName: "refund" })
|
||||
export default class Refund {
|
||||
[OptionalProps]?: OptionalRefundProps
|
||||
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@@ -41,7 +36,7 @@ export default class Refund {
|
||||
created_at: Date
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
created_by: string | null
|
||||
created_by?: string | null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
|
||||
@@ -5,6 +5,7 @@ export * from "./decorators"
|
||||
export * from "./event-bus"
|
||||
export * from "./feature-flags"
|
||||
export * from "./modules-sdk"
|
||||
export * from "./payment"
|
||||
export * from "./pricing"
|
||||
export * from "./product"
|
||||
export * from "./promotion"
|
||||
|
||||
2
packages/utils/src/payment/index.ts
Normal file
2
packages/utils/src/payment/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./payment-collection"
|
||||
export * from "./payment-session"
|
||||
27
packages/utils/src/payment/payment-collection.ts
Normal file
27
packages/utils/src/payment/payment-collection.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The payment collection's status.
|
||||
*/
|
||||
export enum PaymentCollectionStatus {
|
||||
/**
|
||||
* The payment collection isn't paid.
|
||||
*/
|
||||
NOT_PAID = "not_paid",
|
||||
/**
|
||||
* The payment collection is awaiting payment.
|
||||
*/
|
||||
AWAITING = "awaiting",
|
||||
/**
|
||||
* The payment collection is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* Some of the payments in the payment collection are authorized.
|
||||
*/
|
||||
PARTIALLY_AUTHORIZED = "partially_authorized",
|
||||
/**
|
||||
* The payment collection is canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
27
packages/utils/src/payment/payment-session.ts
Normal file
27
packages/utils/src/payment/payment-session.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The status of a payment session.
|
||||
*/
|
||||
export enum PaymentSessionStatus {
|
||||
/**
|
||||
* The payment is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* The payment is pending.
|
||||
*/
|
||||
PENDING = "pending",
|
||||
/**
|
||||
* The payment requires an action.
|
||||
*/
|
||||
REQUIRES_MORE = "requires_more",
|
||||
/**
|
||||
* An error occurred while processing the payment.
|
||||
*/
|
||||
ERROR = "error",
|
||||
/**
|
||||
* The payment is canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
Reference in New Issue
Block a user