feat(medusa,medusa-payment-stripe): Move database mutation from plugin to core (#2743)
**what** The goal of that PR is to first refactor the payment provider and payment plugin to support the new API that removes the data mutation from within the plugin to be done by the core instead. In any case, this pr does not include the steps of the deeper refactoring. The last part will come in later pr. **How** - The payment plugin is now capable to handle both the deprecated and new API and the plugin works the same as it use to works. - The mutation made by the plugin have been moved into the core as well as the subscriber - The tests have been updated to reflect the changed - Remove all new methods introduced by the payment collections - Mutualise types - Update provider and payment collection services - cleanup around all those refactoring including cleanup of the payment collection - refactor stripe payment plugin FIXES CORE-887
This commit is contained in:
@@ -1,18 +1,38 @@
|
||||
import { TransactionBaseService } from "./transaction-base-service"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
Customer,
|
||||
Payment,
|
||||
PaymentSession,
|
||||
PaymentSessionStatus,
|
||||
ShippingMethod,
|
||||
} from "../models"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
import { PaymentProviderDataInput } from "../types/payment-collection"
|
||||
|
||||
export type Data = Record<string, unknown>
|
||||
export type PaymentData = Data
|
||||
export type PaymentSessionData = Data
|
||||
|
||||
export type PaymentContext = {
|
||||
cart: {
|
||||
context: Record<string, unknown>
|
||||
id: string
|
||||
email: string
|
||||
shipping_address: Address | null
|
||||
shipping_methods: ShippingMethod[]
|
||||
}
|
||||
currency_code: string
|
||||
amount: number
|
||||
resource_id?: string
|
||||
customer?: Customer
|
||||
}
|
||||
|
||||
export type PaymentSessionResponse = {
|
||||
update_requests: { customer_metadata: Record<string, unknown> }
|
||||
session_data: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface PaymentService extends TransactionBaseService {
|
||||
getIdentifier(): string
|
||||
|
||||
@@ -23,6 +43,16 @@ export interface PaymentService extends TransactionBaseService {
|
||||
data: Data
|
||||
): Promise<PaymentSessionData>
|
||||
|
||||
/**
|
||||
* @param context The type of this argument is meant to be temporary and once the previous method signature
|
||||
* will be removed, the type will only be PaymentContext instead of Cart & PaymentContext
|
||||
*/
|
||||
createPayment(context: Cart & PaymentContext): Promise<PaymentSessionResponse>
|
||||
|
||||
/**
|
||||
* @deprecated use createPayment(context: Cart & PaymentContext): Promise<PaymentSessionResponse> instead
|
||||
* @param cart
|
||||
*/
|
||||
createPayment(cart: Cart): Promise<PaymentSessionData>
|
||||
|
||||
retrievePayment(paymentData: PaymentData): Promise<Data>
|
||||
@@ -76,23 +106,42 @@ export abstract class AbstractPaymentService
|
||||
data: Data
|
||||
): Promise<PaymentSessionData>
|
||||
|
||||
/**
|
||||
* @param context The type of this argument is meant to be temporary and once the previous method signature
|
||||
* will be removed, the type will only be PaymentContext instead of Cart & PaymentContext
|
||||
*/
|
||||
public abstract createPayment(
|
||||
context: Cart & PaymentContext
|
||||
): Promise<PaymentSessionResponse>
|
||||
|
||||
/**
|
||||
* @deprecated use createPayment(context: Cart & PaymentContext): Promise<PaymentSessionResponse> instead
|
||||
* @param cart
|
||||
*/
|
||||
public abstract createPayment(cart: Cart): Promise<PaymentSessionData>
|
||||
public abstract createPaymentNew(
|
||||
paymentInput: PaymentProviderDataInput
|
||||
): Promise<PaymentSessionData>
|
||||
|
||||
public abstract retrievePayment(paymentData: PaymentData): Promise<Data>
|
||||
|
||||
/**
|
||||
* @param paymentSessionData
|
||||
* @param context The type of this argument is meant to be temporary and once the previous method signature
|
||||
* will be removed, the type will only be PaymentContext instead of Cart & PaymentContext
|
||||
*/
|
||||
public abstract updatePayment(
|
||||
paymentSessionData: PaymentSessionData,
|
||||
context: Cart & PaymentContext
|
||||
): Promise<PaymentSessionResponse>
|
||||
|
||||
/**
|
||||
* @deprecated use updatePayment(paymentSessionData: PaymentSessionData, context: Cart & PaymentContext): Promise<PaymentSessionResponse> instead
|
||||
* @param paymentSessionData
|
||||
* @param cart
|
||||
*/
|
||||
public abstract updatePayment(
|
||||
paymentSessionData: PaymentSessionData,
|
||||
cart: Cart
|
||||
): Promise<PaymentSessionData>
|
||||
|
||||
public abstract updatePaymentNew(
|
||||
paymentSessionData: PaymentSessionData,
|
||||
paymentInput: PaymentProviderDataInput
|
||||
): Promise<PaymentSessionData>
|
||||
|
||||
public abstract authorizePayment(
|
||||
paymentSession: PaymentSession,
|
||||
context: Data
|
||||
|
||||
Reference in New Issue
Block a user