How to add payments to a Django or FastAPI app

Short answer

To add payments to a Django or FastAPI app, install Ruba’s Python SDK, create a checkout session with the product ID in a view or route, redirect the buyer to the returned URL, and confirm the sale with a verified webhook. Ruba is the Merchant of Record, so you need no Stripe account and no company. Ruba pays you to your own bank.

Install and connect

The SDK needs Python 3.11 or newer. Create an access token in the sandbox dashboard first, and keep it in an environment variable.

Terminal
pip install ruba-sdk
Figure 2From Ruba’s docs.

FastAPI: the async client

main.py
import os

from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from ruba import RubaAsync

app = FastAPI()


@app.get("/buy")
async def buy():
    async with RubaAsync(
        access_token=os.environ["RUBA_ACCESS_TOKEN"],
        base_url="https://sandbox-api.getruba.com",  # remove for production
    ) as client:
        checkout = await client.checkouts.create(
            products=[os.environ["RUBA_PRODUCT_ID"]],
        )
    return RedirectResponse(checkout.url)
Figure 3Adapted from Ruba’s Python SDK. Remove base_url when you go live.

Django: the sync client

views.py
import os

from django.shortcuts import redirect
from ruba import Ruba


def buy(request):
    with Ruba(
        access_token=os.environ["RUBA_ACCESS_TOKEN"],
        base_url="https://sandbox-api.getruba.com",  # remove for production
    ) as client:
        checkout = client.checkouts.create(
            products=[os.environ["RUBA_PRODUCT_ID"]],
        )
    return redirect(checkout.url)
Figure 4Adapted from Ruba’s Python SDK. The same call, in a normal view.

Create the session when the buyer clicks. The URL is short-lived. The SDK raises RubaError and its subclasses, so wrap the call and show a friendly message.

Confirm with a webhook

Ruba follows Standard Webhooks. Verify the exact raw request body with your endpoint secret using a Standard Webhooks library or the specification, then queue the work and return 2xx fast. A custom implementation must base64-encode the secret.

Do
Verify the raw body
Queue the work
Make the handler idempotent
Do not
Trust the browser to say “paid”
Parse the body before verifying
Do slow work before answering
Figure 5From Ruba’s delivery docs and general good practice.

Full rules: how to handle Ruba webhooks. Ready to sell? See the early-access deal.

Ruba has a Python SDK. A company is not required, and no monthly fee applies. Get approved in early access and your Python app keeps 4% + $0.50 per sale, locked while the account stays open and in good standing. The $100 promise: a fee Ruba never told you about comes back to you, and Ruba pays you $100. Terms apply. See the early-access deal.

Questions people ask

Does Ruba have a Python SDK?

Yes. Ruba has synchronous and asynchronous clients built on HTTPX, for Python 3.11 or newer. Install it with pip install ruba-sdk.

How do I use it in FastAPI?

Use the async client, RubaAsync, inside your async route, create a checkout with the product ID, and redirect the buyer to the returned url. In Django, the synchronous client fits normal views.

How do I point at the sandbox?

Pass base_url="https://sandbox-api.getruba.com" and use an access token created in the sandbox.

How do I verify webhooks in Python?

Ruba follows Standard Webhooks, so use a Standard Webhooks library or implement the specification. Always verify the exact raw request body, and note that a custom implementation must base64-encode the secret.

What errors does the SDK raise?

The package exports RubaError, RubaNetworkError, RubaServerError and RubaClientError for handling failures.

Sources

We check these when we update this guide. Rules can change, so check them yourself before you decide.

A note from FaizanHi, I’m Faizan, the founder of Ruba. I built it so people anywhere, from Pakistan, India and Bangladesh to the UK, the EU and the US, can sell software to the world and get paid at home.I wrote these guides to be as fair as I can. But I built Ruba, so I’m about as neutral as a parent at a school play. That’s why every fact has a source you can check.
Early access is live.

Sellers approved now keep 4% + $0.50 per sale locked for as long as they sell, plus +$100 if we ever charge a fee we never told you about. No company and no monthly fee. You are paid to a bank in your own name, in PKR, INR, BDT or 51 other currencies, whenever you ask, from $10. A payout costs $2 up to $200.

Applying is not approval. Terms apply.
All guides

Can’t find your country or currency? Email support@getruba.com.

This guide is general information, not legal, tax or financial advice. Other companies named here set their own rules, which can change. Check their websites before you decide.