mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a1e6e77ad | ||
| 552ec700c2 | |||
|
|
7d069e5cf1 | ||
| f7d6066d9a |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-billing",
|
"name": "@xtr-dev/payload-billing",
|
||||||
"version": "0.1.10",
|
"version": "0.1.12",
|
||||||
"description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing",
|
"description": "PayloadCMS plugin for billing and payment provider integrations with tracking and local testing",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -55,6 +55,6 @@ export interface BillingPluginConfig {
|
|||||||
customerInfoExtractor?: CustomerInfoExtractor // Callback to extract customer info from relationship
|
customerInfoExtractor?: CustomerInfoExtractor // Callback to extract customer info from relationship
|
||||||
customerRelationSlug?: string // Customer collection slug for relationship
|
customerRelationSlug?: string // Customer collection slug for relationship
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
providers?: PaymentProvider[]
|
providers?: (PaymentProvider | undefined | null)[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
|
|||||||
];
|
];
|
||||||
|
|
||||||
(pluginConfig.providers || [])
|
(pluginConfig.providers || [])
|
||||||
.filter(provider => provider.onConfig)
|
.filter(provider => provider?.onConfig)
|
||||||
.forEach(provider => provider.onConfig!(config, pluginConfig))
|
.forEach(provider => provider?.onConfig!(config, pluginConfig))
|
||||||
|
|
||||||
const incomingOnInit = config.onInit
|
const incomingOnInit = config.onInit
|
||||||
config.onInit = async (payload) => {
|
config.onInit = async (payload) => {
|
||||||
@@ -38,17 +38,17 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
|
|||||||
}
|
}
|
||||||
singleton.set(payload, {
|
singleton.set(payload, {
|
||||||
config: pluginConfig,
|
config: pluginConfig,
|
||||||
providerConfig: (pluginConfig.providers || []).reduce(
|
providerConfig: (pluginConfig.providers || []).filter(Boolean).reduce(
|
||||||
(record, provider) => {
|
(record, provider) => {
|
||||||
record[provider.key] = provider
|
record[provider!.key] = provider as PaymentProvider
|
||||||
return record
|
return record
|
||||||
},
|
},
|
||||||
{} as Record<string, PaymentProvider>
|
{} as Record<string, PaymentProvider>
|
||||||
)
|
)
|
||||||
} satisfies BillingPlugin)
|
} satisfies BillingPlugin)
|
||||||
await Promise.all((pluginConfig.providers || [])
|
await Promise.all((pluginConfig.providers || [])
|
||||||
.filter(provider => provider.onInit)
|
.filter(provider => provider?.onInit)
|
||||||
.map(provider => provider.onInit!(payload)))
|
.map(provider => provider?.onInit!(payload)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ const testPaymentSessions = new Map<string, TestPaymentSession>()
|
|||||||
|
|
||||||
export const testProvider = (testConfig: TestProviderConfig) => {
|
export const testProvider = (testConfig: TestProviderConfig) => {
|
||||||
if (!testConfig.enabled) {
|
if (!testConfig.enabled) {
|
||||||
throw new Error('Test provider is disabled')
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const scenarios = testConfig.scenarios || DEFAULT_SCENARIOS
|
const scenarios = testConfig.scenarios || DEFAULT_SCENARIOS
|
||||||
@@ -242,7 +242,7 @@ export const testProvider = (testConfig: TestProviderConfig) => {
|
|||||||
{
|
{
|
||||||
path: '/payload-billing/test/payment/:id',
|
path: '/payload-billing/test/payment/:id',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
handler: async (req) => {
|
handler: (req) => {
|
||||||
// Extract payment ID from URL path
|
// Extract payment ID from URL path
|
||||||
const urlParts = req.url?.split('/') || []
|
const urlParts = req.url?.split('/') || []
|
||||||
const paymentId = urlParts[urlParts.length - 1]
|
const paymentId = urlParts[urlParts.length - 1]
|
||||||
@@ -458,7 +458,7 @@ export const testProvider = (testConfig: TestProviderConfig) => {
|
|||||||
})
|
})
|
||||||
}, 10 * 60 * 1000) // Clean every 10 minutes
|
}, 10 * 60 * 1000) // Clean every 10 minutes
|
||||||
},
|
},
|
||||||
initPayment: async (payload, payment) => {
|
initPayment: (payload, payment) => {
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!payment.amount) {
|
if (!payment.amount) {
|
||||||
throw new Error('Amount is required')
|
throw new Error('Amount is required')
|
||||||
|
|||||||
Reference in New Issue
Block a user