From 22254a22c04330ccb6b7623ee986221ae97f3de8 Mon Sep 17 00:00:00 2001 From: fPolic Date: Tue, 16 Jan 2024 10:30:52 +0100 Subject: [PATCH] fix: address feedback partial --- packages/payment/src/models/capture.ts | 2 +- .../payment/src/models/payment-collection.ts | 37 ++++--------------- .../payment/src/models/payment-session.ts | 30 +-------------- packages/payment/src/models/refund.ts | 2 +- packages/utils/src/index.ts | 1 + packages/utils/src/payment/index.ts | 2 + .../utils/src/payment/payment-collection.ts | 27 ++++++++++++++ packages/utils/src/payment/payment-session.ts | 27 ++++++++++++++ 8 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 packages/utils/src/payment/index.ts create mode 100644 packages/utils/src/payment/payment-collection.ts create mode 100644 packages/utils/src/payment/payment-session.ts diff --git a/packages/payment/src/models/capture.ts b/packages/payment/src/models/capture.ts index 9952342db1..f180fa21d5 100644 --- a/packages/payment/src/models/capture.ts +++ b/packages/payment/src/models/capture.ts @@ -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_by" | "created_at" @Entity({ tableName: "capture" }) export default class Capture { diff --git a/packages/payment/src/models/payment-collection.ts b/packages/payment/src/models/payment-collection.ts index e844224381..9b5985fdbf 100644 --- a/packages/payment/src/models/payment-collection.ts +++ b/packages/payment/src/models/payment-collection.ts @@ -14,44 +14,21 @@ import { } from "@mikro-orm/core" import { DAL } from "@medusajs/types" -import { DALUtils, generateEntityId } from "@medusajs/utils" +import { + DALUtils, + generateEntityId, + 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" + | "status" | DAL.SoftDeletableEntityDateColumns @Entity({ tableName: "payment_collection" }) @@ -120,7 +97,7 @@ export default class PaymentCollection { items: () => PaymentCollectionStatus, default: PaymentCollectionStatus.NOT_PAID, }) - status: PaymentCollectionStatus = PaymentCollectionStatus.NOT_PAID + status?: PaymentCollectionStatus = PaymentCollectionStatus.NOT_PAID @ManyToMany(() => PaymentProvider) payment_providers = new Collection(this) diff --git a/packages/payment/src/models/payment-session.ts b/packages/payment/src/models/payment-session.ts index ca0a4e8f5f..387a702490 100644 --- a/packages/payment/src/models/payment-session.ts +++ b/packages/payment/src/models/payment-session.ts @@ -10,39 +10,11 @@ import { 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" diff --git a/packages/payment/src/models/refund.ts b/packages/payment/src/models/refund.ts index 6da06d2c16..59cda86f3a 100644 --- a/packages/payment/src/models/refund.ts +++ b/packages/payment/src/models/refund.ts @@ -11,7 +11,7 @@ import { import { generateEntityId } from "@medusajs/utils" import Payment from "./payment" -type OptionalRefundProps = "created_by" | "completed_at" +type OptionalRefundProps = "created_by" @Entity({ tableName: "refund" }) export default class Refund { diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 7674050a26..5f96dcb3dd 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -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" diff --git a/packages/utils/src/payment/index.ts b/packages/utils/src/payment/index.ts new file mode 100644 index 0000000000..e5e483a8d5 --- /dev/null +++ b/packages/utils/src/payment/index.ts @@ -0,0 +1,2 @@ +export * from "./payment-collection" +export * from "./payment-session" diff --git a/packages/utils/src/payment/payment-collection.ts b/packages/utils/src/payment/payment-collection.ts new file mode 100644 index 0000000000..600445705f --- /dev/null +++ b/packages/utils/src/payment/payment-collection.ts @@ -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", +} diff --git a/packages/utils/src/payment/payment-session.ts b/packages/utils/src/payment/payment-session.ts new file mode 100644 index 0000000000..d65005fc92 --- /dev/null +++ b/packages/utils/src/payment/payment-session.ts @@ -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", +}