1 Commits

Author SHA1 Message Date
claude[bot]
eaf54ae893 feat: add test provider config endpoint
Add GET /api/payload-billing/test/config endpoint to retrieve test provider configuration including scenarios, payment methods, and test mode indicators.

This allows custom UIs to dynamically sync with plugin configuration instead of hardcoding values.

- Add TestProviderConfigResponse interface
- Export new type in provider index and main index
- Endpoint returns enabled status, scenarios, methods, test mode indicators, default delay, and custom UI route

Resolves #22

Co-authored-by: Bas <bvdaakster@users.noreply.github.com>
2025-09-19 11:10:18 +00:00
3 changed files with 44 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ export type {
StripeProviderConfig, StripeProviderConfig,
MollieProviderConfig, MollieProviderConfig,
TestProviderConfig, TestProviderConfig,
TestProviderConfigResponse,
PaymentOutcome, PaymentOutcome,
PaymentMethod, PaymentMethod,
PaymentScenario PaymentScenario

View File

@@ -7,4 +7,4 @@ export * from './currency'
// Re-export provider configurations and types // Re-export provider configurations and types
export type { StripeProviderConfig } from './stripe' export type { StripeProviderConfig } from './stripe'
export type { MollieProviderConfig } from './mollie' export type { MollieProviderConfig } from './mollie'
export type { TestProviderConfig, PaymentOutcome, PaymentMethod, PaymentScenario } from './test' export type { TestProviderConfig, TestProviderConfigResponse, PaymentOutcome, PaymentMethod, PaymentScenario } from './test'

View File

@@ -31,6 +31,23 @@ export interface TestProviderConfig {
baseUrl?: string baseUrl?: string
} }
export interface TestProviderConfigResponse {
enabled: boolean
scenarios: PaymentScenario[]
methods: Array<{
id: string
name: string
icon: string
}>
testModeIndicators: {
showWarningBanners: boolean
showTestBadges: boolean
consoleWarnings: boolean
}
defaultDelay: number
customUiRoute: string
}
// Properly typed session interface // Properly typed session interface
export interface TestPaymentSession { export interface TestPaymentSession {
id: string id: string
@@ -144,6 +161,31 @@ export const testProvider = (testConfig: TestProviderConfig) => {
}) })
} }
}, },
{
path: '/payload-billing/test/config',
method: 'get',
handler: async (req) => {
const response: TestProviderConfigResponse = {
enabled: testConfig.enabled,
scenarios: scenarios,
methods: Object.entries(PAYMENT_METHODS).map(([id, method]) => ({
id,
name: method.name,
icon: method.icon
})),
testModeIndicators: testConfig.testModeIndicators || {
showWarningBanners: true,
showTestBadges: true,
consoleWarnings: true
},
defaultDelay: testConfig.defaultDelay || 1000,
customUiRoute: uiRoute
}
return new Response(JSON.stringify(response), {
headers: { 'Content-Type': 'application/json' }
})
}
},
{ {
path: '/payload-billing/test/process', path: '/payload-billing/test/process',
method: 'post', method: 'post',