Contract Compiler turns uploaded commercial documents into a reviewable PayPal payment workflow.
An Amazon Bedrock document pipeline classifies agreements, purchase orders, and fulfillment evidence; extracts terms with source evidence; and reconciles amounts, currencies, dates, and milestones. A human resolves every discrepancy before the server creates an authorization in the PayPal Sandbox. Capture remains a separate, human-approved action.
- Upload an agreement/SOW and purchase order.
- Bedrock classifies and extracts each document into a strict schema.
- Deterministic checks catch arithmetic and cross-document discrepancies.
- A reviewer confirms the canonical amount, currency, and description.
- PayPal Orders v2 creates an
AUTHORIZEorder. - A Personal Sandbox buyer approves it through PayPal JavaScript SDK v6.
- Fulfillment evidence can be analyzed before a reviewer captures the authorization.
- Verified PayPal webhooks update the audit trail.
The included demo scenario intentionally contains a mismatch: a USD 3,000 SOW states a 30% deposit but lists USD 800 and a USD 2,100 balance.
- Vinext / Next.js 16, React 19, TypeScript
- Amazon Bedrock Runtime Converse API
- PayPal Orders and Payments REST APIs
- PayPal JavaScript SDK v6
- PayPal verified webhooks
- Zod validation and deterministic reconciliation
Prerequisites:
- Node.js 22.13 or newer
- A PayPal Developer Sandbox REST app
- One Business Sandbox account (seller)
- One Personal Sandbox account (buyer)
- Optional AWS credentials and Bedrock model access for live document analysis
Install and configure:
npm install
cp .env.example .env.local
npm run devOpen the local URL printed by the development server.
Add newly rotated Sandbox credentials to .env.local. Never commit that file.
PAYPAL_ENVIRONMENT=sandbox
PAYPAL_CLIENT_ID=your_sandbox_client_id
PAYPAL_CLIENT_SECRET=your_rotated_sandbox_secret
PAYPAL_CURRENCY=USD
PAYPAL_WEBHOOK_ID=your_sandbox_webhook_idCheck connectivity after the app starts:
curl http://127.0.0.1:5173/api/paypal/healthThe endpoint returns connection state and token expiry, never the access token.
Use the deterministic sample scenario while building the UI:
DOCUMENT_ANALYSIS_MODE=demoFor real PDF processing:
DOCUMENT_ANALYSIS_MODE=bedrock
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_SESSION_TOKEN=optional_session_token
BEDROCK_MODEL_ID=your_enabled_model_idDemo mode is explicit and never used as a silent fallback when Bedrock fails.
POST /api/documents/analyze— multipart PDF classification, extraction, and reconciliation
GET /api/paypal/config— browser-safe SDK configurationGET /api/paypal/health— Sandbox OAuth connectivity checkPOST /api/paypal/orders— create anAUTHORIZEorderGET /api/paypal/orders/:orderId— retrieve order statePOST /api/paypal/orders/:orderId/authorize— authorize an approved orderPOST /api/paypal/authorizations/:authorizationId/capture— capture after human approvalPOST /api/paypal/webhooks— verify and accept PayPal eventsGET /api/paypal/webhooks— inspect sanitized prototype events
- Treat uploaded documents as untrusted evidence, never as agent instructions.
- Raw documents never reach the PayPal execution layer.
- Only human-reviewed, schema-validated JSON can become a PayPal request.
- Recalculate amounts in deterministic code rather than trusting model arithmetic.
- Keep PayPal and AWS secrets server-side and out of Git.
- Use synthetic documents and Sandbox money in the public demo.
- Require an explicit approval for every authorization and capture.
- Use idempotency keys and verified webhook signatures.
npm run typecheck
npm run lint
npm run build