Package: django-cryptapi
CryptAPI's Django LibraryDjango's implementation of CryptAPI's payment gatewayRequirements:Python >= 3.0
Django >= 2.0
Requests >= 2.20Installpipinstalldjango-cryptapion pypioron GitHubAdd to INSTALLED_APPS:INSTALLED_APPS=('cryptapi',...)Run migrations:python3manage.pymigratecryptapiCollect static files:python3manage.pycollectstaticAdd CryptAPI's URLs to your project's urls.py file:urlpatterns=[path('cryptapi/',include('cryptapi.urls')),...]ConfigurationAfter 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 CryptAPIProviderfor each coin with your cold wallet address where the funds will be forwarded to.UsageCreating an InvoiceIn your order creation view, assuminguser_orderis your order object:If you want the address generated:fromcryptapiimportInvoice...deforder_creation_view(request):...invoice=Invoice(request=request,order_id=user_order.id,coin='btc',value=user_order.value)payment_address=invoice.address()ifpayment_addressisnotNone:# Show the payment address to the user...else:# Handle request error, check RequestLogs on AdminIf you want thecryptapi.models.Requestobject:fromcryptapiimportInvoice...deforder_creation_view(request):...invoice=Invoice(request=request,# This if your view request. It's meant to create the callback URLorder_id=user_order.id,coin='btc',value=user_order.value)payment_request=invoice.request()ifpayment_requestisnotNone:# Show the payment address to the user...else:# Handle request error, check RequestLogs on AdminWhere:requestis Django's view HttpRequest objectorder_idis just your order idcoinis the ticker of the coin you wish to use, any of our supported coins (https://cryptapi.io/cryptocurrencies/). You need to have aProviderset up for that coin.valueis an integer of the value of your order, either in satoshi, litoshi, wei, piconero or IOTAGetting notified when the user paysfromdjango.dispatchimportreceiverfromcryptapi.signalsimportpayment_complete@receiver(payment_complete)defpayment_received(order_id,payment,value):# Implement your logic to mark the order as paid and release the goods to the user...Where:order_idis the id of the order that you provided earlier, used to fetch your orderpaymentis ancryptapi.models.Paymentobject with the payment details, such as TXID, number of confirmations, etc.valueis the value the user paid, either in satoshi, litoshi, wei or IOTAImportant:Don't forget to import your signals file.On your App'sapps.pyfile:classMyAppConfig(AppConfig):name='MyApp'defready(self):super(MyAppConfig,self).ready()# noinspection PyUnresolvedReferencesimportMyApp.signalsdjango docsUsing our provided interfaceCreate a view inviews.pydefpayment(_r,request_id):try:req=Request.objects.get(id=request_id)coin=req.provider.coinqrcode=get_qrcode(coin,req.address_in)fiat=get_conversion(coin,'eur',req.value_requested)print(fiat)ctx={'req':req,'qrcode':qrcode,'fiat':fiat['value_coin']}returnrender(_r,'payment.html',context=ctx)exceptRequest.DoesNotExist:passreturnredirect('store:request')In your template HTML{% extends 'base.html' %}
{% load cryptapi_helper %}
{% block content %}
    {% generate_payment_template %}
{% endblock %}HelpersThis library has a couple of helpers to help you get started. They are present in the fileutils.py.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 aform.ChoiceFieldcryptapi.get_order_invoices(order_id)returns a list ofcryptapi.models.Requestobjects of your order (you can have multiple objects for the same order if the user mistakenly initiated the payment with another coin or if he mistakenly didn't send the full payment)cryptapi.callback_url(_r, params)build your callback URL to provide toget_request. Should be used inside a view since_r = requestCryptAPI HelperThis is the helper responsible for the connections ot the API itself. All these functions are in thecryptapi.pyfile.get_info(coin)returns the information of all cryptocurrencies or just ifcoin=''or a specific cryptocurrency ifcoin='ltc'for example.docsget_supported_coins()returns all the support cryptocurrencies. You can consult them in thislist.get_logs(coin, callback_url)returns all the callback logs related to a request.callback_urlshould be the callback provided to our API.docsget_qrcode(coin, address, value, size)returns a PNG of a QR Code with the address for payment.docsget_conversion(origin, to, value)returns the converted value in the parametervalue_cointo the currency you wish, FIAT or Cryptocurrency.get_estimate(coin)returns the estimation of the blockchain fees for the cryptocurrency specified in the parametercoin. E.g:get_estimate('trc20_usdt')docsget_address(coin, address_out, callback_url, pending, api_key)requests a payment address to CryptAPI. If you don't wish to useBlockBee, you can leaveapi_keyempty.docsHow to use the QR code (with address, coin and value)To generate a QR Code you must useget_qrcodein your view and feed the parameters to your template. To generate a QR Code image you must place content of the API response afterdata:image/png;base64,{{qr_code}}so the browser generates the QR Code.<img src="data:image/png;base64,{{ qrcode.qr_code }}" alt="Payment QR Code"/>You can also make the QR Code clickable.<a href='{{ qrcode.payment_uri }}'>
    <img src="data:image/png;base64,{{ qrcode.qr_code }}" alt="Payment QR Code"/>
</a>You can also add a value to the QR Code setting thevalueparameter to the value of your order (e.g0.2 LTC). This may not function correctly in some wallets.Use at your own risk.What is the Store application?We made thestoreapplication to provide you with code examples on how to implement our service. It also has the code for our suggested UI (both CSS and HTML).HelpNeed help?Contact us @https://cryptapi.io/contacts/Changelog0.1.2Version bump0.1.3Pending transactions (through thepayment_pendingsignal)Monero0.1.5Fixed bug with MySQL database varchar length limitationsAdded build payment URI tag, to help you generate payment URIs to feed into any QR Code generator0.2.0Added ERC-20 token supportAdded payment QR codeImproved documentationFixed bugs0.2.7Added coin info helper0.3.1New API URLNew general info API0.4.0Support for BlockBeeFetch all supported cryptocurrencies and cache themUpdated API HelperAdded conversion endpointAdded support for BlockBee API KeyAdded UI for paymentsAdded store application to provide examples on how to implementGeneral improvementsFixed bugs0.4.1Minor bugfixes0.4.2Minor fixesSignals now use the value_coinRemoved deprecated fields from the payment model0.4.3Minor fixes