Package: django-blockbee
BlockBee's Django LibraryDjango's implementation of BlockBee's payment gatewayRequirements:Python >= 3.0
Django >= 2.0
Requests >= 2.20Installpipinstalldjango-blockbeeon pypioron GitHubAdd to INSTALLED_APPS:INSTALLED_APPS=('blockbee',...)Run migrations:python3manage.pymigrateblockbeeCollect static files:python3manage.pycollectstaticAdd BlockBee's URLs to your project's urls.py file:urlpatterns=[path('blockbee/',include('blockbee.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 BlockBeeProviderfor 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:fromblockbeeimportInvoice...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 theblockbee.models.Requestobject:fromblockbeeimportInvoice...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://blockbee.io/cryptocurrencies/). You need to have aProviderset up for that coin.valueis an integer of the value of your orderapikeyis the API Key that you got from your BlockBee DashboardGetting notified when the user paysfromdjango.dispatchimportreceiverfromblockbee.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 anblockbee.models.Paymentobject with the payment details, such as TXID, number of confirmations, etc.valueis the value the user paidImportant: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 blockbee_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.blockbee.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.ChoiceFieldblockbee.get_order_invoices(order_id)returns a list ofblockbee.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)blockbee.callback_url(_r, params)build your callback URL to provide toget_request. Should be used inside a view since_r = requestBlockBee HelperThis is the helper responsible for the connections ot the API itself. All these functions are in theblockbee.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, params)requests a payment address to BlockBee. Params include all the parameters that can be foundhere. The parameterapikeyis mandatory.How 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://blockbee.io/contacts/Changelog1.0.0Initial Release1.0.1Minor fixesUI Improvements1.0.2Minor fixes1.0.3Minor fixesSignals now use the value_coinRemoved deprecated fields from the payment model1.0.4Minor fixes