diff --git a/src/plugin/config.ts b/src/plugin/config.ts index 7b16838..e2e5665 100644 --- a/src/plugin/config.ts +++ b/src/plugin/config.ts @@ -19,25 +19,8 @@ export interface TestProviderConfig { simulateFailures?: boolean } -export interface AdvancedTestProviderConfig { - enabled: boolean - scenarios?: Array<{ - id: string - name: string - description: string - outcome: 'paid' | 'failed' | 'cancelled' | 'expired' | 'pending' - delay?: number - method?: 'ideal' | 'creditcard' | 'paypal' | 'applepay' | 'banktransfer' - }> - customUiRoute?: string - testModeIndicators?: { - showWarningBanners?: boolean - showTestBadges?: boolean - consoleWarnings?: boolean - } - defaultDelay?: number - baseUrl?: string -} +// Re-export the actual test provider config instead of duplicating +export type { TestProviderConfig as AdvancedTestProviderConfig } from '../providers/test.js' // Customer info extractor callback type export interface CustomerInfoExtractor { diff --git a/src/providers/test.ts b/src/providers/test.ts index 63bd285..f48e50b 100644 --- a/src/providers/test.ts +++ b/src/providers/test.ts @@ -176,9 +176,38 @@ export const testProvider = (testConfig: TestProviderConfig) => { // Process payment after delay setTimeout(() => { - processTestPayment(payload, session, pluginConfig).catch((error) => { + processTestPayment(payload, session, pluginConfig).catch(async (error) => { console.error('[Test Provider] Failed to process payment:', error) session.status = 'failed' + + // Also update the payment record in database + try { + const paymentsCollection = (typeof pluginConfig.collections?.payments === 'string' + ? pluginConfig.collections.payments + : 'payments') as any + const payments = await payload.find({ + collection: paymentsCollection, + where: { providerId: { equals: session.id } }, + limit: 1 + }) + + if (payments.docs.length > 0) { + await payload.update({ + collection: paymentsCollection, + id: payments.docs[0].id, + data: { + status: 'failed', + providerData: { + raw: { error: error.message, processedAt: new Date().toISOString() }, + timestamp: new Date().toISOString(), + provider: 'test' + } + } + }) + } + } catch (dbError) { + console.error('[Test Provider] Failed to update payment in database:', dbError) + } }) }, scenario.delay || testConfig.defaultDelay || 1000) @@ -665,7 +694,7 @@ function generateTestPaymentUI( method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - paymentId: "${session.id}", + paymentId: '${session.id}', scenarioId: selectedScenario, method: selectedMethod })