Skip to main content

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:

    pip install django_tbank_kassa
    
  2. Add django_tbank_kassa to your INSTALLED_APPS in the Django settings file:

    INSTALLED_APPS = [
        # ... other apps ...
        'django_tbank_kassa',
    ]
    
  3. Add the following settings to your Django project:

    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:

python manage.py migrate

Views

The library includes views for handling payment creation and retrieving payment details. Add the following to your urls.py:

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:

{
  "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.

Metadata

Release files for django-tbank-kassa 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-tbank-kassa 0.1.1
File Size Uploaded
django_tbank_kassa-0.1.1.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-tbank-kassa 0.1.1
File Interpreter ABI Platform
django_tbank_kassa-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / django_tbank_kassa-0.1.1.tar.gz

Download URL django_tbank_kassa-0.1.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1d7c3c185d00f16a600d84099b6742b7030ac249ab83239bfd5eafbf3e166b61
BLAKE2b-256 checksum
How to use checksums
c81f51c868696657ca4ebf8173b5a3e4faad0625cab8d8a6912e418649d9d492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.11.11 Linux/6.8.0-1017-azure

Release files / django_tbank_kassa-0.1.1-py3-none-any.whl

Download URL django_tbank_kassa-0.1.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49222bff82a256977c2c8348ab0dd8d1901576c059c90ca8243a7e4891a73d59
BLAKE2b-256 checksum
How to use checksums
7358c7771f896948578ae1a7b0822bb60a679af27c22e88a8fa853ed01ce7b09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.11.11 Linux/6.8.0-1017-azure

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page