feat(payment, payment-stripe): Add Stripe module provider (#6311)
This commit is contained in:
@@ -5,9 +5,13 @@ import {
|
||||
PaymentProviderError,
|
||||
PaymentProviderSessionResponse,
|
||||
PaymentSessionStatus,
|
||||
ProviderWebhookPayload,
|
||||
WebhookActionResult,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export abstract class AbstractPaymentProvider implements IPaymentProvider {
|
||||
export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
|
||||
implements IPaymentProvider
|
||||
{
|
||||
/**
|
||||
* You can use the `constructor` of your Payment Provider to have access to different services in Medusa through [dependency injection](https://docs.medusajs.com/development/fundamentals/dependency-injection).
|
||||
*
|
||||
@@ -38,7 +42,7 @@ export abstract class AbstractPaymentProvider implements IPaymentProvider {
|
||||
*/
|
||||
protected constructor(
|
||||
protected readonly container: MedusaContainer,
|
||||
protected readonly config?: Record<string, unknown> // eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
protected readonly config: TConfig = {} as TConfig // eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -126,8 +130,18 @@ export abstract class AbstractPaymentProvider implements IPaymentProvider {
|
||||
abstract updatePayment(
|
||||
context: PaymentProviderContext
|
||||
): Promise<PaymentProviderError | PaymentProviderSessionResponse>
|
||||
|
||||
abstract getWebhookActionAndData(
|
||||
data: ProviderWebhookPayload["payload"]
|
||||
): Promise<WebhookActionResult>
|
||||
}
|
||||
|
||||
export function isPaymentProviderError(obj: any): obj is PaymentProviderError {
|
||||
return obj && typeof obj === "object" && obj.error && obj.code && obj.detail
|
||||
return (
|
||||
obj &&
|
||||
typeof obj === "object" &&
|
||||
"error" in obj &&
|
||||
"code" in obj &&
|
||||
"detail" in obj
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./abstract-payment-provider"
|
||||
export * from "./payment-collection"
|
||||
export * from "./payment-session"
|
||||
export * from "./abstract-payment-provider"
|
||||
export * from "./webhook"
|
||||
|
||||
25
packages/utils/src/payment/webhook.ts
Normal file
25
packages/utils/src/payment/webhook.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export enum PaymentWebhookEvents {
|
||||
WebhookReceived = "payment.webhook_received",
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalized events from payment provider to internal payment module events.
|
||||
*/
|
||||
export enum PaymentActions {
|
||||
/**
|
||||
* Payment session has been authorized and there are available funds for capture.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* Payment was successful and the mount is captured.
|
||||
*/
|
||||
SUCCESSFUL = "captured",
|
||||
/**
|
||||
* Payment failed.
|
||||
*/
|
||||
FAILED = "failed",
|
||||
/**
|
||||
* Received an event that is not processable.
|
||||
*/
|
||||
NOT_SUPPORTED = "not_supported",
|
||||
}
|
||||
Reference in New Issue
Block a user