https://github.com/elian3x14/fastapi_vnpay_integration
https://github.com/elian3x14/fastapi_vnpay_integration
fastapi self-learning-project vnpay
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/elian3x14/fastapi_vnpay_integration
- Owner: Elian3x14
- Created: 2025-03-05T12:22:59.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-05T15:29:58.000Z (over 1 year ago)
- Last Synced: 2025-08-21T16:04:13.575Z (10 months ago)
- Topics: fastapi, self-learning-project, vnpay
- Language: Python
- Homepage:
- Size: 1.42 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# FastAPI VNPAY Integration
## Description
This project integrates VNPAY with FastAPI to handle online payments.
## Installation Guide
1. Install Python 3.9+.
2. Create a virtual environment:
```sh
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
```
3. Install required dependencies:
```sh
pip install -r requirements.txt
```
4. Set up the `.env` file:
```env
VNPAY_URL=
VNPAY_TMN_CODE=
VNPAY_HASH_SECRET=
VNPAY_RETURN_URL=
```
5. Run the application with FastAPI:
```sh
uvicorn main:app --reload
```
## How to Create a VNPAY Account (Sandbox)
**Access the VNPAY Sandbox Page**
1. Register an account by providing your **email** and necessary details.
2. After successful registration, you will receive the required credentials:
- **vnp_TmnCode**: Test merchant site code.
- **vnp_HashSecret**: Secret key for data encryption.
- **API Endpoint**: Test payment API endpoint.
## API Endpoints
- `GET /create_payment?amount=100000&order_desc=Order Payment`
- `GET /vnpay_return` - Receive transaction results from VNPAY
## Workflow Diagram
```mermaid
sequenceDiagram
participant User
participant Website
participant VNPAY
User->>Website: 1. Request payment
Website->>VNPAY: 2. Send transaction request
VNPAY-->>Website: 3. Return payment URL
Website->>User: 4. Redirect to VNPAY
User->>VNPAY: 5. Enter payment details
VNPAY-->>Website: 6. Send transaction result
Website->>User: 7. Display transaction result
```
## Test Results
**Request Payment**

**Server redirects to VNPAY's payment URL**

**Enter Card Information**
[Link: Test Payment Account](https://sandbox.vnpayment.vn/apis/vnpay-demo/)

**Payment Result**
*Modify the logic to match your application needs*

## Notes
If you encounter any issues, feel free to reach out for support!