diff --git a/.changeset/forty-moons-wash.md b/.changeset/forty-moons-wash.md new file mode 100644 index 0000000000000..0c943d4fdad53 --- /dev/null +++ b/.changeset/forty-moons-wash.md @@ -0,0 +1,5 @@ +--- +"@medusajs/types": patch +--- + +feat: Payment Module service interface diff --git a/packages/types/src/payment/common.ts b/packages/types/src/payment/common.ts new file mode 100644 index 0000000000000..01788395ed35b --- /dev/null +++ b/packages/types/src/payment/common.ts @@ -0,0 +1,30 @@ +import { BaseFilterable } from "../dal" +import { OperatorMap } from "../dal/utils" + +/* ********** PAYMENT COLLECTION ********** */ + +export interface PaymentCollectionDTO { + /** + * The ID of the Payment Collection + */ + id: string +} + +export interface FilterablePaymentCollectionProps + extends BaseFilterable { + id?: string | string[] + + region_id?: string | string[] | OperatorMap + + created_at?: OperatorMap + updated_at?: OperatorMap +} + +/* ********** PAYMENT ********** */ + +export interface PaymentDTO { + /** + * The ID of the Payment Collection + */ + id: string +} diff --git a/packages/types/src/payment/index.ts b/packages/types/src/payment/index.ts index 9376fea807351..a83c8a61ef6d7 100644 --- a/packages/types/src/payment/index.ts +++ b/packages/types/src/payment/index.ts @@ -1 +1,4 @@ +export * from "./common" +export * from "./mutations" export * from "./service" + diff --git a/packages/types/src/payment/mutations.ts b/packages/types/src/payment/mutations.ts new file mode 100644 index 0000000000000..35f72d81dfa9d --- /dev/null +++ b/packages/types/src/payment/mutations.ts @@ -0,0 +1,47 @@ +/** + * TODO + */ + +export interface CreatePaymentCollectionDTO { + region_id: string + currency_code: string + amount: number +} + +export interface UpdatePaymentCollectionDTO + extends Partial {} + +export interface CreatePaymentDTO { + amount: number + currency_code: string + provider_id: string + data: Record + + cart_id?: string + order_id?: string + order_edit_id?: string + customer_id?: string +} + +export interface UpdatePaymentDTO { + cart_id?: string + order_id?: string + order_edit_id?: string + customer_id?: string +} + +export interface CreatePaymentSessionDTO { + amount: number + currency_code: string + provider_id: string + + cart_id?: string + resource_id?: string + customer_id?: string +} + +export interface SetPaymentSessionsDTO { + provider_id: string + amount: number + session_id?: string +} diff --git a/packages/types/src/payment/service.ts b/packages/types/src/payment/service.ts index 80c70e30da2e7..94951f55455c0 100644 --- a/packages/types/src/payment/service.ts +++ b/packages/types/src/payment/service.ts @@ -1,3 +1,131 @@ import { IModuleService } from "../modules-sdk" +import { Context } from "../shared-context" +import { + CreatePaymentCollectionDTO, + CreatePaymentDTO, + CreatePaymentSessionDTO, + SetPaymentSessionsDTO, + UpdatePaymentCollectionDTO, + UpdatePaymentDTO, +} from "./mutations" +import { + FilterablePaymentCollectionProps, + PaymentCollectionDTO, + PaymentDTO, +} from "./common" +import { FindConfig } from "../common" -export interface IPaymentModuleService extends IModuleService {} +export interface IPaymentModuleService extends IModuleService { + /* ********** PAYMENT COLLECTION ********** */ + + createPaymentCollection( + data: CreatePaymentCollectionDTO[], + sharedContext?: Context + ): Promise + createPaymentCollection( + data: CreatePaymentCollectionDTO, + sharedContext?: Context + ): Promise + + retrievePaymentCollection( + paymentCollectionId: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listPaymentCollections( + filters?: FilterablePaymentCollectionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listAndCountPaymentCollections( + filters?: FilterablePaymentCollectionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[PaymentCollectionDTO[], number]> + + updatePaymentCollection( + data: UpdatePaymentCollectionDTO[], + sharedContext?: Context + ): Promise + updatePaymentCollection( + data: UpdatePaymentCollectionDTO, + sharedContext?: Context + ): Promise + + deletePaymentCollection( + paymentCollectionId: string[], + sharedContext?: Context + ): Promise + deletePaymentCollection( + paymentCollectionId: string, + sharedContext?: Context + ): Promise + + authorizePaymentCollection( + paymentCollectionId: string, + sharedContext?: Context + ): Promise + + completePaymentCollection( + paymentCollectionId: string, + sharedContext?: Context + ): Promise + + /* ********** PAYMENT ********** */ + + createPayment(data: CreatePaymentDTO): Promise + createPayment(data: CreatePaymentDTO[]): Promise + + capturePayment( + paymentId: string, + amount: number, + sharedContext?: Context + ): Promise + refundPayment( + paymentId: string, + amount: number, + sharedContext?: Context + ): Promise + + updatePayment( + data: UpdatePaymentDTO, + sharedContext?: Context + ): Promise + updatePayment( + data: UpdatePaymentDTO[], + sharedContext?: Context + ): Promise + + /* ********** PAYMENT SESSION ********** */ + + createPaymentSession( + paymentCollectionId: string, + data: CreatePaymentSessionDTO, + sharedContext?: Context + ): Promise + createPaymentSession( + paymentCollectionId: string, + data: CreatePaymentSessionDTO[], + sharedContext?: Context + ): Promise + + authorizePaymentSessions( + paymentCollectionId: string, + sessionIds: string[], + sharedContext?: Context + ): Promise + + completePaymentSessions( + paymentCollectionId: string, + sessionIds: string[], + sharedContext?: Context + ): Promise + + setPaymentSessions( + paymentCollectionId: string, + data: SetPaymentSessionsDTO[], + sharedContext?: Context + ): Promise +}