Skip to main content

Application for integrating Django and https://online.atol.ru/

https://img.shields.io/badge/python-3.5,%203.6,%203.7,%203.8,%203.9,%203.10-blue.svg https://travis-ci.org/MyBook/django-atol.svg?branch=master https://codecov.io/gh/MyBook/django-atol/branch/master/graph/badge.svg https://img.shields.io/badge/docs-v3-yellow.svg

Important limitations:

  • Python 3.5+

  • Support Django 1.11+

  • PostgreSQL ≥ 9.4 (JSONB field) (PostgreSQL ≥ 11 for Django 4.0)

  • only 1 purchase is supported in receipt (1 product)

  • only v3 protocol version is supported

Quick start

  1. Add atol to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'atol',
    ]
  2. Add atol settings like this:

    RECEIPTS_ATOL_LOGIN = 'login'
    RECEIPTS_ATOL_PASSWORD = 'secret'
    RECEIPTS_ATOL_GROUP_CODE = 'ATOL-ProdTest-1'
    RECEIPTS_ATOL_TAX_NAME = 'vat18'
    RECEIPTS_ATOL_TAX_SYSTEM = 'osn'
    RECEIPTS_ATOL_INN = '112233445573'
    RECEIPTS_ATOL_PAYMENT_METHOD = 'full_payment'
    RECEIPTS_ATOL_PAYMENT_OBJECT = 'service'
    RECEIPTS_ATOL_CALLBACK_URL = None
    RECEIPTS_ATOL_PAYMENT_ADDRESS = 'www.<your_company>.ru'
    RECEIPTS_ATOL_COMPANY_EMAIL = '<your_company>@gmail.com'
    RECEIPTS_OFD_URL_TEMPLATE = u'https://lk.platformaofd.ru/web/noauth/cheque?fn={fn}&fp={fp}'
  3. Add celery-beat tasks to CELERYBEAT_SCHEDULE settings like this:

    CELERYBEAT_SCHEDULE = {
        ...
        'atol_retry_created_receipts': {
            'task': 'atol_retry_created_receipts',
            'schedule': crontab(minute=25)
        },
        'atol_retry_initiated_receipts': {
            'task': 'atol_retry_initiated_receipts',
            'schedule': crontab(minute=35)
        }
    }
  4. Include the atol URLconf in your project urls.py like this:

    from atol.views import ReceiptView
    
    url(r'^r/(?P<short_uuid>[\w]+)/$', ReceiptView.as_view(), name='receipt')
  5. Run python manage.py migrate atol to create the receipt model.

  6. Add receipt field to your payment model:

    from atol.models import Receipt
    
    receipt = models.OneToOneField(Receipt, verbose_name=_('Чек'), blank=True, null=True, on_delete=models.SET_NULL)
  7. Add the mechanics of calling a receipt creation after a successful payment. For example, this can be done through a signal that will be called upon successful payment:

    # <your_app>/signals.py
    
    payment_accepted = Signal(providing_args=['payment'])
    
    # <your_app>/providers/googleplay.py
    
    def process_payment(payment)
    
        ...
    
        payment_accepted.send(sender='google-play', payment=payment)
    
    # <your_app>/receivers.py
    
    @receiver(payment_accepted)
    @transaction.atomic
    def init_payment_receipt(sender, payment, **kwargs):
    
        ...
    
        receipt = Receipt.objects.create(
            user_email=payment.user.email,
            purchase_price=payment.amount
        )
        payment.receipt = receipt
        payment.save(update_fields=['receipt'])
        transaction.on_commit(
            lambda: atol_create_receipt.apply_async(args=(receipt.id,), fallback_sync=True)
        )

Run tests

pytest

Changelog

1.4.1 (2022-09-13)

  • Fix JSONField module for django>=3.1

1.4.0 (2022-08-17)

  • Add Django 4.0 support

  • Add Python ≥ 3.7 and Django ≥ 3.0 CI tests

  • Upgrade CI Linux dist to Ubuntu 18.04 (Bionic) for Python 3.10 tests

  • Upgrade CI Postgres version to 11 for Django 4.x tests

1.3.4 (2021-10-05)

  • Fix bug with payment_method parameter

1.3.3 (2021-06-28)

  • Add task for sell_refund request

1.3.2 (2020-08-17)

  • Upgrade shortuuid 0.5.0 -> 1.0.1

1.3.1 (2018-12-19)

  • Sell method: do not insert empty email or phone

1.3.0 (2018-12-19)

  • Support Atol protocol v4 (FFD 1.05)

1.2.2 (2018-10-08)

  • Change maximum retry counts for task atol_receive_receipt_report. Now its awaiting report for 29 hours.

  • Changed atol_retry_created_receipts and atol_retry_initiated_receipts tasks retry period. Now it will retry receipts from day before yesterday

1.2.1 (2018-05-22)

  • AtolAPI.base_url specifying in settings

1.2.0 (2017-12-14)

  • Support retried not processed receipt

1.1.0 (2017-12-13)

  • Django 2.0 support

1.0.0 (2017-12-01)

  • Initial release

Metadata

Release files for django-atol 1.4.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-atol 1.4.1
File Size Uploaded
django-atol-1.4.1.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-atol 1.4.1
File Interpreter ABI Platform
django_atol-1.4.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 39.2 kB

Release files / django-atol-1.4.1.tar.gz

Download URL django-atol-1.4.1.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
370f22a58c23dc95092b240035b891d3367b77f650f5ec2682845b29bdf7d2cc
BLAKE2b-256 checksum
How to use checksums
abaa7fc22d727be3f27ef61576c68db55d3630f6a17adde2e19a3d68ef518d14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.9

Release files / django_atol-1.4.1-py2.py3-none-any.whl

Download URL django_atol-1.4.1-py2.py3-none-any.whl
Size 16.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d69d4adc24c055fff49cde967690fc30b657fada09641b8bbde0e5ef76ecb2de
BLAKE2b-256 checksum
How to use checksums
750346a11f3bbe0680306f300500b75f511b5294a2e8c8f577277debdf648703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.9

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4.0

2 release files

1.3.4

2 release files

1.3.3

1 release file

1.3.2

1 release file

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.0.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