paybridge-np
Official Python SDK for the PayBridgeNP payment gateway. Accept eSewa, Khalti, and Fonepay through a single API.
Installation
pip install paybridge-np
Quick start
from paybridge_np import PayBridgeNP
client = PayBridgeNP(api_key="sk_live_...") # from dashboard.paybridgenp.com
# Create a checkout session
session = client.checkout.create({
"amount": 250000, # NPR 2,500 in paisa
"currency": "NPR",
"returnUrl": "https://mystore.com/success",
"cancelUrl": "https://mystore.com/cart",
"metadata": {"orderId": "ORD-7842"},
"customer": {
"name": "Ram Shrestha",
"email": "ram@example.com",
"phone": "9841000000",
},
})
# Redirect customer to hosted checkout
# session["checkout_url"] => https://checkout.paybridgenp.com/checkout/cs_xxx
# Expire a previously-created session so its URL stops being payable
# (use when you mint a fresh session for the same purchase).
client.checkout.expire("cs_xxx")
# Retrieve or list checkout sessions (read-only). The read shape uses
# camelCase keys (customerName, expiresAt, ...).
session = client.checkout.retrieve("cs_xxx")
sessions = client.checkout.list(limit=20, status="success")
Payments
# List payments
result = client.payments.list(limit=20)
payments = result["data"]
# Get a single payment
payment = client.payments.retrieve("pay_xxx")
Payment links
Reusable hosted payment pages. Responses use camelCase keys.
# Create
link = client.payment_links.create({"title": "Donation", "amount": 50000})
# List, retrieve (with view/conversion stats), update, cancel, or delete
links = client.payment_links.list(active=True)
detail = client.payment_links.retrieve(link["id"])
client.payment_links.update(link["id"], {"active": False})
client.payment_links.cancel(link["id"]) # deactivate, keep for records
client.payment_links.delete(link["id"]) # only if never used
Direct-QR (Fonepay)
Premium feature -- mint a Fonepay QR server-side and embed it in your own UI,
skipping the hosted checkout page. Subscribe to events_url (SSE) for
qr.scanned / qr.paid / qr.expired.
qr = client.qr.fonepay({
"amount": 10000, # paisa
"customer": {"name": "Aarav Sharma", "email": "aarav@example.com"},
})
# qr["qr_image"] (PNG data URL), qr["qr_message"], qr["events_url"], qr["expires_at"]
# The QR display window is ~3 min. Refresh it for the SAME session -- same id,
# events_url, and webhook -- without spawning a new session. Lifetime unchanged.
fresh = client.qr.refresh(qr["id"])
Refunds
refund = client.refunds.create({
"paymentId": "pay_xxx",
"amount": 100000, # NPR 1,000 in paisa
"reason": "customer_request",
})
Webhooks
# Register an endpoint
endpoint = client.webhooks.create(
url="https://mystore.com/webhooks/paybridge",
events=["payment.succeeded", "payment.failed"],
)
# Verify a webhook signature (no client instance needed)
from paybridge_np.resources.webhooks import WebhooksResource
event = WebhooksResource.construct_event(
body=raw_body,
signature=request.headers["X-PayBridgeNP-Signature"],
secret="whsec_...",
)
Billing (Subscriptions)
# Create a plan
plan = client.plans.create({
"name": "Pro Monthly",
"amount": 99900,
"intervalUnit": "month",
})
# Create a customer
customer = client.customers.create({
"name": "Sita Gurung",
"email": "sita@example.com",
})
# Subscribe
subscription = client.subscriptions.create({
"customerId": customer["id"],
"planId": plan["id"],
})
# List invoices
invoices = client.invoices.list(customer_id=customer["id"])
Sandbox mode
Use a test-mode API key (sk_test_...) to test without real money. Mode is determined server-side by the key prefix (sk_test_ vs sk_live_) - there is nothing to configure in the SDK.
Retries and idempotency (3.3.0)
Only GET requests are automatically retried after connection errors or HTTP
500/502/503/504 responses, up to max_retries times (default: 2). Set
max_retries=0 to disable retries. POST, PATCH, and DELETE requests are sent once,
even when a caller supplies an idempotency key.
Every POST, PATCH, and DELETE sends an Idempotency-Key header. By default it is
a fresh UUID for each method call. All resource methods using these verbs accept
an optional keyword-only idempotency_key:
refund = client.refunds.create(
{"paymentId": "pay_123", "amount": 10000, "reason": "customer_request"},
idempotency_key="refund-order-123",
)
Persist a key per business operation and reuse it with the same request when retrying manually. A new method call without a supplied key generates a new UUID; it does not reuse the previous call's key. Replay protection is endpoint-specific: sending a key does not guarantee deduplication on every route. If a write fails with an unknown outcome, check its status before retrying.
Changed in 3.3.0
- Writes are no longer retried automatically, and every write sends an
Idempotency-Key(see above). - List filters are percent-encoded by the transport. A
searchvalue containing&,#or a space used to be pasted into the URL raw, which split it into extra parameters or truncated it at the#. - A 404 raises
NotFoundErroragain, soexcept NotFoundErrorbranches written against 0.x start running (see Error handling).
Error handling
from paybridge_np import PayBridgeError, AuthenticationError
try:
session = client.checkout.create({...})
except AuthenticationError:
print("Invalid API key")
except PayBridgeError as e:
print(e, e.status_code)
Errors carry a type (which names the class) and an optional code (a machine
string from the API, often None). The type wins: a 404 typed
permission_error raises PermissionError. An ordinary 404 — typed
invalid_request_error, or untyped — raises NotFoundError, which subclasses
InvalidRequestError, so either except catches it.
Changed in 3.3.0: 404s used to be parsed as plain InvalidRequestError, so an
except NotFoundError branch written against 0.x caught nothing. Such branches
run again. If you have both, order them NotFoundError first.
Context manager
with PayBridgeNP(api_key="sk_live_...") as client:
session = client.checkout.create({...})
# HTTP client is closed automatically
Documentation
License
MIT
Metadata
Release files for paybridge-np 3.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paybridge_np-3.3.0.tar.gz | 23.7 kB | Without provenance | Details for paybridge_np-3.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paybridge_np-3.3.0-py3-none-any.whl | Python 3 | none | any | Details for paybridge_np-3.3.0-py3-none-any.whl |
Total release size: 53.7 kB
Release files / paybridge_np-3.3.0.tar.gz
| Download URL | paybridge_np-3.3.0.tar.gz |
|---|---|
| Size | 23.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a9d93e5674de10f166e2d471e0688846e14fbac7a2e98430984a00a97e338b8
|
|
BLAKE2b-256 checksum How to use checksums |
336004bdba15f105d61d210a98a284dd7867646e79363be3d11285901ad3d70d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / paybridge_np-3.3.0-py3-none-any.whl
| Download URL | paybridge_np-3.3.0-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c1377d996184b1fe1b98b401dc5bd47b2b925ad16586947eed01a082e7f7c4d
|
|
BLAKE2b-256 checksum How to use checksums |
7711406f245b8c87eb12be0c0a41efa8714083c4b1a06f4f39be88674334af64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for paybridge-np 3.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.