Reusable Django payment infrastructure with idempotency and webhook support
Project description
payment_infra
payment_infra is a reusable Django payment package that provides provider integrations, webhook handling, and idempotent payment processing logic you can plug into different Django projects.
Why use this package?
- Reuse payment infrastructure across multiple Django services/projects.
- Start quickly with Paystack charge + verification endpoints.
- Handle webhook events through a structured service layer.
- Reduce duplicate transaction processing with idempotency support.
Installation
Install from PyPI
python -m venv venv # create a virtual environment
pip install payment_infra
Install for local development
git clone "[repo url](https://github.com/0FFSIDE1/payment_infra.git)"
pip install -r requirements.txt
Using payment_infra in any Django project
1) Add the app to INSTALLED_APPS
INSTALLED_APPS = [
# ...
"rest_framework",
"payment_infra",
]
2) Configure environment variables
Typical settings used by providers/runtime:
PAYSTACK_SECRET_KEYPAYSTACK_PUBLIC_KEYPAYSTACK_CALLBACK_URLREDIS_URLDJANGO_SECRET_KEYCACHE_BACKEND
Exact variable wiring depends on your host project's Django settings.
3) Include the package URLs in your project urls
# project/urls.py
from django.urls import include, path
urlpatterns = [
# ...
path("payments", include("payment_infra.api.urls")),
]
With the example above, available endpoints become:
POST /payments/paystack/charge/GET /payments/paystack/verify/<reference>/POST /payments/webhooks/
4) Run migrations
python manage.py migrate
API example
Initiate payment
curl -X POST http://localhost:8000/payments/paystack/charge/ \
-H "Content-Type: application/json" \
-d '{
"email": "customer@example.com",
"amount": "1000.00",
"idempotency_key": "trx-343487629495403" # optional (auto-generated if not provided)
"currency": "NGN",
"callback_url": "https://example.com/callback"
}'
Verify Payment
curl -X GET 'http://localhost:8000/payments/paystack/verify/<reference>/'
- Replace: reference → with the actual reference returned from the charge endpoint.
Asynchronous payment processing example
from payment_infra.infrastructure.tasks.payment_task import process_payment_task
result = process_payment_task.delay(email, amount, currency, idempotency_key, metadata)
NB: You have to configure celery to use asynchronous payment processing
Package architecture
payment_infra/
├── api/ # DRF serializers, views, routes
├── application/ # Service/use-case layer and interfaces
├── domain/ # Core entities
├── infrastructure/ # Providers, repositories, idempotency, tasks
└── migrations/ # Django migrations
This layered design keeps payment orchestration logic decoupled from API and provider implementations, making it easier to extend for additional providers or custom project requirements.
Running tests (repository/local dev)
pytest
Run only integration tests:
pytest -m integration
Run only tests without real integration:
pytest -m "not integration"
Contributing
- Fork the repo
- Create a feature branch
git checkout -b feature/awesome
- Run test after implementing your feature
pytest
- Commit changes
git commit -m 'Add awesome feature'
- Push branch and open a PR
Support
For enterprise inquiries, please contact offsideint@gmail.com
For bugs, open an issue on GitHub.
Built with ❤️ by OFFSIDE INTEGRATED TECHNOLOGY — because developers do not need hassle wiring payments.
License
MIT (see LICENSE).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file payment_infra-1.0.4.tar.gz.
File metadata
- Download URL: payment_infra-1.0.4.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1497999e4c3747f8b7ef9870822b611ba5bad182155004904f2627997127054d
|
|
| MD5 |
9f321b150082f910afb9372a626da053
|
|
| BLAKE2b-256 |
7f84fa0e8107893290aef98f5069345adbd93c7903292d7d9a50070888afd897
|
Provenance
The following attestation bundles were made for payment_infra-1.0.4.tar.gz:
Publisher:
cd.yml on 0FFSIDE1/payment_infra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
payment_infra-1.0.4.tar.gz -
Subject digest:
1497999e4c3747f8b7ef9870822b611ba5bad182155004904f2627997127054d - Sigstore transparency entry: 1160159128
- Sigstore integration time:
-
Permalink:
0FFSIDE1/payment_infra@049c33356249aaeafa31180eb337fd61d060e421 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/0FFSIDE1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@049c33356249aaeafa31180eb337fd61d060e421 -
Trigger Event:
push
-
Statement type:
File details
Details for the file payment_infra-1.0.4-py3-none-any.whl.
File metadata
- Download URL: payment_infra-1.0.4-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d24e2353d96033b42b8762a3e0006415dedd515f19817ec9a9e3b4824e6c3fdf
|
|
| MD5 |
9255fedc4bf42f8c651466d152a873d5
|
|
| BLAKE2b-256 |
a705a2fd5eafe8477c3182f0931b3129c7b1b0687af35e8b0158e4d4022e4bd6
|
Provenance
The following attestation bundles were made for payment_infra-1.0.4-py3-none-any.whl:
Publisher:
cd.yml on 0FFSIDE1/payment_infra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
payment_infra-1.0.4-py3-none-any.whl -
Subject digest:
d24e2353d96033b42b8762a3e0006415dedd515f19817ec9a9e3b4824e6c3fdf - Sigstore transparency entry: 1160159393
- Sigstore integration time:
-
Permalink:
0FFSIDE1/payment_infra@049c33356249aaeafa31180eb337fd61d060e421 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/0FFSIDE1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@049c33356249aaeafa31180eb337fd61d060e421 -
Trigger Event:
push
-
Statement type: