Inspiration: The Price Can Match While the Promise Changes
Imagine renting a camera from a local shop.
The merchant sends a quotation: $60 rental fee, $40 refundable security deposit, $100 upfront. You agree.
The final booking still asks for $100 - but now the deposit is non-refundable.
The amount matches. The agreement does not.
This could happen because of an old template, a handover between employees, or a simple mistake. Whatever the reason, the buyer has to find the change by checking the final booking against earlier quotations and messages.
That camera rental example became the starting point for BeforePay.
BeforePay helps people check what they are agreeing to before they pay for it.
The initial focus is camera and audiovisual equipment rentals, where equipment, dates, deposits, and cancellation terms all matter alongside the total price.
What It Does
BeforePay connects the original offer, the buyer-confirmed agreement, the merchant’s final proposal, cancellation consequences, and PayPal checkout.
A representative journey follows six steps:
- Bring in the original evidence. The buyer uploads the merchant’s quotation or pastes relevant messages.
- Review an AI-generated draft. Gemini extracts equipment, quantities, dates, amounts, and policy clauses with supporting citations. Missing information remains unknown.
- Confirm the agreement. The buyer checks the evidence, makes any corrections, and explicitly confirms a saved agreement version.
- Compare the merchant’s final booking. BeforePay compares the saved proposal against the confirmed agreement and highlights differences or terms needing clarification.
- Understand cancellation consequences. After reviewing and approving structured cancellation rules, the user can preview the rental-fee and deposit refund at a chosen time.
- Approve checkout and pay. Checkout approval is separate from agreement confirmation. A completed PayPal Sandbox payment produces a saved receipt linked to the reviewed versions.
If something needs clarification, Gemini can suggest a question based on the saved discrepancy. It does not send the question or accept changed terms automatically.
How AI, Application Rules, and People Work Together
Different parts of the system have different responsibilities.
Gemini: Read and Interpret
Gemini helps turn quotations and messages into structured draft terms, assess policy wording during comparison, suggest clarification questions, and propose cancellation rules when explicitly requested.
These outputs remain subject to validation and review. AI-generated text does not become an approved agreement simply because it was generated successfully.
Application Code: Validate and Calculate
The backend validates structured data, checks saved versions, and enforces the conditions required to proceed.
Refund amounts are calculated in Python from reviewed rules. The model does not invent the financial result.
The User: Review and Approve
The user confirms the agreement, reviews cancellation rules, and approves checkout through separate actions.
AI helps interpret the evidence. Application code checks consistency and calculates outcomes. People decide what to accept.
PayPal: Payment Connected to the Reviewed Agreement
PayPal is part of the final step of the workflow.
The frontend uses the PayPal JavaScript SDK, while the backend handles order creation and payment capture through PayPal’s APIs.
Before creating an order, the application checks the required saved state and approvals. After a successful capture, it stores a receipt connecting the payment record with the agreement and proposal versions used for checkout.
This gives the user a record of both the payment and the terms reviewed before it.
The current implementation uses PayPal Sandbox. It does not perform live payments or execute cancellation refunds.
APIMatic: Guidance for Building the PayPal Integration
I used the APIMatic PayPal Context Plugin in Codex, specifically its installed Python skills, to guide integration planning, idempotency, error handling, and mocked testing.
This helped address practical payment concerns: handling repeated requests, responding to failures, and testing payment behaviour without making real transactions.
APIMatic supported development; it does not process payments in BeforePay. The running application uses a Python HTTPX adapter to call PayPal Sandbox REST APIs, alongside PayPal’s browser JavaScript SDK. REST contracts came from official PayPal documentation.
No APIMatic-generated SDK or PayPal MCP operations were used.
How I Built It
The architecture separates the interface, AI assistance, business rules, stored evidence, and payment execution.
- React, TypeScript, Vite, and Tailwind CSS power the buyer and merchant prototype interfaces.
- FastAPI and Python handle evidence processing, review workflows, comparison, cancellation calculations, and payment endpoints.
- Pydantic validates structured inputs and AI outputs.
- SQLAlchemy and PostgreSQL on Neon persist evidence, drafts, agreement versions, proposals, comparisons, approvals, and payment records.
- Gemini through the Google GenAI SDK provides the explicitly requested AI assistance.
- PayPal Sandbox supports the checkout and capture flow.
- Vercel hosts the frontend and backend.
Saved versions and fingerprints keep each review connected to its inputs. When a proposal changes, an earlier comparison or approval cannot silently stand in for a review of the new version.
Challenges I Ran Into
Repeated Evidence Is Not Additional Equipment
Both a quotation and a confirmation message may mention the same camera. Treating every extracted mention as a separate item created duplicates.
I added handling for proven corroboration across sources while retaining the citations. Different quantities, qualifying wording, conflicts, and unresolved terms still need review.
Successful AI Requests Can Still Produce Invalid Data
An HTTP 200 response did not always mean the generated draft passed application validation.
One issue involved date-time values with offsets being passed into a model that expected a local time and a separate timezone. Sanitised stage and field-path diagnostics helped identify the mismatch without logging source documents or raw model output.
Approval Must Follow the Version
Editing a merchant proposal can affect comparison results, cancellation rules, and checkout readiness.
The challenge was keeping those dependencies understandable while ensuring that an older approval did not automatically apply to new terms.
Hosted Testing Exposed Different Failures
Database connection timeouts and an exhausted demo payment allowance interrupted the hosted journey.
These issues reinforced the need to distinguish unavailable data, rejected requests, and successful operations—and to investigate the actual backend response rather than infer a cause from a popup closing.
Accomplishments I'm Proud Of
I completed a hosted journey from uploaded evidence through agreement confirmation, booking comparison, cancellation-rule review, and a successful PayPal Sandbox payment.
The cancellation workflow also demonstrated the difference between a $100 refund at the 48-hour cutoff and a $40 refund one minute later, using explicit component rules.
I am particularly proud of preserving the evidence and review history throughout the workflow. Corrections create new versions, while earlier records remain available.
What I Learned
A matching total is only one part of a matching agreement.
Building BeforePay also taught me that useful AI requires more than extraction accuracy. The surrounding application must preserve evidence, expose uncertainty, validate results, and make it clear which decisions still belong to the user.
Testing the complete hosted journey was equally important. Individual components could pass their checks while their interaction still revealed a problem.
What's Next for BeforePay
I want to make the review process shorter and clearer, improve support for different quotation formats, and test BeforePay with rental businesses.
Starting with camera and audiovisual equipment, I plan to explore vehicle rentals and other equipment rentals. These introduce terms such as mileage limits, fuel policies, damage conditions, and late-return charges, requiring review and calculation rules suited to each category.
I also want to extend the workflow beyond payment to cover item returns and deposit refunds. Buyers and merchants could record the return, review the equipment’s condition, and check any proposed deductions against the agreed terms. Once the refund amount is reviewed and approved, the merchant could initiate it through PayPal, with its status linked to the original booking and payment record. Disputed deductions would remain open for resolution.
The current prototype uses simulated buyer and merchant views and sandbox payments. Moving toward everyday use would include separate authenticated accounts, preparation for live payments, and testing with businesses and customers to understand how the full rental process works in practice.
Built With
- alembic
- apimatic
- codex
- css
- docker
- fastapi
- gemini
- genai
- httpx
- javascript
- neon
- postgresql
- pydantic
- pytest
- python
- react
- sqlalchemy
- tailwind
- typescript
- vercel
- vite