feat: Add support for provider-level configuration in billing plugin

- Introduce `onConfig` callback for payment providers
- Add dynamic endpoint registration for Mollie webhook handling
- Remove unused provider-specific configurations from plugin types
- Update initialization to include provider-level configurations
This commit is contained in:
2025-09-16 22:55:30 +02:00
parent e3a58fe6bc
commit 2aad0d2538
4 changed files with 35 additions and 29 deletions

View File

@@ -10,18 +10,6 @@ export const defaults = {
}
// Provider configurations
export interface StripeConfig {
apiVersion?: string
publishableKey: string
secretKey: string
webhookEndpointSecret: string
}
export interface MollieConfig {
apiKey: string
testMode?: boolean
webhookUrl: string
}
export interface TestProviderConfig {
autoComplete?: boolean
@@ -65,13 +53,5 @@ export interface BillingPluginConfig {
customerRelationSlug?: string // Customer collection slug for relationship
disabled?: boolean
providers?: PaymentProvider[]
webhooks?: {
basePath?: string
cors?: boolean
}
}
// Plugin type
export interface BillingPluginOptions extends BillingPluginConfig {
disabled?: boolean
}

View File

@@ -25,7 +25,11 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
createPaymentsCollection(pluginConfig),
createInvoicesCollection(pluginConfig),
createRefundsCollection(pluginConfig),
]
];
(pluginConfig.providers || [])
.filter(provider => provider.onConfig)
.forEach(provider => provider.onConfig!(config, pluginConfig))
const incomingOnInit = config.onInit
config.onInit = async (payload) => {
@@ -35,15 +39,16 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
singleton.set(payload, {
config: pluginConfig,
providerConfig: (pluginConfig.providers || []).reduce(
(acc, val) => {
acc[val.key] = val
return acc
(record, provider) => {
record[provider.key] = provider
return record
},
{} as Record<string, PaymentProvider>
)
} satisfies BillingPlugin)
console.log('Billing plugin initialized', singleton.get(payload))
await Promise.all((pluginConfig.providers || []).map(p => p.onInit(payload)))
await Promise.all((pluginConfig.providers || [])
.filter(provider => provider.onInit)
.map(provider => provider.onInit!(payload)))
}
return config