Hệ thống backend FastAPI sẵn sàng triển khai, tích hợp với PayOS để tạo các liên kết thanh toán QR code động. Được xây dựng đặc biệt để có thể triển khai thông qua Vercel và tích hợp liền mạch với Next.js 15.2 App Router.
PayOS-FastAPI cung cấp dịch vụ backend nhẹ nhưng mạnh mẽ, cho phép ứng dụng của bạn tạo các liên kết thanh toán theo yêu cầu. Nó xử lý tất cả các phức tạp của tích hợp PayOS, cấu hình CORS và thiết lập dựa trên môi trường để bạn có thể tập trung vào việc xây dựng ứng dụng của mình.
- 💰 Tạo yêu cầu thanh toán động thông qua API
- 🔗 Tạo liên kết thanh toán sử dụng PayOS
- 🔒 Thiết lập CORS đầy đủ ngay từ đầu
- ⚙️ Cấu hình dựa trên môi trường thông qua tệp
.env - 📚 Tài liệu API tự động thông qua Swagger UI tại
/api/py/docs - 🚀 Được tối ưu hóa cho việc triển khai Vercel
- ⚡ Hỗ trợ hoàn hảo cho ứng dụng Next.js 15.2 App Router
- Node.js (v16+)
- Python (v3.8+)
- Tài khoản PayOS với thông tin xác thực API
- Sao chép repository:
git clone https://github.com/MaaverGroup/PayOS-FastAPI.git cd PayOS-FastAPI - Thiết lập môi trường ảo Python:
python -m venv venv source venv/bin/activate # Trên Windows: venv\Scripts\activate
- Cài đặt các gói phụ thuộc Python:
pip install -r requirements.txt
- Cài đặt các gói phụ thuộc Node.js:
npm install # hoặc yarn install - Sao chép
.env.exampleđể tạo tệp.envcủa riêng bạn:cp .env.example .env
- Cập nhật tệp
.envvới thông tin xác thực PayOS của bạn:PAYOS_CLIENT_ID=your_client_id PAYOS_API_KEY=your_api_key PAYOS_CHECKSUM_KEY=your_checksum_key CLIENT_DOMAIN=http://localhost:3000/payment
Khởi động máy chủ phát triển:
npm run dev
# hoặc
yarn devAPI của bạn sẽ có sẵn tại http://localhost:3000/api/py với tài liệu Swagger tại http://localhost:3000/api/py/docs.
Dự án này được thiết kế để triển khai trực tiếp lên Vercel:
- Đẩy repository của bạn lên GitHub
- Kết nối repository với Vercel
- Cấu hình các biến môi trường trong bảng điều khiển Vercel
- Triển khai!
Bạn có thể xác minh API đang hoạt động với một yêu cầu GET đơn giản:
curl https://your-vercel-deployment.vercel.app/api/py/helloFastApiPhản hồi:
{
"message": "Hello from FastAPI"
}Tạo liên kết thanh toán với yêu cầu POST sau:
// Ví dụ phía máy khách sử dụng fetch API
const response = await fetch("https://your-vercel-deployment.vercel.app/api/py/create-payment-link", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
description: "Đơn hàng áo thun và quần jean",
items: [
{
name: "Áo thun",
quantity: 1,
price: 100000,
},
{
name: "Quần jean",
quantity: 1,
price: 200000,
},
],
buyer_name: "Nguyễn Văn A",
buyer_email: "nguyen.van.a@example.com",
buyer_phone: "0987654321",
}),
});
const data = await response.json();
const checkoutUrl = data.checkoutUrl;
// Chuyển hướng người dùng đến checkoutUrl để thanh toán
window.location.href = checkoutUrl;Phản hồi:
{
"checkoutUrl": "https://pay.payos.vn/web/xxxxxxxxx"
}Trang thanh toán PayOS sẽ xử lý quy trình thanh toán và chuyển hướng người dùng trở lại URL trả về được chỉ định của bạn sau đó.
Để xem tài liệu API đầy đủ, hãy truy cập Swagger UI tại /api/py/docs.
Chúng tôi hoan nghênh mọi đóng góp! Vui lòng gửi Pull Request.
Dự án này là mã nguồn mở và có sẵn theo Giấy phép MIT.
Được xây dựng và duy trì với ❤️ bởi Maaver Group 🇻🇳
A ready-to-deploy FastAPI backend that integrates with PayOS to generate dynamic QR code payment links. Built specifically to be deployable via Vercel and integrate seamlessly with Next.js 15.2 App Router.
PayOS-FastAPI provides a lightweight yet powerful backend service that enables your application to generate payment links on demand. It handles all the complexities of PayOS integration, CORS configuration, and environment-based setup so you can focus on building your application.
- 💰 Dynamic payment request generation via API
- 🔗 Payment link generation using PayOS
- 🔒 Complete CORS setup out of the box
- ⚙️ Environment-based configuration via
.env - 📚 Automatic API documentation via Swagger UI at
/api/py/docs - 🚀 Optimized for Vercel deployment
- ⚡ Perfect companion for Next.js 15.2 App Router applications
- Node.js (v16+)
- Python (v3.8+)
- PayOS account with API credentials
- Clone the repository:
git clone https://github.com/MaaverGroup/PayOS-FastAPI.git cd PayOS-FastAPI - Set up Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install Python dependencies:
pip install -r requirements.txt
- Install Node.js dependencies:
npm install # or yarn install - Copy
.env.exampleto create your own.envfile:cp .env.example .env
- Update the
.envfile with your PayOS credentials:PAYOS_CLIENT_ID=your_client_id PAYOS_API_KEY=your_api_key PAYOS_CHECKSUM_KEY=your_checksum_key CLIENT_DOMAIN=http://localhost:3000/payment
Start the development server:
npm run dev
# or
yarn devYour API will be available at http://localhost:3000/api/py with Swagger documentation at http://localhost:3000/api/py/docs.
This project is designed to be deployed directly to Vercel:
- Push your repository to GitHub
- Connect the repository to Vercel
- Configure environment variables in Vercel dashboard
- Deploy!
You can verify the API is working with a simple GET request:
curl https://your-vercel-deployment.vercel.app/api/py/helloFastApiResponse:
{
"message": "Hello from FastAPI"
}Generate a payment link with the following POST request:
// Client-side example using fetch API
const response = await fetch("https://your-vercel-deployment.vercel.app/api/py/create-payment-link", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
description: "Order for T-shirt and Jeans",
items: [
{
name: "T-shirt",
quantity: 1,
price: 100000,
},
{
name: "Jeans",
quantity: 1,
price: 200000,
},
],
buyer_name: "John Doe",
buyer_email: "john.doe@example.com",
buyer_phone: "0987654321",
}),
});
const data = await response.json();
const checkoutUrl = data.checkoutUrl;
// Redirect user to checkoutUrl for payment
window.location.href = checkoutUrl;Response:
{
"checkoutUrl": "https://pay.payos.vn/web/xxxxxxxxx"
}The PayOS checkout page will handle the payment process and redirect the user back to your specified return URL afterward.
For complete API documentation, visit the Swagger UI at /api/py/docs.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
Built and maintained with ❤️ by Maaver Group 🇻🇳