{ "info": { "author": "CryptAPI", "author_email": "cryptapi@protonmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3" ], "description": "\n\n# CryptAPI's Django Library\nDjango's implementation of CryptAPI's payment gateway\n\n## Requirements:\n\n```\nPython >= 3.0\nDjango >= 2.0\nRequests >= 2.20\n```\n\n\n\n## Install\n\n\n```shell script\npip install django-cryptapi\n```\n\n\n[on pypi](https://pypi.python.org/pypi/django-cryptapi)\nor\n[on GitHub](https://github.com/cryptapi/django-cryptapi)\n\nAdd to INSTALLED_APPS:\n\n```python\nINSTALLED_APPS = (\n 'cryptapi',\n ...\n)\n```\n\n\nRun migrations:\n\n```shell script\npython3 manage.py migrate cryptapi\n```\n\nCollect static files:\n\n```shell script\npython3 manage.py collectstatic\n```\n\nAdd CryptAPI's URLs to your project's urls.py file:\n\n```python\nurlpatterns = [\n path('cryptapi/', include('cryptapi.urls')),\n ...\n]\n```\n\n## Configuration\n\nAfter the installation you need to set up Providers for each coin you wish to accept.\n\nYou 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.\n\n## Usage\n\n### Creating an Invoice\n\nIn your order creation view, assuming ``user_order`` is your order object:\n\n* ##### If you want the address generated:\n\n```python\nfrom cryptapi import Invoice\n...\ndef order_creation_view(request):\n ...\n invoice = Invoice(\n request=request,\n order_id=user_order.id,\n coin='btc',\n value=user_order.value\n )\n\n payment_address = invoice.address()\n\n if payment_address is not None:\n # Show the payment address to the user\n ...\n else:\n # Handle request error, check RequestLogs on Admin\n```\n\n* ##### If you want the `cryptapi.models.Request` object:\n\n```python\nfrom cryptapi import Invoice\n...\ndef order_creation_view(request):\n ...\n invoice = Invoice(\n request=request,\n order_id=user_order.id,\n coin='btc',\n value=user_order.value\n )\n\n payment_request = invoice.request()\n\n if payment_request is not None:\n # Show the payment address to the user\n ...\n else:\n # Handle request error, check RequestLogs on Admin\n```\n\n#### Where:\n\n``request`` is Django's view HttpRequest object \n``order_id`` is just your order id \n``coin`` is the ticker of the coin you wish to use, any of our supported coins (https://cryptapi.io/pricing/). You need to have a ``Provider`` set up for that coin. \n``value`` is an integer of the value of your order, either in satoshi, litoshi, wei, piconero or IOTA\n\n\n### Getting notified when the user pays\n\n```python\nfrom django.dispatch import receiver\nfrom cryptapi.signals import payment_complete\n\n@receiver(payment_complete)\ndef payment_received(order_id, payment, value):\n # Implement your logic to mark the order as paid and release the goods to the user\n ...\n```\n\n\nWhere: \n\n``order_id`` is the id of the order that you provided earlier, used to fetch your order \n``payment`` is an ``cryptapi.models.Payment`` object with the payment details, such as TXID, number of confirmations, etc. \n``value`` is the value the user paid, either in satoshi, litoshi, wei or IOTA\n\n\n \n\n\n>#### Important:\n>Don't forget to import your signals file. \n>\n>On your App's `apps.py` file:\n>\n>```python\n>class MyAppConfig(AppConfig):\n> name = 'MyApp'\n> \n> def ready(self):\n> super(MyAppConfig, self).ready()\n>\n> # noinspection PyUnresolvedReferences\n> import MyApp.signals\n>```\n>[django docs](https://docs.djangoproject.com/en/3.0/topics/signals/#django.dispatch.receiver)\n\n\n \n\n\n### Helpers\n\nThis library has a couple of helpers to help you get started\n\n``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``\n\n``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)\n\n\n### Template Tags\nThere's also some template tags which you can import to help you with conversions and the protocols.\nYou just need to load ``cryptapi_helper`` on your template and use the following tags / filters: \n\n* #### QR code (with `cryptapi.models.Request` object)\nIf you want the library to generate and display a clickable QR code for you, just use our `generate_qrcode_for_request`, like this:\n\n```djangotemplate\n{% generate_qrcode_for_request payment_request %}\n```\n\nYou just need to feed it the `payment_request` object created with `invoice.request()` \n\nThe QR code that can also be clicked on mobile devices to launch the user's wallet.\n\n* #### QR code (with address, coin and value)\nIf you want the library to generate and display a clickable QR code for you, just use our `generate_qrcode`, like this:\n\n```djangotemplate\n{% generate_qrcode btc 1PE5U4temq1rFzseHHGE2L8smwHCyRbkx3 0.001 %}\n```\n\nIt takes 3 arguments: the coin, the payment address and the value in the main denomination of the coin, and it will output a neat QR code for your page. \n\nThe QR code that can also be clicked on mobile devices to launch the user's wallet.\n\n##### Example:\n```djangotemplate\n{% load cryptapi_helper %}\n
\n