Skip to content

Commit

Permalink
Merge pull request #6092 from medusajs/feat/payment-module-interfaces
Browse files Browse the repository at this point in the history
feat: Payment module interface
  • Loading branch information
fPolic authored Jan 18, 2024
2 parents 844a5d9 + 16945f4 commit 6941627
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 1 deletion.
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
30 changes: 30 additions & 0 deletions packages/types/src/payment/common.ts
Original file line number Diff line number Diff line change
@@ -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<PaymentCollectionDTO> {
id?: string | string[]

region_id?: string | string[] | OperatorMap<string>

created_at?: OperatorMap<string>
updated_at?: OperatorMap<string>
}

/* ********** PAYMENT ********** */

export interface PaymentDTO {
/**
* The ID of the Payment Collection
*/
id: string
}
3 changes: 3 additions & 0 deletions packages/types/src/payment/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from "./common"
export * from "./mutations"
export * from "./service"

47 changes: 47 additions & 0 deletions packages/types/src/payment/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* TODO
*/

export interface CreatePaymentCollectionDTO {
region_id: string
currency_code: string
amount: number
}

export interface UpdatePaymentCollectionDTO
extends Partial<CreatePaymentCollectionDTO> {}

export interface CreatePaymentDTO {
amount: number
currency_code: string
provider_id: string
data: Record<string, unknown>

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
}
130 changes: 129 additions & 1 deletion packages/types/src/payment/service.ts
Original file line number Diff line number Diff line change
@@ -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<PaymentCollectionDTO[]>
createPaymentCollection(
data: CreatePaymentCollectionDTO,
sharedContext?: Context
): Promise<PaymentCollectionDTO>

retrievePaymentCollection(
paymentCollectionId: string,
config?: FindConfig<PaymentCollectionDTO>,
sharedContext?: Context
): Promise<PaymentCollectionDTO>

listPaymentCollections(
filters?: FilterablePaymentCollectionProps,
config?: FindConfig<PaymentCollectionDTO>,
sharedContext?: Context
): Promise<PaymentCollectionDTO[]>

listAndCountPaymentCollections(
filters?: FilterablePaymentCollectionProps,
config?: FindConfig<PaymentCollectionDTO>,
sharedContext?: Context
): Promise<[PaymentCollectionDTO[], number]>

updatePaymentCollection(
data: UpdatePaymentCollectionDTO[],
sharedContext?: Context
): Promise<PaymentCollectionDTO[]>
updatePaymentCollection(
data: UpdatePaymentCollectionDTO,
sharedContext?: Context
): Promise<PaymentCollectionDTO>

deletePaymentCollection(
paymentCollectionId: string[],
sharedContext?: Context
): Promise<void>
deletePaymentCollection(
paymentCollectionId: string,
sharedContext?: Context
): Promise<void>

authorizePaymentCollection(
paymentCollectionId: string,
sharedContext?: Context
): Promise<PaymentCollectionDTO>

completePaymentCollection(
paymentCollectionId: string,
sharedContext?: Context
): Promise<PaymentCollectionDTO>

/* ********** PAYMENT ********** */

createPayment(data: CreatePaymentDTO): Promise<PaymentDTO>
createPayment(data: CreatePaymentDTO[]): Promise<PaymentDTO[]>

capturePayment(
paymentId: string,
amount: number,
sharedContext?: Context
): Promise<PaymentDTO>
refundPayment(
paymentId: string,
amount: number,
sharedContext?: Context
): Promise<PaymentDTO>

updatePayment(
data: UpdatePaymentDTO,
sharedContext?: Context
): Promise<PaymentDTO>
updatePayment(
data: UpdatePaymentDTO[],
sharedContext?: Context
): Promise<PaymentDTO[]>

/* ********** PAYMENT SESSION ********** */

createPaymentSession(
paymentCollectionId: string,
data: CreatePaymentSessionDTO,
sharedContext?: Context
): Promise<PaymentCollectionDTO>
createPaymentSession(
paymentCollectionId: string,
data: CreatePaymentSessionDTO[],
sharedContext?: Context
): Promise<PaymentCollectionDTO>

authorizePaymentSessions(
paymentCollectionId: string,
sessionIds: string[],
sharedContext?: Context
): Promise<PaymentCollectionDTO>

completePaymentSessions(
paymentCollectionId: string,
sessionIds: string[],
sharedContext?: Context
): Promise<PaymentCollectionDTO>

setPaymentSessions(
paymentCollectionId: string,
data: SetPaymentSessionsDTO[],
sharedContext?: Context
): Promise<PaymentCollectionDTO>
}

0 comments on commit 6941627

Please sign in to comment.