Project is made with Python and Django Rest Framework
- POST /api/v1/create_charge -
request data -
{
"amount": int,
"currency": string,
"description": string,
"card_number": string,
"card_exp_month": int,
"card_exp_year": int,
"card_cvc": string
}
Example:
{
"amount": 10000,
"currency": "INR",
"description": "First Payment",
"card_number": "4242424242424242",
"card_exp_month": 1,
"card_exp_year": 2025,
"card_cvc": "100"
}
- POST /api/v1/capture_charge/:chargeId - Capture the created charge
- POST /api/v1/create_refund/:chargeId - Refund created charge
- GET /api/v1/get_charges - Get list of all charges
- Django==3.2.6
- djangorestframework==3.12.4
- stripe==2.60
Python 3 is intalled on your system
- Open terminal in stripe_payment directory
- Run Following commands
# Create Virual Environment
python -m venv ./venv
# Activate Virtual Environment
./venv/Scripts/Activate
# Install Dependencies
pip install -r requirements.txt
Once dependencies are installed run following
# Sets up migrations scripts to create/update/delete Models if any in database
python manage.py makemigrations
# Runs the migrations
python manage.py migrate
Before running the service we need to set STRIPE_API_KEY
environment variable.
# Windows Powershell
$ENV:STRIPE_API_KEY = '<your stripe api key>'
# Windows CMD
set STRIPE_API_KEY=<your stripe api key>
# Linux
export STRIPE_API_KEY='<your stripe api key>'
Run the server
python manage.py runserver
python manage.py test
Root:
| - README.md
|
|---stripe_payment
| - manage.py
| - requirements.txt
|
|---payments (module)
| | - apps.py
| | - serializers.py
| | - tests.py
| | - urls.py
| | - utils.py
| | - views.py
| |
| |---services
| - stripe.py
|
|---stripe_payment (core App)
- asgi.py
- settings.py
- urls.py
- wsgi.py
- payments/urls.py - Contains Routes to the endpoints binded with views
- payments/serializers.py - Serializing the request
- payments/views.py - Entry point to execute code for endpoints
- payments/services/stripe.py