diff --git a/package.json b/package.json index 6551680..ad9879c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-billing", - "version": "0.1.11", + "version": "0.1.12", "description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing", "license": "MIT", "type": "module", diff --git a/src/plugin/config.ts b/src/plugin/config.ts index 1e7f8c7..6c8658a 100644 --- a/src/plugin/config.ts +++ b/src/plugin/config.ts @@ -55,6 +55,6 @@ export interface BillingPluginConfig { customerInfoExtractor?: CustomerInfoExtractor // Callback to extract customer info from relationship customerRelationSlug?: string // Customer collection slug for relationship disabled?: boolean - providers?: PaymentProvider[] + providers?: (PaymentProvider | undefined | null)[] } diff --git a/src/plugin/index.ts b/src/plugin/index.ts index 7e837fe..a15b47a 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -28,8 +28,8 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config ]; (pluginConfig.providers || []) - .filter(provider => provider.onConfig) - .forEach(provider => provider.onConfig!(config, pluginConfig)) + .filter(provider => provider?.onConfig) + .forEach(provider => provider?.onConfig!(config, pluginConfig)) const incomingOnInit = config.onInit config.onInit = async (payload) => { @@ -38,17 +38,17 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config } singleton.set(payload, { config: pluginConfig, - providerConfig: (pluginConfig.providers || []).reduce( + providerConfig: (pluginConfig.providers || []).filter(Boolean).reduce( (record, provider) => { - record[provider.key] = provider + record[provider!.key] = provider as PaymentProvider return record }, {} as Record ) } satisfies BillingPlugin) await Promise.all((pluginConfig.providers || []) - .filter(provider => provider.onInit) - .map(provider => provider.onInit!(payload))) + .filter(provider => provider?.onInit) + .map(provider => provider?.onInit!(payload))) } return config