Skip to content

Commit

Permalink
fix(stripe): Wrong container type (#10223)
Browse files Browse the repository at this point in the history
RESOLVES SUP-238

**What**

wrong container type withing payment providers
  • Loading branch information
adrien2p authored Nov 22, 2024
1 parent 9d5b041 commit b964b45
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 2 additions & 6 deletions packages/core/utils/src/event-bus/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
EventBusTypes,
InternalModuleDeclaration,
MedusaContainer,
} from "@medusajs/types"
import { EventBusTypes, InternalModuleDeclaration } from "@medusajs/types"
import { ulid } from "ulid"

export abstract class AbstractEventBusModuleService
Expand All @@ -23,7 +19,7 @@ export abstract class AbstractEventBusModuleService
}

protected constructor(
container: MedusaContainer,
cradle: Record<string, unknown>,
moduleOptions = {},
moduleDeclaration: InternalModuleDeclaration
) {
Expand Down
18 changes: 10 additions & 8 deletions packages/core/utils/src/payment/abstract-payment-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
CreatePaymentProviderSession,
IPaymentProvider,
MedusaContainer,
PaymentProviderError,
PaymentProviderSessionResponse,
PaymentSessionStatus,
Expand All @@ -13,14 +12,15 @@ import {
export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
implements IPaymentProvider
{
protected readonly container: Record<string, unknown>
/**
* This method validates the options of the provider set in `medusa-config.ts`.
* Implementing this method is optional. It's useful if your provider requires custom validation.
*
*
* If the options aren't valid, throw an error.
*
*
* @param options - The provider's options.
*
*
* @example
* class MyPaymentProviderService extends AbstractPaymentProvider<Options> {
* static validateOptions(options: Record<any, any>) {
Expand All @@ -43,7 +43,7 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
*
* The provider can also access the module's options as a second parameter.
*
* @param {MedusaContainer} container - The module's container used to resolve resources.
* @param {Record<string, unknown>} cradle - The module's container cradle used to resolve resources.
* @param {Record<string, unknown>} config - The options passed to the payment module provider.
*
* @example
Expand Down Expand Up @@ -92,9 +92,11 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>
* ```
*/
protected constructor(
protected readonly container: MedusaContainer,
cradle: Record<string, unknown>,
protected readonly config: TConfig = {} as TConfig // eslint-disable-next-line @typescript-eslint/no-empty-function
) {}
) {
this.container = cradle
}

/**
* @ignore
Expand All @@ -110,7 +112,7 @@ export abstract class AbstractPaymentProvider<TConfig = Record<string, unknown>>

/**
* Each payment provider has a unique identifier defined in its class. The provider's ID
* will be stored as `pp_{identifier}_{id}`, where `{id}` is the provider's `id`
* will be stored as `pp_{identifier}_{id}`, where `{id}` is the provider's `id`
* property in the `medusa-config.ts`.
*
* @example
Expand Down
4 changes: 2 additions & 2 deletions packages/core/utils/src/search/abstract-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export abstract class AbstractSearchService
* Additionally, if you’re creating your search service as an external plugin to be installed on any Medusa backend and you want to access the options added for the plugin,
* you can access them in the constructor. The default constructor already sets the value of the class proeprty `options_` to the passed options.
*
* @param {MedusaContainer} container - An instance of `MedusaContainer` that allows you to access other resources, such as services, in your Medusa backend.
* @param {Record<string, unknown>} cradle - An container cradle that allows you to access other resources, such as services, in your Medusa backend.
* @param {Record<string, unknown>} options - If this search service is created in a plugin, the plugin's options are passed in this parameter.
*
* @example
Expand Down Expand Up @@ -144,7 +144,7 @@ export abstract class AbstractSearchService
* // ...
* }
*/
protected constructor(container, options) {
protected constructor(cradle, options) {
this.options_ = options
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Stripe from "stripe"

import {
CreatePaymentProviderSession,
MedusaContainer,
PaymentProviderError,
PaymentProviderSessionResponse,
ProviderWebhookPayload,
Expand Down Expand Up @@ -34,19 +33,22 @@ import {
abstract class StripeBase extends AbstractPaymentProvider<StripeOptions> {
protected readonly options_: StripeOptions
protected stripe_: Stripe
protected container_: MedusaContainer
protected container_: Record<string, unknown>

static validateOptions(options: StripeOptions): void {
if (!isDefined(options.apiKey)) {
throw new Error("Required option `apiKey` is missing in Stripe plugin")
}
}

protected constructor(container: MedusaContainer, options: StripeOptions) {
protected constructor(
cradle: Record<string, unknown>,
options: StripeOptions
) {
// @ts-ignore
super(...arguments)

this.container_ = container
this.container_ = cradle
this.options_ = options

this.stripe_ = new Stripe(options.apiKey)
Expand Down

0 comments on commit b964b45

Please sign in to comment.