Skip to main content

Official Python SDK for the PayBridgeNP payment gateway - accept eSewa, Khalti, and Fonepay through a single API

Project description

paybridge-np

Official Python SDK for the PayBridgeNP payment gateway. Accept eSewa, Khalti, and ConnectIPS through a single API.

Installation

pip install paybridge-np

Quick start

from paybridge_np import PayBridge

client = PayBridge(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")

Payments

# List payments
result = client.payments.list(limit=20)
payments = result["data"]

# Get a single payment
payment = client.payments.retrieve("pay_xxx")

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-PayBridge-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 sandbox API key (sk_sandbox_...) to test without real money. The SDK automatically routes to sandbox endpoints.

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)

Context manager

with PayBridge(api_key="sk_live_...") as client:
    session = client.checkout.create({...})
# HTTP client is closed automatically

Documentation

License

MIT

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

paybridge_np-0.6.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paybridge_np-0.6.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file paybridge_np-0.6.0.tar.gz.

File metadata

  • Download URL: paybridge_np-0.6.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for paybridge_np-0.6.0.tar.gz
Algorithm Hash digest
SHA256 c2ad40b11124d0e44a6d68f4eea06b033e7757a3db0b8d2afcc302414c880735
MD5 6c77587c4ac94e3569eedd170b08c40a
BLAKE2b-256 f5cbc54e90301094f06b514a6681fd0b529eca79797a1b8e036af217c1bbdd12

See more details on using hashes here.

File details

Details for the file paybridge_np-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: paybridge_np-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for paybridge_np-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 224e5a8b69c0fd7a336ea40cdfc1d998680443922991f6ad79ddea1fc5f1d4d0
MD5 d20cfdc8981d48a093e23bf54d0421fd
BLAKE2b-256 1b6b7bcef16265e7928efe608c24ec9fa5941402f874f6d36d00321c30b450c2

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