# django_tbank_kassa
django_tbank_kassa is a Django library for integrating with Tinkoff Bank's payment system. It simplifies the process of managing payments by providing tools to handle payments and webhooks with minimal setup.
## Features
- Easy integration with Tinkoff Bank's API.
- Handles payment creation and status updates.
- Provides built-in views and serializers for payments.
- Configurable via environment variables.
## Installation
1. Install the package using pip:
```bash
pip install django_tbank_kassa
```
2. Add `django_tbank_kassa` to your `INSTALLED_APPS` in the Django settings file:
```python
INSTALLED_APPS = [
# ... other apps ...
'django_tbank_kassa',
]
```
3. Add the following settings to your Django project:
```python
TBANK_KASSA_TERMINAL_KEY = 'your_terminal_key'
TBANK_KASSA_PASSWORD = 'your_password'
TBANK_KASSA_TEST = True # Set to False for production
```
## Usage
### Configuration
Ensure the following settings are configured in your Django project:
- `TBANK_KASSA_TERMINAL_KEY`: Your Tinkoff Bank terminal key.
- `TBANK_KASSA_PASSWORD`: Your Tinkoff Bank password.
- `TBANK_KASSA_TEST`: Set to `True` for testing mode or `False` for production.
### Payment Model
django_tbank_kassa provides a `Payment` model. Migrations will create the necessary database tables for storing payment details.
Run the migrations:
```bash
python manage.py migrate
```
### Views
The library includes views for handling payment creation and retrieving payment details. Add the following to your `urls.py`:
```python
from django.urls import path
from django_tbank_kassa.generics import ListCreatePaymentView, RetrievePaymentView, TBankWebhookView
urlpatterns = [
path('payments/', ListCreatePaymentView.as_view(), name='list_create_payment'),
path('payments/<str:id>/', RetrievePaymentView.as_view(), name='retrieve_payment'),
path('webhook/', TBankWebhookView.as_view(), name='webhook'),
]
```
### Creating Payments
To create a new payment, send a POST request to the `/payments/` endpoint with the following data:
- `id` (string): A unique identifier for the payment.
- `amount` (decimal): The amount of the payment.
Example:
```json
{
"id": "order123",
"amount": "1000.00"
}
```
The response will include the payment status, a payment ID, and a URL to complete the payment.
### Handling Webhooks
Tinkoff Bank sends webhook events to notify about payment status changes. Configure the webhook URL (e.g., `/webhook/`) in your Tinkoff Bank account settings.
When a webhook is received, the library validates it and updates the corresponding payment status. You can customize the webhook handling by extending the `TBankWebhookView` and overriding its methods if necessary.
## Example Project
Here is an example of integrating django_tbank_kassa into a Django project:
1. Add the app and configure the settings as described above.
2. Add the provided URLs to your `urls.py`.
3. Use the `/payments/` endpoint to create and manage payments.
4. Register the webhook URL with Tinkoff Bank.
Raw data
{
"_id": null,
"home_page": "https://github.com/RostHarcha/django-tbank-kassa",
"name": "django-tbank-kassa",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": null,
"author": "Rostislaww",
"author_email": "rostiki.com@mail.ru",
"download_url": "https://files.pythonhosted.org/packages/c8/1f/51c868696657ca4ebf8173b5a3e4faad0625cab8d8a6912e418649d9d492/django_tbank_kassa-0.1.1.tar.gz",
"platform": null,
"description": "# django_tbank_kassa\n\ndjango_tbank_kassa is a Django library for integrating with Tinkoff Bank's payment system. It simplifies the process of managing payments by providing tools to handle payments and webhooks with minimal setup.\n\n## Features\n\n- Easy integration with Tinkoff Bank's API.\n- Handles payment creation and status updates.\n- Provides built-in views and serializers for payments.\n- Configurable via environment variables.\n\n## Installation\n\n1. Install the package using pip:\n ```bash\n pip install django_tbank_kassa\n ```\n\n2. Add `django_tbank_kassa` to your `INSTALLED_APPS` in the Django settings file:\n ```python\n INSTALLED_APPS = [\n # ... other apps ...\n 'django_tbank_kassa',\n ]\n ```\n\n3. Add the following settings to your Django project:\n ```python\n TBANK_KASSA_TERMINAL_KEY = 'your_terminal_key'\n TBANK_KASSA_PASSWORD = 'your_password'\n TBANK_KASSA_TEST = True # Set to False for production\n ```\n\n## Usage\n\n### Configuration\n\nEnsure the following settings are configured in your Django project:\n\n- `TBANK_KASSA_TERMINAL_KEY`: Your Tinkoff Bank terminal key.\n- `TBANK_KASSA_PASSWORD`: Your Tinkoff Bank password.\n- `TBANK_KASSA_TEST`: Set to `True` for testing mode or `False` for production.\n\n### Payment Model\n\ndjango_tbank_kassa provides a `Payment` model. Migrations will create the necessary database tables for storing payment details.\n\nRun the migrations:\n```bash\npython manage.py migrate\n```\n\n### Views\n\nThe library includes views for handling payment creation and retrieving payment details. Add the following to your `urls.py`:\n\n```python\nfrom django.urls import path\nfrom django_tbank_kassa.generics import ListCreatePaymentView, RetrievePaymentView, TBankWebhookView\n\nurlpatterns = [\n path('payments/', ListCreatePaymentView.as_view(), name='list_create_payment'),\n path('payments/<str:id>/', RetrievePaymentView.as_view(), name='retrieve_payment'),\n path('webhook/', TBankWebhookView.as_view(), name='webhook'),\n]\n```\n\n### Creating Payments\n\nTo create a new payment, send a POST request to the `/payments/` endpoint with the following data:\n\n- `id` (string): A unique identifier for the payment.\n- `amount` (decimal): The amount of the payment.\n\nExample:\n```json\n{\n \"id\": \"order123\",\n \"amount\": \"1000.00\"\n}\n```\nThe response will include the payment status, a payment ID, and a URL to complete the payment.\n\n### Handling Webhooks\n\nTinkoff Bank sends webhook events to notify about payment status changes. Configure the webhook URL (e.g., `/webhook/`) in your Tinkoff Bank account settings.\n\nWhen a webhook is received, the library validates it and updates the corresponding payment status. You can customize the webhook handling by extending the `TBankWebhookView` and overriding its methods if necessary.\n\n## Example Project\n\nHere is an example of integrating django_tbank_kassa into a Django project:\n\n1. Add the app and configure the settings as described above.\n2. Add the provided URLs to your `urls.py`.\n3. Use the `/payments/` endpoint to create and manage payments.\n4. Register the webhook URL with Tinkoff Bank.\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/RostHarcha/django-tbank-kassa"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7358c7771f896948578ae1a7b0822bb60a679af27c22e88a8fa853ed01ce7b09",
"md5": "aeeda4735449df02c6635717f76ffec2",
"sha256": "49222bff82a256977c2c8348ab0dd8d1901576c059c90ca8243a7e4891a73d59"
},
"downloads": -1,
"filename": "django_tbank_kassa-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aeeda4735449df02c6635717f76ffec2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 8251,
"upload_time": "2025-01-20T23:45:58",
"upload_time_iso_8601": "2025-01-20T23:45:58.305259Z",
"url": "https://files.pythonhosted.org/packages/73/58/c7771f896948578ae1a7b0822bb60a679af27c22e88a8fa853ed01ce7b09/django_tbank_kassa-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c81f51c868696657ca4ebf8173b5a3e4faad0625cab8d8a6912e418649d9d492",
"md5": "1025d610e3419942351bb28b0beaf051",
"sha256": "1d7c3c185d00f16a600d84099b6742b7030ac249ab83239bfd5eafbf3e166b61"
},
"downloads": -1,
"filename": "django_tbank_kassa-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "1025d610e3419942351bb28b0beaf051",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 4705,
"upload_time": "2025-01-20T23:45:59",
"upload_time_iso_8601": "2025-01-20T23:45:59.891530Z",
"url": "https://files.pythonhosted.org/packages/c8/1f/51c868696657ca4ebf8173b5a3e4faad0625cab8d8a6912e418649d9d492/django_tbank_kassa-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-20 23:45:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RostHarcha",
"github_project": "django-tbank-kassa",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-tbank-kassa"
}