* A payment provider is used to handle and process payments, such as authorizing, capturing, and refund payments.
*
* Refer to [this guide](https://docs.medusajs.com/experimental/payment/payment-provider/) to learn more about payment providers.
*
* Refer to [this guide](https://docs.medusajs.com/experimental/payment/payment-flow/) to learn more about the payment flow.
*
* ---
*
* ## How to Create a Payment Provider
*
* A payment provider is a TypeScript or JavaScript class that extends the `AbstractPaymentProvider` class imported from `@medusajsa/utils`.
*
* You can create the payment provider in a module or plugin, then pass that module/plugin in the Payment Module's `providers` option. You can also pass the path to the file
* that defines the provider if it's created in the Medusa application's codebase.
*
* For example:
*
* ```ts
* abstract class MyPayment extends AbstractPaymentProvider<MyConfigurations> {
* // ...
* }
* ```
*
* ---
*
* ## Configuration Type Parameter
*
* The `AbstractPaymentProvider` class accepts an optional type parameter that defines the type of configuration that your payment provider expects.
*
* For example:
*
* ```ts
* interface MyConfigurations {
* apiKey: string
* }
*
* abstract class MyPayment extends AbstractPaymentProvider<MyConfigurations> {
* // ...
* }
* ```
*
* ---
*
* ## Identifier Property
*
* The `PaymentProvider` data model has 2 properties: `id` and `is_enabled`.
*
* ```ts
* class MyPaymentProvider extends AbstractPaymentProvider<MyConfigurations> {
* static identifier = "my-payment"
* // ...
* }
* ```
*
* ---
*
* ## PROVIDER Property
*
* The `PROVIDER` static property is used when registering the provider in the dependency container. Typically, it would have the
* same value as the `identifier` property.
*
* ```ts
* class MyPaymentProvider extends AbstractPaymentProvider<MyConfigurations> {
* static PROVIDER = "my-payment"
* // ...
* }
* ```
*
* ---
*
* ## PaymentProviderError
*
* Before diving into the methods of the Payment Provider, you'll notice that part of the expected return signature of these method includes `PaymentProviderError`.
*
* ```ts
* interface PaymentProviderError {
* error: string
* code?: string
* detail?: any
* }
* ```
*
* While implementing the Payment Provider's methods, if you need to inform the Payment Module that an error occurred at a certain stage,
* return an object having the attributes defined in the `PaymentProviderError` interface.
*
* For example, the Stripe payment provider has the following method to create the error object, which is used within other methods:
*
* ```ts
* abstract class StripeBase extends AbstractPaymentProvider {
* You can use the `constructor` of your Payment Provider to have access to resources in your application through the [dependency container](https://docs.medusajs.com/development/fundamentals/dependency-injection).
*
* You can also use the constructor to initialize your integration with the third-party provider. For example, if you use a client to connect to the third-party provider’s APIs,
* you can initialize it in the constructor and use it in other methods in the service.
*
* The payment provider also can access the configurations of the module or plugin it's created in as a second parameter.
*
* @param {MedusaContainer} container - An instance of `MedusaContainer` that allows you to access other resources in the [dependency container](https://docs.medusajs.com/development/fundamentals/dependency-injection)
* @param {Record<string, unknown>} config - If this provider processor is created in a module or plugin, their options are passed in this parameter.
*
* @example
* ```ts
* class MyPaymentProvider extends AbstractPaymentProvider<MyConfigurations> {
* Normalized events from payment provider to internal payment module events.
*/
exportenumPaymentActions{
/**
* 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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.