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.4.tar.gz (5.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.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_payments_blockbee-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a1cc5c08c8e416513126e48b31e81ecd80b643e0b62675ee4eb5c89035d7276f
MD5 35444bd3d0b4018b7a58333dfe8f3e98
BLAKE2b-256 ac098b3d7fb989dfd886c833f6beb19ac198ce293e97eb157852a2a5ecbf55b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_payments_blockbee-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a4dafd35e5e5e4fba15efb3a44034fe0f5798981c25896844de01fbcca10c102
MD5 2632c9753847e44f02b7c2868585511d
BLAKE2b-256 0c1f313741d614115f99581401bd6475521d5a49d56ae56522f90b53342ca8bc

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