Inspiration
When building payment integrations, almost every developer tests the exact same happy path: initiate a checkout, approve it in PayPal Sandbox, receive a single webhook, and watch the database update. It works in staging, so it ships to production.
In real distributed systems, payment networks are asynchronous and guarantee at-least-once delivery:
Network blips trigger automatic duplicate webhook retries. Concurrent deliveries of PAYMENT.CAPTURE.COMPLETED arrive milliseconds apart, bypassing naive database checks and crediting buyer accounts twice. Delayed out-of-order webhooks (like an older CHECKOUT.ORDER.APPROVED arriving after a capture) regress orders back to pending states. Handlers that commit database transactions before returning an HTTP 500 cause duplicate fulfillment on the next retry.
An HTTP 200 OK only proves your web server answered—it does not prove your financial invariants held. I built Faultline because developers lack a dedicated chaos-engineering workbench to prove their payment logic survives failure before going live.
What it does
Faultline is a payment reliability and webhook chaos-engineering platform for PayPal Sandbox, combining 11 deterministic financial safety checks with a strictly guardrailed AI Test Engineer powered by Google Gemini and OpenAI.
Genuine PayPal Sandbox Integration: Connects directly to PayPal Sandbox via OAuth2, creates and captures real Sandbox orders, and validates incoming webhook payloads byte-for-byte against PayPal’s cryptographic signature verification API (POST /v1/notifications/verify-webhook-signature). Test Lab (Webhook Chaos Injection): Injects controlled delivery anomalies against your target application: Duplicate Delivery: Fires the verified event 2 to 10 times, sequentially or in parallel concurrent bursts to test race conditions. Delayed Delivery: Pauses and forwards webhooks after 1 to 3,600 seconds to test out-of-order tolerance and stale state regressions. Dropped Delivery: Intentionally withholds deliveries to verify background reconciliation against PayPal’s Orders API. Replay Delivery: Resends previously verified events to verify long-horizon idempotency. 11 Deterministic Financial Invariants: Evaluates concrete invariants across HTTP traces, PayPal Order snapshots, and an application state probe (e.g., verifying processed_count never exceeds 1, payment_records never duplicates, and state never regresses). Deterministic checks are the sole source of test verdicts. AI Test Engineer (Google Gemini & OpenAI): Natural Language Planning: Translates plain-English developer requests (e.g., "Test if my app double-credits when receiving two concurrent capture webhooks") into schema-validated Faultline test specifications. Evidence-Based Trace Analysis: Explains completed execution traces, pinpointing root-cause database race conditions and transaction boundary errors. Follow-Up Test Advisor: Analyzes stored events and past check failures to recommend high-priority coverage gaps. How I built it
I built Faultline as a modular Node.js/Express application with zero bloated external UI frameworks:
Core Engine & Persistence: Node.js 22 LTS with an embedded SQLite database running in WAL mode, backed by an AES-256-GCM encrypted vault for PayPal client secrets. PayPal Sandbox REST API v2: Handled OAuth2 token lifecycle with client credentials, order creation, buyer approval redirects, capture calls, and raw byte-preserved signature verification. Dual-Provider AI Architecture: Google Gemini API: Integrated using the official @google/genai SDK with gemini-3.8-flash as the default model for structured JSON generation. OpenAI API: Integrated using the official openai SDK with gpt-4o-mini as an alternative/fallback provider. Designed an auto-detecting abstraction with strict input/output bounds, AbortController timeouts, rate limiting, and unified error mapping. Security & Safety Guardrails: Implemented strict delimiter-isolated allow-lists (sanitizeTraceForAi, redactSensitiveText) to ensure access tokens, client secrets, encryption keys, raw bodies, and buyer PII are never sent to AI models. Gated all AI-generated plans behind explicit user confirmation before execution. Hard-locked deterministicVerdict.canOverride = false and financialOperationsAllowed: false so AI models can never trigger financial operations or alter safety verdicts. Testing: Built a comprehensive test suite of 141 automated unit and integration tests using Node.js built-in test runner (node:test). Stand-in fixture servers mock PayPal and AI responses, allowing full offline testing with zero live credentials. Challenges I ran into Byte-Exact Webhook Signature Verification: PayPal’s signature verification hashes the original raw webhook bytes. If Express parses the JSON body into an object and re-stringifies it, key reordering or whitespace changes cause PayPal's verification API to reject the signature. I solved this by capturing and preserving the raw Buffer on ingestion, storing it verbatim, and verifying it directly. Strict AI Safety vs. Model Creativity: LLMs naturally want to be helpful and sometimes propose actions outside their domain, like offering to execute refunds or declaring a failed test "passed." I established a strict architecture where the AI only proposes parameters from an allow-listed schema (KNOWN_CHECKS). If an output references an unknown check ID, invalid event, or attempts to override a verdict, Faultline's server-side validator instantly discards it with 502 ai_invalid_output. Sandbox Latency and Flakiness: The PayPal Sandbox OAuth endpoint can occasionally experience latency spikes up to 15–20 seconds. My initial 10-second timeout caused false-positive connection drops. I adjusted the timeout policy to 25 seconds and added retry-tolerant connection diagnostics with informative troubleshooting tips. Accomplishments that I'm proud of 100% Honest Engineering: Deterministic safety checks remain the sole truth for test verdicts. AI is applied where it excels—interpreting developer intent, finding coverage gaps, and diagnosing complex trace logs—without ever having authority over financial state or verdicts. Dual-Provider Flexibility: Implemented clean, seamless switching between Google Gemini 3.8 Flash and OpenAI GPT-4o-mini with graceful degradation (the entire product functions 100% even if no AI key is provided). Rock-Solid Test Coverage: 141 tests passing with 0 external network dependencies in automated CI, proving that every failure mode, security boundary, and race condition is accounted for. Full Sandbox Lifecycle: Built a complete end-to-end PayPal Sandbox workbench—from order creation and buyer approval to capture, webhook verification, and fault injection. What I learned The Nuances of PayPal Signature Verification: Gained deep appreciation for PayPal's security architecture, including transmission headers, certificate validation, and byte-exact verification requirements. Defensive AI Engineering: Learned that building reliable AI products requires treating model responses as untrusted user input. Strict schema validators, delimiter isolation, and server-side invariant locks are essential when AI interacts with financial infrastructure. Designing Clean State Probes: Proving distributed safety without coupling to a specific database requires clean contracts. The lightweight application state probe contract demonstrated how easily any developer can expose before-and-after snapshots for deterministic verification. What's next for Faultline Pre-Built SDK Middleware: Releasing plug-and-play middleware for Express, Next.js, and FastAPI that automatically exposes the Faultline state probe contract and implements built-in idempotency deduplication. Automated CI/CD GitHub Action: Packaging Faultline as a GitHub Action that spins up in CI pipelines, injects duplicate and delayed webhooks into preview deployments, and blocks pull requests that fail idempotency checks. Expanded PayPal Events: Extending chaos scenarios to subscription lifecycle webhooks (BILLING.SUBSCRIPTION.*), dispute resolutions, and multi-currency refund edge cases.
Built With
- cd/ci
- nextjs
- paypal