An AI-powered payments operations assistant built as a take-home assessment for Replicant.
The application provides:
- A web-based AI payments assistant for business owners
- Natural-language payment operations
- Stripe payment and invoice management
- Daily payment summaries generated with an LLM
- Week-over-week payment comparison
- Payment refunds
- Invoice creation
- A privacy-preserving Telegram customer payment bot
- Stripe-hosted payment pages
- Safety controls for high-value customer payments
┌─────────────────────────┐
│ React UI │
│ TypeScript/Vite │
└────────────┬────────────┘
│
│ HTTP
▼
┌─────────────────────────┐
│ FastAPI API │
│ │
│ AssistantService │
│ StripeService │
│ LLMService │
└───────┬─────────┬───────┘
│ │
┌────────────┘ └─────────────┐
▼ ▼
┌──────────────────┐ ┌─────────────────┐
│ Stripe │ │ OpenAI │
│ │ │ │
│ Payments │ │ Intent parsing │
│ Customers │ │ Summaries │
│ Invoices │ │ │
│ Refunds │ │ │
└──────────────────┘ └─────────────────┘
┌─────────────────────────┐
│ Telegram Bot │
│ │
│ Customer authentication │
│ Own invoices/payments │
│ Payment workflow │
└────────────┬────────────┘
│
▼
┌──────────────┐
│ Stripe │
└──────────────┘
- Python 3.12
- FastAPI
- Stripe Python SDK
- OpenAI API
- Pydantic
- python-dotenv / pydantic-settings
- Python Telegram Bot
- Pytest
- React
- TypeScript
- Vite
- CSS
- Stripe Test Mode
- OpenAI
- Telegram Bot API
replicant-payments-assistant/
│
├── backend/
│ ├── app/
│ │ ├── __init__.py
│ │ │
│ │ ├── api/
│ │ │ ├── __init__.py
│ │ │ └── routes/
│ │ │ ├── __init__.py
│ │ │ ├── health.py
│ │ │ ├── assistant.py
│ │ │ ├── payments.py
│ │ │ ├── invoices.py
│ │ │ └── customers.py
│ │ │
│ │ ├── core/
│ │ │ ├── __init__.py
│ │ │ └── config.py
│ │ │
│ │ ├── schemas/
│ │ │ ├── __init__.py
│ │ │ ├── assistant.py
│ │ │ └── invoice.py
│ │ │
│ │ └── services/
│ │ ├── __init__.py
│ │ ├── stripe_service.py
│ │ ├── assistant_service.py
│ │ ├── llm_service.py
│ │ └── telegram_service.py
│ │
│ ├── tests/
│ ├── seed.py
│ ├── telegram_bot.py
│ ├── .env
│ ├── .env.example
│ └── .gitignore
│
├── frontend/
│ ├── src/
│ ├── public/
│ ├── package.json
│ ├── tsconfig.json
│ ├── vite.config.ts
│ └── ...
│
├── README.md
├── write-up.md
├── .gitignore
└── .env.example
Install the following before starting:
- Python 3.12+
- Node.js 18+
- npm
- Stripe account
- Stripe test API key
- OpenAI API key
- Telegram bot token
Everything in this project should be run against Stripe test mode.
No real money should be involved.
git clone https://github.com/ajayKomirishetty/replicant-payment-assistant
cd replicant-payments-assistantMove into the backend directory:
cd backendCreate a Python virtual environment:
python3.12 -m venv .venvActivate it:
source .venv/bin/activate.venv\Scripts\activateVerify Python:
python --versionExpected:
Python 3.12.x
Upgrade pip:
python -m pip install --upgrade pipInstall application dependencies:
python -m pip install fastapi "uvicorn[standard]" stripe python-dotenv pydantic-settings openai python-telegram-botInstall test dependencies:
python -m pip install pytestAlternatively, if a requirements.txt file is provided:
python -m pip install -r requirements.txtCreate:
backend/.env
Example:
STRIPE_SECRET_KEY=sk_test_...
OPENAI_API_KEY=sk-...
TELEGRAM_BOT_TOKEN=...Do not commit .env to Git.
The repository includes .env.example as a template.
Create or use a Stripe account in test mode.
The application expects a Stripe test secret key:
STRIPE_SECRET_KEY=sk_test_...
Stripe test mode is important because this application creates payments, invoices, refunds, and payment links.
No real payments should be made.
Set:
OPENAI_API_KEY=your_openai_api_keyThe application uses the LLM for:
- Natural-language command interpretation
- Daily payment summary generation
The LLM is not responsible for directly executing financial operations.
Instead, the architecture is:
User message
│
▼
LLM
│
│ structured command
▼
Python validation
│
▼
Stripe API
This keeps financial actions deterministic and separates interpretation from execution.
Create a Telegram bot using BotFather.
Set the token:
TELEGRAM_BOT_TOKEN=your_telegram_bot_tokenThe Telegram bot is intended for customers rather than business administrators.
Customers authenticate using their Stripe customer email.
The bot only accesses the Stripe customer associated with the authenticated Telegram session.
From:
backend/
run:
python seed.pyThe seed script creates the sample Stripe data required by the application.
The sample data includes customers such as:
- Maya Johnson
- Acme Corp
- John Smith
- Sarah Williams
It also creates test payment activity and invoices.
The seed script uses Stripe test mode.
From:
backend/
activate the virtual environment:
source .venv/bin/activateStart FastAPI:
uvicorn app.main:app --reloadThe backend will normally be available at:
http://localhost:8000
FastAPI documentation:
http://localhost:8000/docs
GET /healthExample:
curl http://localhost:8000/healthGET /api/paymentsExample:
curl http://localhost:8000/api/paymentsPOST /api/payments/{payment_id}/refundExample:
curl -X POST \
http://localhost:8000/api/payments/pi_xxx/refundGET /api/customersExample:
curl http://localhost:8000/api/customersGET /api/customers/{name_or_email}Example:
curl http://localhost:8000/api/customers/Maya%20JohnsonGET /api/customers/{name_or_email}/latest-paymentExample:
curl http://localhost:8000/api/customers/Maya%20Johnson/latest-paymentGET /api/invoicesExample:
curl http://localhost:8000/api/invoicesPOST /api/invoicesExample:
curl -X POST \
http://localhost:8000/api/invoices \
-H "Content-Type: application/json" \
-d '{
"customer": "Acme Corp",
"amount": 25000,
"description": "Test invoice",
"days_until_due": 7
}'The API accepts the invoice amount in cents.
For example:
25000 = $250.00
The main assistant endpoint is:
POST /api/assistantRequest:
{
"message": "Refund Maya's last payment"
}Example:
curl -X POST \
http://localhost:8000/api/assistant \
-H "Content-Type: application/json" \
-d '{
"message": "Refund Maya'\''s last payment"
}'The assistant extracts the user's intent and relevant information.
Supported intents include:
refund_payment
create_invoice
payment_comparison
daily_summary
Summarize my day
or:
How did payments look today?
The backend retrieves today's payment activity and sends the structured payment information to the LLM.
The LLM generates a concise natural-language summary.
Refund Maya's last payment
The LLM identifies:
intent = refund_payment
customer = Maya Johnson
Python then:
- Finds Maya's Stripe customer
- Finds her latest refundable payment
- Validates that the payment succeeded
- Checks the remaining refundable amount
- Creates the Stripe refund
The LLM does not execute the refund itself.
Create a $250 invoice for Acme Corp due next Friday
The LLM extracts:
intent = create_invoice
customer = Acme Corp
amount = 250
due_date = next Friday
Python then validates the information and creates the Stripe invoice.
How much did we take last week compared to the week before?
The backend calculates the payment totals deterministically from Stripe data.
The calculation is not delegated to the LLM.
Example:
We took $7,570.00 this week compared with $0.00 last week — no previous-week revenue to compare against.
Open a second terminal.
From the project root:
cd frontendInstall dependencies:
npm installStart the development server:
npm run devVite will display the local frontend URL.
Typically:
http://localhost:5173
The frontend communicates with:
http://localhost:8000
for the FastAPI backend.
The frontend provides a chatbot-style interface.
Example commands:
Summarize my day
Refund Maya's last payment
Create a $250 invoice for Acme Corp due next Friday
How much did we take last week compared to the week before?
The UI displays:
- User messages
- Assistant responses
- Suggested commands
- Loading state
- Error messages
The Telegram bot runs separately from FastAPI.
From:
backend/
activate the virtual environment:
source .venv/bin/activateRun:
python telegram_bot.pyThe bot starts polling Telegram.
A customer starts the bot with:
/start
The bot asks for the customer's email.
For example:
maya@example.com
The application looks up the Stripe customer by email.
After successful authentication, the Telegram chat is associated with the Stripe customer.
The customer can then ask:
What is my latest payment?
Show my invoices
Pay my invoice
The Telegram bot intentionally has a more restricted permission model than the business-owner web assistant.
A customer can only access:
Their own payments
Their own invoices
Their own payment links
The customer cannot access:
Other customers
Other customers' invoices
Other customers' payments
Business revenue
Total account revenue
Account-level financial information
Customer-specific Stripe IDs are obtained from the authenticated session rather than being accepted directly from user input.
For example, the bot does not allow a customer to provide:
cus_other_customer
and retrieve that customer's information.
A customer can ask:
Pay my invoice
The bot retrieves only open invoices belonging to the authenticated customer.
If there is an open invoice, the bot provides Stripe's hosted invoice payment page.
Example:
Your invoice is $250.00 CAD.
You can securely pay it here:
https://invoice.stripe.com/...
The payment itself is completed through Stripe's hosted payment page.
The Telegram bot does not collect or store card information.
The assessment requires that payments of $2,000 or more cannot be completed by the Telegram bot.
The bot therefore checks the invoice amount before providing a payment workflow.
For example:
Your invoice is $2,500.00 CAD.
Payments of $2,000 or more require business-owner approval
and cannot be completed by this bot.
Please contact the business owner to complete the payment.
This rule is enforced in application code rather than relying on the LLM.
The project intentionally separates AI interpretation from financial execution.
The LLM can determine:
What is the user asking for?
But it cannot directly perform:
Stripe refund
Stripe payment
Stripe invoice creation
Instead:
User
↓
LLM
↓
Structured command
↓
Application validation
↓
StripeService
↓
Stripe
This makes it possible to apply deterministic validation around financial actions.
Examples include:
- Customer must exist
- Payment must be refundable
- Refund cannot exceed the remaining refundable amount
- Invoice amount must be positive
- Invoice due date must be in the future
- Telegram customer must be authenticated
- Telegram customer can only access their own Stripe resources
- Telegram payments >= $2,000 are blocked
The application does not assume that every Stripe customer uses USD.
For example, a customer may have an invoice in CAD.
When creating an invoice, the application uses the Stripe invoice's currency when creating its invoice item.
This prevents Stripe errors caused by mixing currencies on a single invoice.
For example:
Invoice currency: CAD
Invoice item currency: CAD
Run tests from the backend directory:
cd backend
source .venv/bin/activate
python -m pytestFor verbose output:
python -m pytest -vA basic end-to-end test can be performed in the following order.
Start the backend:
cd backend
source .venv/bin/activate
uvicorn app.main:app --reloadStart the frontend in another terminal:
cd frontend
npm run devOpen the frontend.
Try:
Summarize my day
Try:
How much did we take last week compared to the week before?
Try:
Refund Maya's last payment
Try:
Create a $250 invoice for Acme Corp due next Friday
Start Telegram:
cd backend
source .venv/bin/activate
python telegram_bot.pyOpen the Telegram bot.
Send:
/start
Then authenticate using a seeded customer email.
For example:
maya@example.com
Then try:
What is my latest payment?
Show my invoices
Pay my invoice
The project intentionally uses a single repository containing both applications.
replicant-payments-assistant/
├── backend/
├── frontend/
├── README.md
└── write-up.md
This makes the take-home easier to evaluate because the complete system is contained in one repository.
The repository should contain:
.env.example
but should not contain real credentials.
For example:
STRIPE_SECRET_KEY=
OPENAI_API_KEY=
TELEGRAM_BOT_TOKEN=The real:
.env
must remain ignored by Git.
From the project root:
git statusMake sure secrets are not tracked.
Check:
git ls-files | grep ".env"You should not see your real .env file.
Check that virtual environments are ignored:
git status --ignoredThe following should not be committed:
backend/.venv/
frontend/node_modules/
.env
The repository should ignore at least:
# Environment
.env
.env.*
!.env.example
# Python
__pycache__/
*.py[cod]
.pytest_cache/
.venv/
venv/
*.egg-info/
# Node
node_modules/
dist/
# macOS
.DS_Store
# IDE
.idea/
.vscode/FastAPI provides a small, straightforward API layer with:
- Type validation
- Automatic API documentation
- Async support
- Simple route organization
- Good fit for an AI/Stripe integration
The assessment is a proof of concept, so a lightweight backend was preferable to introducing unnecessary infrastructure.
The frontend is a single-page chatbot application.
React provides a simple component model while TypeScript provides stronger type safety around API responses and UI state.
The application only requires a small number of LLM operations:
- Structured command extraction
- Daily summary generation
Using the OpenAI API directly keeps the implementation simple and makes the control flow explicit.
A framework such as LangChain or LangGraph was not necessary for this proof of concept.
The Telegram bot does not collect card information.
Instead, it provides Stripe's hosted payment page.
This keeps payment handling inside Stripe and reduces the amount of sensitive payment data handled by the application.
This is intentionally a proof of concept.
Some areas that would be improved for production include:
The current Telegram authentication mapping is stored in memory.
chat_id -> stripe_customer_id
A production implementation would persist this relationship in PostgreSQL.
This would allow sessions to survive application restarts and support multiple application instances.
The demo authenticates Telegram users using their customer email.
A production implementation should use a stronger identity verification mechanism, such as:
- Magic link
- OTP
- Verified customer account
- Signed customer token
- Stripe Customer Portal authentication
The seed script is designed for a fresh Stripe test account.
A production-quality seed system would use deterministic metadata or identifiers to make repeated executions completely idempotent.
Daily summaries currently use UTC boundaries.
A production implementation should use the business's configured timezone.
Some Stripe queries use bounded limits for the proof of concept.
A production system should implement Stripe pagination when processing larger accounts.
The web assistant is designed as the business-owner interface.
A production implementation would add explicit authentication and authorization around the business-owner API.
The LLM command parser currently supports the core commands required by the assessment.
A production implementation could support more flexible commands such as:
Refund the payment Maya made yesterday
Create an invoice for Acme for $500 CAD due in 30 days
Show me failed payments from this month
With more development time, I would add:
- PostgreSQL persistence
- Proper business-owner authentication
- Role-based authorization
- Idempotency keys for financial mutations
- Stripe webhook processing
- Persistent Telegram customer sessions
- Better customer verification
- Audit logs for financial operations
- Confirmation steps before destructive actions
- More comprehensive automated tests
- Stripe pagination
- Configurable business timezone
- Observability and structured logging
- Rate limiting
- More detailed payment analytics
- Production deployment configuration
Financial mutations are intentionally protected by application-level validation.
For example, for a refund:
User:
"Refund Maya's last payment"
↓
LLM extracts:
intent = refund_payment
customer = Maya
↓
Application:
Find Maya
↓
Find latest refundable payment
↓
Verify payment succeeded
↓
Verify remaining refundable amount
↓
Create Stripe refund
The LLM never receives unrestricted access to Stripe.
| Requirement | Implementation |
|---|---|
| Backend server | FastAPI |
| Stripe integration | Stripe Python SDK |
| LLM integration | OpenAI API |
| Daily summary | Implemented |
| Natural language commands | Implemented |
| Refund payment | Implemented |
| Create invoice | Implemented |
| Payment comparison | Implemented |
| React SPA | Implemented |
| Chatbot interface | Implemented |
| Telegram bot | Implemented |
| Customer-specific access | Implemented |
| Privacy restrictions | Implemented |
| $2,000 payment restriction | Implemented |
| Stripe payment workflow | Implemented |
| Seed script | Implemented |
| Automated tests | Pytest |
| Architecture documentation | This README |
| Assumptions/challenges/limitations | write-up.md |
For an evaluator, the shortest path is:
cd backend
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install fastapi "uvicorn[standard]" stripe python-dotenv pydantic-settings openai python-telegram-bot pytest
# Configure .env first
python seed.py
uvicorn app.main:app --reloadcd frontend
npm install
npm run devcd backend
source .venv/bin/activate
python telegram_bot.pyThis project is designed as a small but complete proof of concept.
The main architectural principle is:
Use AI for interpretation and communication, but keep financial operations deterministic and controlled by application code.
Stripe remains the source of truth for payments, invoices, refunds, and customer financial data.
The web assistant is designed for the business owner, while the Telegram bot is deliberately restricted to the authenticated customer's own financial information.