Skip to main content

Django integration with ATOL online

Project description

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

https://img.shields.io/badge/python-3.5,%203.6-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)

  • 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 = 'г. Москва, ул. Оранжевая, д.22 к.11'
    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.3.0 (2018-11-28)

  • 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

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

django-atol-1.3.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_atol-1.3.0-py2.py3-none-any.whl (15.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-atol-1.3.0.tar.gz.

File metadata

  • Download URL: django-atol-1.3.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for django-atol-1.3.0.tar.gz
Algorithm Hash digest
SHA256 cb09dd466e9f78dee0494aa7e428da3ee7be6b20050d0d0690351ad687248bee
MD5 4377ce55d71dbf07ed751b2e33c0333f
BLAKE2b-256 6bd4de65791875ac02f5be94ac854504c9a210f5e484491dfe5897a81dff55e9

See more details on using hashes here.

File details

Details for the file django_atol-1.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_atol-1.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for django_atol-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1de2bc33971eb73949e5b76c3b6458e4bb57146506c92737ba5b7da8e14e54e4
MD5 e41f959bad5a64f25e67f3fec59bf492
BLAKE2b-256 0e74472ac5fe8f6eb34f99716b11d4babea9a1f8e2e5f9eca401ab4f1888fbb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page