Интеграция с Banxa
Banxa — публично торгуемый on/off-ramp провайдер (TSX: BNXA) с акцентом на комплаенс и глобальное покрытие. Используется крупными биржами и кошельками как надёжная регулируемая инфраструктура. Поддерживает 100+ платёжных методов в 100+ странах.
Аутентификация HMAC
Banxa использует HMAC-SHA256 для аутентификации API запросов:
import hmac
import hashlib
import time
import uuid
import httpx
class BanxaClient:
def __init__(self, api_key: str, secret: str, sandbox: bool = False):
self.api_key = api_key
self.secret = secret
self.base_url = (
"https://banxa-sandbox.com/api" if sandbox
else "https://banxa.com/api"
)
def _auth_header(self, method: str, path: str, body: str = "") -> str:
nonce = str(int(time.time() * 1000))
payload = f"{method}\n{path}\n{nonce}\n{body}"
signature = hmac.new(
self.secret.encode(),
payload.encode(),
hashlib.sha256
).hexdigest()
return f"Bearer {self.api_key}:{nonce}:{signature}"
async def get_payment_methods(self, source_currency: str = "USD") -> list:
path = f"/payment-methods?source_currency={source_currency}"
async with httpx.AsyncClient() as client:
resp = await client.get(
f"{self.base_url}{path}",
headers={"Authorization": self._auth_header("GET", path)}
)
return resp.json()["data"]["payment_methods"]
async def create_order(self, order_data: dict) -> dict:
path = "/orders"
body = json.dumps(order_data)
async with httpx.AsyncClient() as client:
resp = await client.post(
f"{self.base_url}{path}",
headers={
"Authorization": self._auth_header("POST", path, body),
"Content-Type": "application/json"
},
content=body
)
return resp.json()["data"]["order"]
Создание ордера покупки
async def create_buy_order(
client: BanxaClient,
fiat_amount: float,
fiat_currency: str,
crypto_currency: str,
wallet_address: str,
payment_method_id: int,
return_url: str
) -> dict:
order = await client.create_order({
"account_reference": str(uuid.uuid4()),
"payment_method_id": payment_method_id,
"source": fiat_currency,
"source_amount": fiat_amount,
"target": crypto_currency,
"wallet_address": wallet_address,
"return_url_on_success": return_url,
"return_url_on_failure": return_url + "?status=failed",
"return_url_on_cancelled": return_url + "?status=cancelled",
})
return order # содержит checkout_url для редиректа пользователя
Webhook обработка
@app.post("/webhooks/banxa")
async def banxa_webhook(request: Request):
body = await request.body()
signature = request.headers.get("X-Banxa-Hmac-Sha256")
# Верификация
expected = hmac.new(
BANXA_WEBHOOK_SECRET.encode(), body, hashlib.sha256
).hexdigest()
if not hmac.compare_digest(expected, signature or ""):
raise HTTPException(403)
data = json.loads(body)
order = data["order"]
status_map = {
"complete": "COMPLETED",
"cancelled": "CANCELLED",
"declined": "FAILED",
"expired": "EXPIRED",
}
await update_order_status(
order_id=order["id"],
status=status_map.get(order["status"], "UNKNOWN"),
tx_hash=order.get("transaction", {}).get("hash")
)
Banxa — надёжный выбор для биржей, которым нужен регулируемый партнёр с хорошей репутацией у банков-партнёров. Комиссии варьируются от 1.5% (SEPA) до 3.5% (карты). Хорошее покрытие Australia, Canada, US, Europe.







