This is a travel application built using Django that allows users to browse listings, make bookings, and process payments through the Chapa payment gateway.
- User authentication and authorization
- Browse and search travel listings
- Create and manage bookings
- Integrated Chapa payment gateway
- Payment verification and status tracking
- Review and rating system
- Python 3.8+
- pip
- PostgreSQL/SQLite (default)
- Chapa API account
git clone <repository-url>
cd alx-travel-apppython -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`pip install -r requirements.txtCreate a .env file in the project root and add the following variables:
SECRET_KEY=your-django-secret-key
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# Database Configuration (Optional - defaults to SQLite)
DATABASE_URL=postgresql://user:password@localhost:5432/alx_travel_db
# Chapa API Configuration
CHAPA_SECRET_KEY=your-chapa-secret-key
CHAPA_PUBLIC_KEY=your-chapa-public-key
# Email Configuration (for payment confirmations)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-email-passwordpython manage.py makemigrations
python manage.py migratepython manage.py setup_db --seedpython manage.py createsuperuserpython manage.py runserverIn a new terminal, activate the virtual environment and run:
celery -A config worker -l infoThe API documentation is available at http://localhost:8000/api/docs/ once the server is running.
POST /api/auth/register/- Register a new userPOST /api/auth/login/- Login user and obtain JWT tokenPOST /api/auth/logout/- Logout user
GET /api/listings/- Retrieve all listingsGET /api/listings/<id>/- Retrieve a specific listingPOST /api/listings/- Create a new listing (authenticated)PUT /api/listings/<id>/- Update a listing (authenticated)DELETE /api/listings/<id>/- Delete a listing (authenticated)
POST /api/bookings/- Create a new booking (authenticated)GET /api/bookings/<id>/- Retrieve a specific booking (authenticated)GET /api/bookings/user/- Retrieve bookings for the logged-in user (authenticated)PUT /api/bookings/<id>/- Update a booking (authenticated)DELETE /api/bookings/<id>/- Cancel a booking (authenticated)
POST /api/payments/initiate/- Initiate a payment (authenticated)
{
"booking_id": "uuid",
"return_url": "http://yourapp.com/success"
}
GET /api/payments/verify/?tx_ref=BK-{booking_id}- Verify payment status (authenticated)GET /api/payments/- Retrieve payment history for the logged-in user (authenticated)GET /api/payments/<id>/- Retrieve a specific payment (authenticated)
- User creates a booking via the
/api/bookings/endpoint.
{
"listing_id": "uuid",
"check_in_date": "2024-01-15",
"check_out_date": "2024-01-20"
}- User initiates payment via the
/api/payments/initiate/endpoint.
{
"booking_id": "booking-uuid",
"return_url": "http://localhost:8000/payment/success"
}{
"payment_url": "https://checkout.chapa.co/checkout/payment/...",
"reference": "BK-booking-uuid",
"status": "success"
}- User is redirected to Chapa's payment page to complete the transaction.
- After payment, Chapa redirects the user to the specified return URL.
- The application verifies the payment status via the
/api/payments/verify/endpoint.
GET /api/payments/verify/?tx_ref=BK-booking-uuid{
"reference": "BK-booking-uuid",
"status": "completed",
"amount": "5000.00"
}alx_travel_app/
├── alx_travel_app/
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── listings/
│ ├── models.py # Listing, Booking, Payment, Review models
│ ├── serializers.py # DRF serializers
│ ├── views.py # ViewSets and API endpoints
│ ├── urls.py # URL routing
│ └── tests.py # Unit tests
├── manage.py
├── requirement.txt
├── .env
└── README.md