mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
refactor: Replace conditional fields with customer info extractor callback
- Add CustomerInfoExtractor callback type for flexible customer data extraction - Implement automatic customer info sync via beforeChange hook - Make customer info fields read-only when using extractor - Add defaultCustomerInfoExtractor for built-in customer collection - Update validation to require customer selection when using extractor - Keep customer info in sync when relationship changes Breaking change: Plugin users must now provide customerInfoExtractor callback to enable customer relationship syncing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { sqliteAdapter } from '@payloadcms/db-sqlite'
|
||||
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
||||
import path from 'path'
|
||||
import { buildConfig } from 'payload'
|
||||
import { billingPlugin } from '../dist/index.js'
|
||||
import { billingPlugin, defaultCustomerInfoExtractor } from '../dist/index.js'
|
||||
import sharp from 'sharp'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
@@ -61,7 +61,23 @@ const buildConfigWithSQLite = () => {
|
||||
refunds: 'refunds',
|
||||
// customerRelation: false, // Set to false to disable customer relationship in invoices
|
||||
// customerRelation: 'clients', // Or set to a custom collection slug
|
||||
}
|
||||
},
|
||||
// Use the default extractor for the built-in customer collection
|
||||
customerInfoExtractor: defaultCustomerInfoExtractor,
|
||||
// Or provide a custom extractor for your own customer collection structure:
|
||||
// customerInfoExtractor: (customer) => ({
|
||||
// name: customer.fullName,
|
||||
// email: customer.contactEmail,
|
||||
// phone: customer.phoneNumber,
|
||||
// company: customer.companyName,
|
||||
// taxId: customer.vatNumber,
|
||||
// billingAddress: {
|
||||
// line1: customer.billing.street,
|
||||
// city: customer.billing.city,
|
||||
// postalCode: customer.billing.zip,
|
||||
// country: customer.billing.countryCode,
|
||||
// }
|
||||
// })
|
||||
}),
|
||||
],
|
||||
secret: process.env.PAYLOAD_SECRET || 'test-secret_key',
|
||||
|
||||
Reference in New Issue
Block a user