Skip to main content

SabPaisa Python SDK

Official Python SDK for SabPaisa Payment Gateway 2.0

Supports Python 2.7+ to Python 3.12+

Installation

pip install sabpaisa-python

Quick Start

from sabpaisa_python import SabPaisa

# Initialize SDK
sabpaisa = SabPaisa(
    merchant_id="YOUR_MERCHANT_ID",
    api_key="YOUR_API_KEY",
    secret_key="YOUR_SECRET_KEY",
    is_production=False  # True for production
)

# Create Payment
response = sabpaisa.create_payment(
    order_id="ORD123",
    amount=500.00,
    customer_name="John Doe",
    customer_email="john@example.com",
    customer_phone="9876543210",
    return_url="https://yoursite.com/callback"
)

# Redirect to checkout
if response["success"]:
    checkout_url = sabpaisa.get_checkout_url(response)
    # redirect user to checkout_url

Handle Callback

# Flask
@app.route('/callback')
def callback():
    params = request.args.to_dict()
    result = sabpaisa.verify_callback(params)

    if result["success"] and result["signature_valid"]:
        print("Payment successful!")
        print("Transaction ID:", result["transaction_id"])
        print("Amount:", result["paid_amount_in_rupees"])
    return "OK"

# Django
def callback(request):
    params = request.GET.dict()
    result = sabpaisa.verify_callback(params)
    if result["success"]:
        # Update order status
        pass
    return HttpResponse("OK")

Webhook Handling

@app.route('/webhook', methods=['POST'])
def webhook():
    payload = request.get_json()
    signature = request.headers.get('X-SabPaisa-Signature', '')

    result = sabpaisa.verify_webhook(payload, signature)

    if result["signature_valid"]:
        event = result["event"]
        # Process webhook event
        return jsonify({"status": "ok"}), 200
    return jsonify({"error": "Invalid signature"}), 400

Transaction Enquiry

response = sabpaisa.enquiry("MERCHANT_TXN_ID")

if response["success"]:
    print("Status:", response["status"])
    print("Amount:", response["amount"])
    print("Payment Mode:", response["paymentMode"])

Refund

# Full Refund
response = sabpaisa.refund("SABPAISA_TXN_ID")

# Partial Refund (Rs. 100)
response = sabpaisa.refund(
    transaction_id="SABPAISA_TXN_ID",
    amount=100.00,
    reason="Customer request"
)

if response["success"]:
    print("Refund ID:", response["refund_id"])

# Check Refund Status
status = sabpaisa.refund_status("REFUND_ID")

API Endpoints

Environment Base URL
Staging https://staging-sb-merchant-api.sabpaisa.in
Production https://merchant-api.sabpaisa.in

Features

  • Payment Initiation
  • Callback/Response Handling with Signature Verification
  • Webhook Handling
  • Transaction Enquiry
  • Refund (Full & Partial)
  • No external dependencies

Requirements

  • Python 2.7+ or Python 3.5+
  • No external packages required

Support

License

MIT License

Copyright (c) 2024 SabPaisa (SRS Live Technologies Pvt. Ltd.)

Metadata

Release files for sabpaisa-python 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sabpaisa-python 3.0.0
File Size Uploaded Provenance Actions
sabpaisa_python-3.0.0.tar.gz 7.5 kB Without provenance Details for sabpaisa_python-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sabpaisa-python 3.0.0
File Interpreter ABI Platform Actions
sabpaisa_python-3.0.0-py3-none-any.whl Python 3 none any Details for sabpaisa_python-3.0.0-py3-none-any.whl

Total release size: 14.6 kB

Release files / sabpaisa_python-3.0.0.tar.gz

Download URL sabpaisa_python-3.0.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c5538a420dbd5cc07fdbf235ddf4bc97c47b9bfa4133b0547b3e383ef44e9b6d
BLAKE2b-256 checksum
How to use checksums
585e6649845abfd13bd0d8bb06fa47852f864867aa4604fe4a48aff4350ec7a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / sabpaisa_python-3.0.0-py3-none-any.whl

Download URL sabpaisa_python-3.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32deb1e922b8ca6c88c98e65ca7aec8cb2258de59a5fa5bf722b3e0fa0ba759c
BLAKE2b-256 checksum
How to use checksums
8ebe621fa754b1dc31342e2bd335470df117bf517f6089eb9cab2cda8ba7138e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for sabpaisa-python 3.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page