mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
Core Plugin Enhancements: - Add afterChange hook to payments collection to auto-update linked invoice status to 'paid' when payment succeeds - Add afterChange hook to invoices collection for bidirectional payment-invoice relationship management - Add invoice status sync when manually marked as paid - Update plugin config types to support collection extension options Demo Application Features: - Add professional invoice view page with print-friendly layout (/invoice/[id]) - Add custom message field to payment creation form - Add invoice API endpoint to fetch complete invoice data with customer info - Add payment API endpoint to retrieve payment with invoice relationship - Update payment success page with "View Invoice" button - Implement beforeChange hook to copy custom message from payment metadata to invoice - Remove customer collection dependency - use direct customerInfo fields instead Documentation: - Update README with automatic status synchronization section - Add collection extension examples to demo README - Document new features: bidirectional relationships, status sync, invoice view Technical Improvements: - Fix total calculation in invoice API (use 'amount' field instead of 'total') - Add proper TypeScript types with CollectionSlug casting - Implement Next.js 15 async params pattern in API routes - Add customer name/email/company fields to payment creation form 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
|
import type { FieldsOverride } from './utils'
|
|
import type { PaymentProvider } from './types/index'
|
|
|
|
export const defaults = {
|
|
paymentsCollection: 'payments',
|
|
invoicesCollection: 'invoices',
|
|
refundsCollection: 'refunds',
|
|
customerRelationSlug: 'customer'
|
|
}
|
|
|
|
// Provider configurations
|
|
|
|
export interface TestProviderConfig {
|
|
autoComplete?: boolean
|
|
defaultDelay?: number
|
|
enabled: boolean
|
|
failureRate?: number
|
|
simulateFailures?: boolean
|
|
}
|
|
|
|
// Re-export the actual test provider config instead of duplicating
|
|
export type { TestProviderConfig as AdvancedTestProviderConfig } from '../providers/test'
|
|
|
|
// Customer info extractor callback type
|
|
export interface CustomerInfoExtractor {
|
|
(customer: any): {
|
|
name: string
|
|
email: string
|
|
phone?: string
|
|
company?: string
|
|
taxId?: string
|
|
billingAddress?: {
|
|
line1: string
|
|
line2?: string
|
|
city: string
|
|
state?: string
|
|
postalCode: string
|
|
country: string
|
|
}
|
|
}
|
|
}
|
|
|
|
// Collection configuration type
|
|
export type CollectionExtension =
|
|
| string
|
|
| {
|
|
slug: string
|
|
extend?: (config: CollectionConfig) => CollectionConfig
|
|
}
|
|
|
|
// Plugin configuration
|
|
export interface BillingPluginConfig {
|
|
admin?: {
|
|
customComponents?: boolean
|
|
dashboard?: boolean
|
|
}
|
|
collections?: {
|
|
invoices?: CollectionExtension
|
|
payments?: CollectionExtension
|
|
refunds?: CollectionExtension
|
|
}
|
|
customerInfoExtractor?: CustomerInfoExtractor // Callback to extract customer info from relationship
|
|
customerRelationSlug?: string // Customer collection slug for relationship
|
|
disabled?: boolean
|
|
providers?: (PaymentProvider | undefined | null)[]
|
|
}
|
|
|