Skip to main content

integrate django payments with zarrinpal

Project description

django-zarinpal

Integrate django payments with zarinpal

Features

  • sending signal on verifying transaction to let other apps know about it

Quickstart

Install django-zarinpal::

pip install django-zarinpal

Add it to your INSTALLED_APPS:

.. code-block:: python

INSTALLED_APPS = (
    ...
    'zarinpal',
    ...
)

Add django-zarinpal's URL patterns:

.. code-block:: python

import zarrinpal


urlpatterns = [
    ...
    path('zarinpal/', include(zarinpal_urls)),
    ...
]

How to Use

set these variables in your settings file:

ZARINPAL_CALLBACK_URL: bool # the url user redirects to after transaction

ZARINPAL_SIMULATION: bool # is transactions for test?

ZARINPAL_MERCHANT_ID: str # merchant id from zarinpal (you may leave it blank if you set the simulation to True)

you can use function start_transaction with a dictionary containing your transaction data like this:

from django.shortcuts import redirect
from django_zarinpal.services import start_transaction


def start_payment(request):
    result = start_transaction(
        {
            "user": request.user,
            "amount": 10000,
            "description": "transaction description",
            "mobile": "09123456789",
            "email": "string",
        }
    )
    return redirect(result) # result is the url for starting transaction

If you specify a callback_url in transaction data after completing transaction zarinpal will redirect user to the page you specified with two get arguments:

1.order_number: str

2.success: boolean

Custom verification

If you want to handle verifying transaction your self you can define your view and address it in settings with ZARINPAL_VERIFY_TRANSACTION_VIEW. you can use function verify_transaction to verify a transaction.

If you don't specify this view, package will use default view for verifying transactions.

Tests

Running tests: ::

python manage.py runtests.py

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-zarinpal-1.0.1.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

django_zarinpal-1.0.1-py3-none-any.whl (8.4 kB view hashes)

Uploaded Python 3

Supported by

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