Skip to content

askawa/stripe_bot_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stripe Manager Telegram Bot + Django API

A comprehensive Telegram bot integrated with Django that manages Stripe(sandbox) connected accounts. Users can create Stripe accounts, verify their identity, check balances, and manage two revenue flows: receiving payments (Get Paid) or paying for a subscription.

Features

Core Functionality

  • Account Management

    • Create Stripe connected accounts via Telegram
    • One-time verification links for account verification
    • Account status tracking in MySQL database
    • Real-time balance checks
  • Two Transaction Types

    • Get Paid: Users request payouts (max $500 USD) from platform to their connected account
    • Subscription: Users pay for subscription plans (tier options available)
  • Multi-Currency Support

    • Real-time currency conversion via exchange-rate-api.com
    • Automatic conversion between user and platform currencies
    • Support for USD, EUR, CHF
  • Stripe Integration

    • Direct Stripe API integration via custom service layer
    • Connected account onboarding and verification
    • Real-time balance retrieval and management
    • PaymentLinks for subscription payments
    • Test mode support with test cards

Architecture

| Django Project
|   |- Custom Command: python manage.py runbot
|   |- Custom API (stores account info)
|   |- Stripe Services App (Stripe API logic)
|   `- MySQL Database (profile models, verification status)
|
|- Telegram Bot (aiogram 3.x)
|   |- FSM States (Sign-in, Get Paid, Subscription flows)
|   |- Command Handlers (/start)
|   |- Callback Handlers (account selection, payment confirmation)
|   `- Message Handlers (multi-step forms)
|
|- External APIs
|   |- Stripe API (payments, accounts, transfers)
|   `- exchange-rate-api.com (currency conversion)
|
`- Integration Flow
    |- User signs in via Telegram
    |- Bot queries Custom API for account verification status
    |- Currency conversion via exchange-rate-api
    `- Stripe operations (transfers, payment links)

Tech Stack

  • Bot Framework: aiogram 3.x (async)
  • Backend: Django + Python async/await
  • Database: MySQL (account tracking)
  • Payment Processing: Stripe API
  • Currency Conversion: exchange-rate-api.com
  • State Management: aiogram FSM (Finite State Machine)
  • HTTP Client: aiohttp (async requests)

Installation

Prerequisites

  • Python 3.9+
  • Django 4.0+
  • MySQL 8.0+
  • Stripe account (test/live)
  • Telegram Bot Token
  • exchange-rate-api.com API Key

Setup

  1. Clone the repository
git clone https://github.com/askawa/stripe_bot_api.git
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
# .env
TELEGRAM_BOT_TOKEN=your_bot_token
STRIPE_SECRET_API_KEY=sk_test_...
PLATFORM_ACC_ID=acct_...
EXCHANGE_API_KEY=your_api_key
DJANGO_SECRET_KEY=your_secret_key

# MySQL
DB_ENGINE=django.db.backends.mysql
DB_NAME=financelog_db
DB_USER=django_user
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=3306
  1. Run Django migrations
python manage.py makemigrations
python manage.py migrate
  1. Start the Telegram bot and Custom API
python manage.py runbot
python manage.py runserver

Usage

For Users

  1. Start the bot

    • Click /start in drop-down menu in Telegram
  2. Sign Up

    • Click No, I have not option and follow instructions
    • It will require currency, email, confirmation
  3. Sign In

    • Enter email associated with Stripe account
    • Bot retrieves your connected account
  4. Choose Flow

    • Get Paid: Request payout (with currency conversion)
    • Subscription: Pay for subscription plan
  5. Complete Transaction

    • Get Paid: Confirm payout details
    • Subscription: Click PaymentLink and pay with test card

Key Flows

Custom API

Your Django API stores and manages:

  • Account Information: Connected account details and Stripe IDs
  • Verification Status: Account verification capability tracking
  • User Metadata

API Features

  • Account creation and retrieval
  • Verification status updates

File Structure

project/
|- manage.py
|- bot/
|   |- management/
|   |   `- commands/
|   |        `- runbot.py   (Bot startup command)
|   `- finance_bot.py                   
|
|- services/
|   `- stripe_services.py   (All Stripe API logic)
|
|- api/   (Custom API)
|   |- models.py
|   |- serializers.py
|   |- urls.py
|   `- views.py
`- requirements.txt

Stripe Integration Details

Supported Operations

  • Connected Account Creation: Express account onboarding
  • Identity Verification: One-time verification links via onboarding forms
  • Fetching Connected Accounts
  • Balance Checks: Real-time balance retrieval
  • Transfers: Platform to connected accounts (Get Paid flow)
  • PaymentLinks: Hosted payment forms (Subscription flow)
  • Price Objects: Reusable price definitions for subscription plans

Currency Conversion

  • Uses exchange-rate-api.com for real-time conversion rates
  • Supports USD, EUR, GBP, CHF, and more
  • Automatic conversion displayed to users before confirmation
  • Rates checked before each transaction

Error Handling

The bot includes try/except blocks with detailed error messages:

  • Insufficient balance checks
  • Stripe API errors with user-friendly messages
  • State management error recovery

Troubleshooting

Contributing

  1. Create feature branch
  2. Make changes
  3. Test with Stripe test cards
  4. Submit pull request

License

MIT License

Support

For issues or questions:


Last Updated: May 2026

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages