Metadata-Version: 2.5
Name: razcrypto
Version: 2.0.0
Summary: Official Python SDK for RazCrypto Gateway: payments, payment links, Standard Webhooks and checkout signature verification.
Project-URL: Homepage, https://razcryptogateway.com
Project-URL: Documentation, https://razcryptogateway.com/docs/sdks
Project-URL: Repository, https://github.com/WorldxGrowth/razcrypto-python-sdk
Author: worldXgrowth
License-Expression: MIT
License-File: LICENSE
Keywords: crypto,gateway,payments,razcrypto,standard-webhooks,webhooks
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# RazCrypto Gateway — Python SDK

Official Python client for [RazCrypto Gateway](https://razcryptogateway.com), the non-custodial crypto payment gateway.

- **PyPI:** `razcrypto` (import name `razcrypto`)
- **Requires:** Python ≥ 3.9
- **Dependencies:** standard library only
- **Types:** typed (`py.typed`)
- **License:** MIT

```bash
pip install razcrypto
```


## Upgrading

This major version is the SDK for the new RazCrypto Gateway: initialise with only your secret key (Dashboard → API apps) and use the new `/v1` API. Pin the previous major version only if you still use the old gateway.

## Create a payment

```python
import os
from razcrypto import RazCrypto

rc = RazCrypto(os.environ["RAZCRYPTO_SECRET_KEY"])  # sk_test_… or sk_live_…

payment = rc.payments.create(
    amount="49.00",
    currency="USD",
    reference_id=order.id,
    redirect_url="https://shop.example/thanks",
    idempotency_key=order.id,  # safe to retry
)
return redirect(payment["checkout_url"])
```

## API

| Area | Methods |
|---|---|
| Payments | `rc.payments.create(**params, idempotency_key=…)`, `retrieve(id)`, `list(**params)`, `auto_paging_iter(**params)`, `methods(id)`, `quote(id, chain, coin)`, `cancel(id)`, `simulate(id, outcome)` (test mode) |
| Payment links | `rc.payment_links.create(...)`, `retrieve`, `list`, `update`, `deactivate` |
| Others | `rc.chains()`, `rc.rates(["USDT", "BNB"], "USD")`, `rc.merchant()`, `rc.event(id)` |

**Errors:**
- API errors raise `razcrypto.ApiError` with `status`, `code`, `param` and `request_id`.
- Network problems raise `razcrypto.ConnectionError_`.
- The client retries network errors, `429` and `5xx`.

Options: `RazCrypto(key, timeout=30.0, max_retries=2)`. The client talks to `https://razcryptogateway.com` by default;
`api_base` (or env `RAZCRYPTO_API_BASE`) is only for staging or a self-hosted gateway.

## Verify webhooks (Standard Webhooks)

```python
from flask import Flask, request
from razcrypto import webhooks, SignatureVerificationError

@app.post("/webhooks/razcrypto")
def razcrypto_webhook():
    try:
        event = webhooks.verify(request.get_data(), request.headers, os.environ["RAZCRYPTO_WEBHOOK_SECRET"])  # whsec_…
    except SignatureVerificationError:
        return "", 400
    if event["type"] == "payment.paid":
        mark_order_paid(event["data"]["reference_id"])
    return "", 200
```

Django: `webhooks.verify(request.body, request.headers, secret)`.

## Verify the checkout signature

```python
from razcrypto import is_valid_checkout_signature

# Redirect query: ?payment_id=…&reference_id=…&status=…&signature=…
if not is_valid_checkout_signature(request.args, os.environ["RAZCRYPTO_WEBHOOK_SECRET"]):
    ...  # do not trust it — wait for the webhook
```

## Test mode
- Use `sk_test_…` keys.
- `rc.payments.simulate(payment_id, "paid")` runs the full flow, webhooks included.

Tests: `python -m unittest discover -s tests`. They also run the shared vectors in `../test-vectors.json`.
