Skip to main content

BlockBee Checkout backend for django-payments.

Project description

django-payments-blockbee

PyPI - Version PyPI - Python Version


django-payments-blockbee adds support for the BlockBee hosted checkout to Django Payments.

Table of Contents

Installation

pip install django-payments-blockbee

Configuration

Follow the Django Payments setup (define a concrete Payment model and set PAYMENT_MODEL). Then add this variant:

PAYMENT_VARIANTS = {
    "blockbee": (
        "payments_blockbee.BlockBeeProvider",
        {
            "apikey": "test_example-api-key",
            "redirect_url": "https://example.com/payment/success/",
            "notify_url": "https://example.com/payment/webhook/",
        },
    )
}

Available configuration options

  • apikey: Your BlockBee API key
  • redirect_url: URL to send the customer back to after paying (your success page)
  • notify_url: Public webhook endpoint that BlockBee will call when a payment is completed

Notes:

  • Currency is taken from the Payment instance (payment.currency, e.g. "EUR").
  • We recommend using a public domain/tunnel for local development and setting PAYMENT_HOST accordingly.

Webhook

Create a webhook view and delegate to the provider. The provider processes GET-only webhooks and confirms the payment when is_paid == "1" and status == "done".

from django.http import HttpResponseBadRequest
from django.shortcuts import get_object_or_404
from django.views.decorators.csrf import csrf_exempt
from payments import get_payment_model
from payments.core import provider_factory


@csrf_exempt
def blockbee_webhook(request):
    provider = provider_factory("blockbee")
    # Resolve our transaction id (stored as BlockBee payment_id on creation)
    transaction_id = provider.get_transaction_id_from_request(request=request)
    if not transaction_id:
        return HttpResponseBadRequest("Invalid response")
    Payment = get_payment_model()
    payment = get_object_or_404(Payment, variant="blockbee", transaction_id=transaction_id)
    return provider.process_data(payment, request)

Usage

Create a Payment and call get_form() or handle RedirectNeeded per Django Payments docs:

from django.shortcuts import redirect, render
from payments import RedirectNeeded, get_payment_model


def checkout(request):
    Payment = get_payment_model()
    payment = Payment.objects.create(
        variant="blockbee",
        description="Order #123",
        total="10.00",
        currency="EUR",
    )
    try:
        payment_url = payment.get_form(data=request.POST or None)
    except RedirectNeeded as redirect_to:
        return redirect(str(redirect_to))

    return render(request, "shop/checkout.html", {"payment_url": payment_url})

On successful webhook processing, the provider will set the Payment status to confirmed. Useful webhook payload fields (like paid_amount_fiat, paid_coin, txid) are saved into payment.attrs.

Sandbox

BlockBee does not provide a sandbox environment. Testing is done against live endpoints. Recommended practices:

  • Use small order amounts when developing (e.g., 1–2 USD) and low-fee networks/coins
  • Enable a public tunnel (ngrok/cloudflared) so your notify_url is reachable
  • Treat webhook handling as idempotent (this provider already does)
  • Never expose secrets in client code; keep the API key in server-side settings

License

django-payments-blockbee is distributed under the terms of the MIT license.

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_payments_blockbee-1.0.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_payments_blockbee-1.0.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file django_payments_blockbee-1.0.3.tar.gz.

File metadata

File hashes

Hashes for django_payments_blockbee-1.0.3.tar.gz
Algorithm Hash digest
SHA256 66963fbe279a2cbd182e0d159375321c8038b7277ffb9f528037ef86dd496665
MD5 b804c04a02fd1027c809fa59c3e56c76
BLAKE2b-256 9220bcc2d5ce2242b5e3086a0d0740c306be03b3295dd50dd96a555c327e59d4

See more details on using hashes here.

File details

Details for the file django_payments_blockbee-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_payments_blockbee-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e0450a897b291fa68049c844a9c65be1ed6d5567033b59990079f956935421aa
MD5 3dcd9ca66dd26293deee56cd5d226219
BLAKE2b-256 dbd3c10f0a95c0683bcc72cea318f067c99d9730dceb86ed0e4cdc8579f29941

See more details on using hashes here.

Supported by

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