A complete full-stack example of a modern Telegram Mini App for selling digital products using Telegram Stars payments. Built with Next.js 15, TypeScript, Tailwind CSS, and Telegram Bot API, this app includes secure invoice generation, purchase history, secret content access after purchase, and refund processing via a Python companion bot. Ideal for Web3 developers, Telegram bot creators, and digital entrepreneurs looking to monetize through Telegram's payment ecosystem.
Note: This application is designed to work exclusively within the Telegram ecosystem as a Telegram Mini App. It should be accessed only through Telegram and not directly via a web browser.
- 💸 Telegram Stars integration for payments
- 🔄 Purchase history tracking
- 📱 Responsive design optimized for Telegram WebApp
- 🔑 Secret code delivery for purchased digital items
- 🔄 Refund support via companion bot
- Node.js 18+ and npm
- A Telegram bot token (obtained from BotFather)
- Python 3.7+ (for the companion bot)
- Vercel account (for deployment)
git clone https://github.com/nikandr-surkov/telegram-mini-app-stars-payments.git
cd telegram-mini-app-stars-payments
npm installnpm run buildNote: The app will only function correctly when accessed through Telegram.
For the companion bot with refund capabilities, visit the separate repository: Python Telegram Bot with Stars Payment
As this is a Telegram Mini App, it must be deployed and accessed through Telegram. Follow these steps:
- Push your code to a GitHub repository
- Sign up for a Vercel account if you haven't already
- Connect your GitHub repository to Vercel and deploy the app
- During deployment, add your
BOT_TOKENas an environment variable in the Vercel dashboard - Once deployed, Vercel will provide you with a URL for your app
- Use this URL to set up your Telegram Mini App:
- Go to @BotFather on Telegram
- Send the command
/newappor choose to edit an existing bot - Follow the prompts to set up your Mini App, using the Vercel URL as the Web App URL
- Once set up, you can access your Mini App through Telegram on mobile devices or in the Web version of Telegram
/app- Next.js application/api- API routes for invoice creation, payment processing, and purchase history/components- React UI components (modals, cards, loaders, etc.)/data- Shared item definitions and configurations/server- Server-only code, including sensitive data like secret codes/types- TypeScript type definitions and interfacespage.tsx- Main application componentlayout.tsx- Root layout componentglobals.css- Global styles
/public- Static assets
- User clicks "Buy" on a digital item
- App creates an invoice through Telegram Bot API
- Telegram shows the payment interface
- User approves the payment with Stars
- App receives a success callback and shows the secret code
- Purchase is recorded in the history
- User requests a refund through the companion Telegram bot
- Bot processes the refund using Telegram's API
- Stars are returned to the user's account
- 🌐 Website: nikandr.com
- 📺 YouTube: @NikandrSurkov
- 📱 Telegram: @nikandr_s
- 📢 Telegram Channel: Nikandr's Apps
- 📰 Clicker Game News: Clicker Game News
- 💻 GitHub: nikandr-surkov
- 🐦 Twitter: @NikandrSurkov
- 💼 LinkedIn: Nikandr Surkov
- ✍️ Medium: @NikandrSurkov