mirror of
https://github.com/xtr-dev/payload-billing.git
synced 2025-12-10 02:43:24 +00:00
- Add emoji accessibility labels (jsx-a11y/accessible-emoji) - Remove unused imports and variables - Fix async functions without await - Add dev directory to ESLint ignore list - Add eslint-disable comment for necessary console.error - Clean up unused route file All ESLint errors resolved (0 errors, 33 warnings remaining) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import configPromise from '@payload-config'
|
|
import { getPayload } from 'payload'
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const payload = await getPayload({
|
|
config: configPromise,
|
|
})
|
|
|
|
const body = await request.json()
|
|
const { amount, currency, description } = body
|
|
|
|
if (!amount || !currency) {
|
|
return Response.json(
|
|
{ success: false, error: 'Amount and currency are required' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// Create a payment using the test provider
|
|
const payment = await payload.create({
|
|
collection: 'payments',
|
|
data: {
|
|
provider: 'test',
|
|
amount,
|
|
currency,
|
|
description: description || 'Demo payment',
|
|
status: 'pending',
|
|
metadata: {
|
|
source: 'demo-ui',
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
})
|
|
|
|
return Response.json({
|
|
success: true,
|
|
payment: {
|
|
id: payment.providerId, // Use the test provider ID for the UI
|
|
paymentId: payment.id,
|
|
amount: payment.amount,
|
|
currency: payment.currency,
|
|
description: payment.description,
|
|
},
|
|
})
|
|
} catch (error) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('Failed to create payment:', error)
|
|
return Response.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to create payment',
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|