Metadata-Version: 2.4
Name: sabpaisa-python
Version: 3.0.0
Summary: Official Python SDK for SabPaisa Payment Gateway
Home-page: https://www.sabpaisa.in
Author: SabPaisa
Author-email: SabPaisa <support@sabpaisa.in>
License: MIT
Project-URL: Homepage, https://www.sabpaisa.in
Project-URL: Documentation, https://docs.sabpaisa.in
Project-URL: Repository, https://github.com/sabpaisa/sabpaisa-python
Keywords: sabpaisa,payment,gateway,india,upi,card,netbanking,wallet
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# SabPaisa Python SDK

Official Python SDK for SabPaisa Payment Gateway 2.0

**Supports Python 2.7+ to Python 3.12+**

## Installation

```bash
pip install sabpaisa-python
```

## Quick Start

```python
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

```python
# 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

```python
@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

```python
response = sabpaisa.enquiry("MERCHANT_TXN_ID")

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

## Refund

```python
# 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.)
