Skip to main content

CryptAPI's Django Library

Django's implementation of CryptAPI's payment gateway

Requirements:

Python >= 3.0
Django >= 2.0
Requests >= 2.20

Install

pip install django-cryptapi

on pypi or on GitHub

Add to INSTALLED_APPS:

INSTALLED_APPS = (
     'cryptapi',
     ...
     )

Run migrations:

python3 manage.py migrate cryptapi

Add CryptAPI's URLs to your project's urls.py file:

urlpatterns = [
    path('cryptapi/', include('cryptapi.urls')),
    ...
]

Configuration

After the installation you need to set up Providers for each coin you wish to accept.

You need to go into your Django Admin and create a new CryptAPI Provider for each coin with your cold wallet address where the funds will be forwarded to.

Usage

Creating an Invoice

In your order creation view, assuming user_order is your order object:

from cryptapi import Invoice
...
def order_creation_view(request):
    ...
    invoice = Invoice(
        request=request,
        order_id=user_order.id,
        coin='btc',
        value=user_order.value
    )

    payment_address = invoice.address()

    if payment_address is not None:
        # Show the payment address to the user
        ...
    else:
        # Handle request error, check RequestLogs on Admin

Where:

request is Django's view HttpRequest object
order_id is just your order id
coin is the coin you wish to use, can be one of: ['btc', 'eth', 'bch', 'ltc', 'iota'] and you need to have a Provider set up for that coin.
value is an integer of the value of your order, either in satoshi, litoshi, wei or IOTA

Getting notified when the user pays

from django.dispatch import receiver
from cryptapi.signals import payment_complete

@receiver(payment_complete)
def payment_received(order_id, payment, value):
    # Implement your logic to mark the order as paid and release the goods to the user
    ...

Where:

order_id is the id of the order that you provided earlier, used to fetch your order
payment is an cryptapi.models.Payment object with the payment details, such as TXID, number of confirmations, etc.
value is the value the user paid, either in satoshi, litoshi, wei or IOTA

Helpers

This library has a couple of helpers to help you get started

cryptapi.valid_providers() is a method that returns a list of tuples of the active providers that you can just feed into the choices of a form.ChoiceField

cryptapi.get_order_invoices(order_id) returns a list of cryptapi.models.Request objects of your order (you can have multiple objects for the same order if the user mistakenly initiated the payment with another coin)

There's also some template tags which you can import to help you with conversions and the protocols. You just need to load cryptapi_helper on your template and use the following tags / filters:

{% convert_value coin value %} where the coin is one of ['btc', 'eth', 'bch', 'ltc', 'iota'] and the value is the value in satoshi, litoshi, wei or IOTA, will convert to the main coin denomination.

{{ coin|coin_name }} will output the properly formatted cryptocurrency name

Help

Need help?
Contact us @ https://cryptapi.io/contact/

Metadata

Release files for django-cryptapi 0.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-cryptapi 0.1
File Size Uploaded Provenance Actions
django-cryptapi-0.1.tar.gz 8.5 kB Without provenance Details for django-cryptapi-0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-cryptapi 0.1
File Interpreter ABI Platform Actions
django_cryptapi-0.1-py3-none-any.whl Python 3 none any Details for django_cryptapi-0.1-py3-none-any.whl

Total release size: 21.1 kB

Release files / django-cryptapi-0.1.tar.gz

Download URL django-cryptapi-0.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b64a467c53c9737390ac2b686af7a731e7d9e59f307bcacda6f11abd22d65b07
BLAKE2b-256 checksum
How to use checksums
e40068a35964193fba3ffefd7ec979a4b3be73581395dbfd42ecd264e2d863a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.20.0 CPython/3.6.3

Release files / django_cryptapi-0.1-py3-none-any.whl

Download URL django_cryptapi-0.1-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c3216a237223dd30dfbe442e1682ce511c82cb3fa8e6ba545e29a19ebbd89b2
BLAKE2b-256 checksum
How to use checksums
a94aa6646b00549561e977747885fbb95766daf5ac4af76db1f24cf75afba61c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.20.0 CPython/3.6.3

Security for django-cryptapi 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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