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(medusa): Load PaymentProcessors + integrate in PaymentProviderService #2978

Merged
merged 28 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7c7c5e1
feat: Add payment process support into the loader and payment provider
adrien2p Jan 10, 2023
dc4f155
WIP
adrien2p Jan 11, 2023
4709f45
feat: continue payment provider alignment
adrien2p Jan 11, 2023
d1d1d8c
fix tests and defer payment service resolution
adrien2p Jan 11, 2023
8ab3f5d
continue to add support to payment provider
adrien2p Jan 11, 2023
5608eed
continue to add support to payment provider
adrien2p Jan 11, 2023
d6ca681
fix fixtures
adrien2p Jan 11, 2023
965590a
chore: add updateSessionData unsupported error
adrien2p Jan 26, 2023
46dc0fb
chore: Adress feedback
adrien2p Feb 6, 2023
e6eff20
chore: Adress feedback
adrien2p Feb 6, 2023
f7fe429
chore: fix default loader
adrien2p Feb 6, 2023
e8aa553
Merge branch 'develop' into feat/payment-processor-loader-provider
adrien2p Feb 7, 2023
7d6bce4
Merge branch 'develop' into feat/payment-processor-loader-provider
adrien2p Feb 13, 2023
220caf0
Merge branch 'develop' into feat/payment-processor-loader-provider
adrien2p Feb 14, 2023
4e78c9f
cleanup
adrien2p Feb 15, 2023
8c99d6e
cleanup
adrien2p Feb 15, 2023
0b06836
fix unit tests
adrien2p Feb 15, 2023
83d1808
merge conflicts
adrien2p Feb 16, 2023
55d859a
merge develop amd manage conflcit
adrien2p Feb 17, 2023
f428eab
Create purple-sloths-confess.md
olivermrbl Feb 17, 2023
2565429
address feedback
adrien2p Feb 17, 2023
25229ef
Merge branch 'feat/payment-processor-loader-provider' of github.com:m…
adrien2p Feb 17, 2023
12e06e3
Merge branch 'develop' into feat/payment-processor-loader-provider
adrien2p Feb 20, 2023
bdde1af
minor changes
adrien2p Feb 20, 2023
b41ea20
Merge branch 'develop' into feat/payment-processor-loader-provider
olivermrbl Feb 20, 2023
f1594f0
fix unit test
adrien2p Feb 20, 2023
0113eae
Merge branch 'feat/payment-processor-loader-provider' of github.com:m…
adrien2p Feb 20, 2023
230dc84
Merge branch 'develop' into feat/payment-processor-loader-provider
olivermrbl Feb 20, 2023
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
1 change: 1 addition & 0 deletions packages/medusa/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from "./models/base-entity"
export * from "./models/soft-deletable-entity"
export * from "./search-service"
export * from "./payment-service"
export * from "./payment-processor"
export * from "./services"
81 changes: 56 additions & 25 deletions packages/medusa/src/interfaces/payment-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type PaymentProcessorSessionResponse = {
export interface PaymentProcessorError {
error: string
code: number
details: any
details?: any
}

/**
Expand Down Expand Up @@ -51,55 +51,73 @@ export interface PaymentProcessor {
*/
updatePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
): Promise<PaymentProcessorError | PaymentProcessorSessionResponse | void>

/**
* Refund an existing session
* @param context
* @param paymentSessionData
*/
refundPayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>

/**
* Authorize an existing session if it is not already authorized
* @param paymentSessionData
* @param context
*/
authorizePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>,
context: Record<string, unknown>
): Promise<
| PaymentProcessorError
| {
status: PaymentSessionStatus
data: PaymentProcessorSessionResponse["session_data"]
}
>

/**
* Capture an existing session
* @param context
* @param paymentSessionData
*/
capturePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>

/**
* Delete an existing session
*/
deletePayment(paymentId: string): Promise<PaymentProcessorError | void>
deletePayment(
paymentSessionData: Record<string, unknown>
): Promise<PaymentProcessorError | void>

/**
* Retrieve an existing session
*/
retrievePayment(
paymentId: string
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>

/**
* Cancel an existing session
*/
cancelPayment(paymentId: string): Promise<PaymentProcessorError | void>
cancelPayment(
paymentSessionData: Record<string, unknown>
): Promise<PaymentProcessorError | void>

/**
* Return the status of the session
*/
getPaymentStatus(paymentId: string): Promise<PaymentSessionStatus>
getPaymentStatus(
paymentSessionData: Record<string, unknown>
): Promise<PaymentSessionStatus>
}

/**
Expand All @@ -111,7 +129,7 @@ export abstract class AbstractPaymentProcessor implements PaymentProcessor {
protected readonly config?: Record<string, unknown> // eslint-disable-next-line @typescript-eslint/no-empty-function
) {}

protected static identifier: string
public static identifier: string

public getIdentifier(): string {
const ctr = this.constructor as typeof AbstractPaymentProcessor
Expand All @@ -126,33 +144,46 @@ export abstract class AbstractPaymentProcessor implements PaymentProcessor {
abstract init(): Promise<void>

abstract capturePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>

abstract authorizePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>,
context: Record<string, unknown>
): Promise<
| PaymentProcessorError
| {
status: PaymentSessionStatus
data: PaymentProcessorSessionResponse["session_data"]
}
>

abstract cancelPayment(
paymentId: string
paymentSessionData: Record<string, unknown>
): Promise<PaymentProcessorError | void>

abstract initiatePayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | PaymentProcessorSessionResponse>

abstract deletePayment(
paymentId: string
paymentSessionData: Record<string, unknown>
): Promise<PaymentProcessorError | void>

abstract getPaymentStatus(paymentId: string): Promise<PaymentSessionStatus>
abstract getPaymentStatus(
paymentSessionData: Record<string, unknown>
): Promise<PaymentSessionStatus>

abstract refundPayment(
context: PaymentProcessorContext
): Promise<PaymentProcessorError | void>
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>

abstract retrievePayment(
paymentId: string
paymentSessionData: Record<string, unknown>
): Promise<
PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]
>
Expand Down
4 changes: 3 additions & 1 deletion packages/medusa/src/interfaces/payment-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export type PaymentContext = {
email: string
shipping_address: Address | null
shipping_methods: ShippingMethod[]
billing_address?: Address | null
}
currency_code: string
amount: number
resource_id?: string
customer?: Customer
paymentSessionData: Record<string, unknown>
}

export type PaymentSessionResponse = {
Expand Down Expand Up @@ -148,7 +150,7 @@ export abstract class AbstractPaymentService
super(container, config)
}

protected static identifier: string
public static identifier: string

public getIdentifier(): string {
if (!(this.constructor as typeof AbstractPaymentService).identifier) {
Expand Down
11 changes: 10 additions & 1 deletion packages/medusa/src/loaders/__tests__/default.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { asValue, createContainer } from "awilix";
import { MockRepository, MockManager } from "medusa-test-utils"
import { MockManager, MockRepository } from "medusa-test-utils"
import { StoreServiceMock } from "../../services/__mocks__/store";
import { ShippingProfileServiceMock } from "../../services/__mocks__/shipping-profile";
import Logger from "../logger";
Expand Down Expand Up @@ -33,14 +33,23 @@ describe('default', () => {
paymentProviderService: asValue(PaymentProviderServiceMock),
notificationProviders: asValue([]),
notificationService: asValue({
withTransaction: function () {
return this
},
registerInstalledProviders: jest.fn(),
}),
fulfillmentProviders: asValue([]),
fulfillmentProviderService: asValue({
withTransaction: function () {
return this
},
registerInstalledProviders: jest.fn(),
}),
taxProviders: asValue([]),
taxProviderService: asValue({
withTransaction: function () {
return this
},
registerInstalledProviders: jest.fn(),
}),
})
Expand Down
Loading