mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 10:53:23 +00:00
fix: Address validation and consistency issues
- Restore missing customers collection import and creation - Fix required field validation: customerInfo fields only required when no extractor - Fix linting warnings in webhook handler - Ensure consistent typing across all interfaces 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -69,7 +69,7 @@ export function createInvoicesCollection(
|
|||||||
description: 'Customer name',
|
description: 'Customer name',
|
||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'email',
|
name: 'email',
|
||||||
@@ -78,7 +78,7 @@ export function createInvoicesCollection(
|
|||||||
description: 'Customer email address',
|
description: 'Customer email address',
|
||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'phone',
|
name: 'phone',
|
||||||
@@ -123,7 +123,7 @@ export function createInvoicesCollection(
|
|||||||
description: 'Address line 1',
|
description: 'Address line 1',
|
||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'line2',
|
name: 'line2',
|
||||||
@@ -139,7 +139,7 @@ export function createInvoicesCollection(
|
|||||||
admin: {
|
admin: {
|
||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'state',
|
name: 'state',
|
||||||
@@ -156,7 +156,7 @@ export function createInvoicesCollection(
|
|||||||
description: 'Postal or ZIP code',
|
description: 'Postal or ZIP code',
|
||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'country',
|
name: 'country',
|
||||||
@@ -166,7 +166,7 @@ export function createInvoicesCollection(
|
|||||||
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
readOnly: customerCollectionSlug && customerInfoExtractor ? true : false,
|
||||||
},
|
},
|
||||||
maxLength: 2,
|
maxLength: 2,
|
||||||
required: true,
|
required: !customerCollectionSlug || !customerInfoExtractor,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { Config } from 'payload'
|
|||||||
|
|
||||||
import type { BillingPluginConfig, CustomerInfoExtractor } from './types'
|
import type { BillingPluginConfig, CustomerInfoExtractor } from './types'
|
||||||
|
|
||||||
|
import { createCustomersCollection } from './collections/customers'
|
||||||
import { createInvoicesCollection } from './collections/invoices'
|
import { createInvoicesCollection } from './collections/invoices'
|
||||||
import { createPaymentsCollection } from './collections/payments'
|
import { createPaymentsCollection } from './collections/payments'
|
||||||
import { createRefundsCollection } from './collections/refunds'
|
import { createRefundsCollection } from './collections/refunds'
|
||||||
@@ -41,6 +42,7 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
|
|||||||
|
|
||||||
config.collections.push(
|
config.collections.push(
|
||||||
createPaymentsCollection(pluginConfig.collections?.payments || 'payments'),
|
createPaymentsCollection(pluginConfig.collections?.payments || 'payments'),
|
||||||
|
createCustomersCollection(customerSlug),
|
||||||
createInvoicesCollection(
|
createInvoicesCollection(
|
||||||
pluginConfig.collections?.invoices || 'invoices',
|
pluginConfig.collections?.invoices || 'invoices',
|
||||||
pluginConfig.collections?.customerRelation !== false ? customerSlug : undefined,
|
pluginConfig.collections?.customerRelation !== false ? customerSlug : undefined,
|
||||||
@@ -57,18 +59,19 @@ export const billingPlugin = (pluginConfig: BillingPluginConfig = {}) => (config
|
|||||||
config.endpoints?.push(
|
config.endpoints?.push(
|
||||||
// Webhook endpoints
|
// Webhook endpoints
|
||||||
{
|
{
|
||||||
handler: (req) => {
|
handler: (_req) => {
|
||||||
try {
|
try {
|
||||||
const provider = null
|
const provider = null
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return Response.json({ error: 'Provider not found' }, { status: 404 })
|
return Response.json({ error: 'Provider not found' }, { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Process webhook event and update database
|
// TODO: Process webhook event and update database
|
||||||
|
|
||||||
return Response.json({ received: true })
|
return Response.json({ received: true })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// TODO: Use proper logger instead of console
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.error('[BILLING] Webhook error:', error)
|
console.error('[BILLING] Webhook error:', error)
|
||||||
return Response.json({ error: 'Webhook processing failed' }, { status: 400 })
|
return Response.json({ error: 'Webhook processing failed' }, { status: 400 })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user