Official Python SDK for SabPaisa Payment Gateway
Project description
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
- Email: support@sabpaisa.in
- Website: https://www.sabpaisa.in
- Documentation: https://docs.sabpaisa.in
License
MIT License
Copyright (c) 2024 SabPaisa (SRS Live Technologies Pvt. Ltd.)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sabpaisa_python-3.0.0.tar.gz
(7.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sabpaisa_python-3.0.0.tar.gz.
File metadata
- Download URL: sabpaisa_python-3.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5538a420dbd5cc07fdbf235ddf4bc97c47b9bfa4133b0547b3e383ef44e9b6d
|
|
| MD5 |
fec25ea94ec74e1eba37e34d1e97898a
|
|
| BLAKE2b-256 |
585e6649845abfd13bd0d8bb06fa47852f864867aa4604fe4a48aff4350ec7a6
|
File details
Details for the file sabpaisa_python-3.0.0-py3-none-any.whl.
File metadata
- Download URL: sabpaisa_python-3.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32deb1e922b8ca6c88c98e65ca7aec8cb2258de59a5fa5bf722b3e0fa0ba759c
|
|
| MD5 |
c8e61de64c9a76e7cee7e2ed1c21a2e6
|
|
| BLAKE2b-256 |
8ebe621fa754b1dc31342e2bd335470df117bf517f6089eb9cab2cda8ba7138e
|