Skip to main content

Python SDK for Zarinpal Payment Gateway with sync and async support.

Project description

Zarinpal Python SDK

A modern, type-safe Python SDK for Zarinpal Payment Gateway with both synchronous and asynchronous support.

Features

  • ✅ Sync and async client support
  • ✅ Type hints and full IDE autocomplete
  • ✅ Comprehensive error handling
  • ✅ Support for all Zarinpal API endpoints
  • ✅ Sandbox environment for testing
  • ✅ Custom StartPay endpoint configuration
  • ✅ Wage splitting for shared settlements
  • ✅ Fee calculation utilities

Installation

pip install irgateway

Quick Start

Synchronous Usage

from irgateway.zarinpal import ZarinpalClient
from irgateway.zarinpal.enums import Environment, Currency

# Initialize client
client = ZarinpalClient(
    merchant_id="YOUR-MERCHANT-ID",
    environment=Environment.SANDBOX  # Use PRODUCTION for live
)

# Create payment request
payment = client.request(
    amount=10000,
    callback_url="https://yoursite.com/callback",
    description="خرید محصول"
)

print(f"Payment URL: {payment.payment_url}")

# Verify payment after callback
verification = client.verify(
    authority="A00000000000000000000000000123456789",
    amount=10000
)

print(f"Reference ID: {verification.ref_id}")

Asynchronous Usage

from irgateway.zarinpal import ZarinpalClient
from irgateway.zarinpal.enums import Environment, Currency

async def process_payment():
    async with AsyncZarinpalClient(
        merchant_id="YOUR-MERCHANT-ID",
        environment=Environment.SANDBOX
    ) as client:
        payment = await client.request(
            amount=10000,
            callback_url="https://yoursite.com/callback",
            description="خرید محصول"
        )
        return payment.payment_url

# In your async function
url = await process_payment()

API Methods

Method Description
request() Create new payment request
verify() Verify payment after user returns
unverified() Get list of unverified transactions
reverse() Request refund (requires permission)
inquiry() Check payment status
calculate_fee() Calculate gateway fees

Advanced Features

Payment Metadata

from irgateway.types import PaymentMetadata

metadata = PaymentMetadata(
    mobile="09123456789",
    email="user@example.com"
)

payment = client.request(
    amount=10000,
    callback_url="https://yoursite.com/callback",
    description="خرید محصول",
    metadata=metadata
)

Wage Splitting

from irgateway.zarinpal.types import Wage

wages = [
    Wage(iban="IR123456789012345678901234", amount=5000),
    Wage(iban="IR987654321098765432109876", amount=3000)
]

payment = client.request(
    amount=10000,
    callback_url="https://yoursite.com/callback",
    description="خرید مشترک",
    wages=wages
)

Configuration

from irgateway.zarinpal import ZarinpalClient, ZarinpalConfig

config = ZarinpalConfig(
    timeout=30,  # Request timeout in seconds
    startpay_endpoint="https://custom-gateway.com/"  # Optional custom gateway
)

client = ZarinpalClient(
    merchant_id="YOUR-MERCHANT-ID",
    config=config
)

Error Handling

from irgateway.zarinpal.errors import ZarinpalException, InvalidMerchantError

try:
    payment = client.request(...)
except InvalidMerchantError:
    print("Merchant ID is invalid")
except ZarinpalException as e:
    print(f"Error {e.code}: {e.message}")

Requirements

  • Python 3.7+
  • requests (for sync client)
  • aiohttp (for async client)

Development

# Clone repository
git clone https://github.com/javad2nd/irgateway.git
cd irgateway

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

irgateway-0.1.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

irgateway-0.1.2-py2.py3-none-any.whl (15.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file irgateway-0.1.2.tar.gz.

File metadata

  • Download URL: irgateway-0.1.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for irgateway-0.1.2.tar.gz
Algorithm Hash digest
SHA256 867cabfb9b6976ec5fc6dad717f86f6a1fd3957066bd86d18e5cff8362c687d6
MD5 1df4e7eef407d6b15947829c3b17c41f
BLAKE2b-256 f6e8ef6d463cac859a0adb864a54b24812ec9fd29617950a27271c7c54d1833e

See more details on using hashes here.

File details

Details for the file irgateway-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: irgateway-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for irgateway-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ea51e868cf5d7e01123bfc1e68ce94a5b058e34a539b10a102b61c3f6af69de8
MD5 03a094c9bc1c34f50e2618e2670de469
BLAKE2b-256 a8e18ba00b9c2eda5cefba80312a249f54c1a399ad533f53f78fb34c4853e4c5

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