Skip to main content

A unified payment gateway SDK for Iranian gateways.

Project description

Payman — Unified Payment Gateway Integration for Python

Payman is a Python package for integrating with Iranian payment gateways like Zarinpal and Zibal. It provides a clean and flexible interface for handling payments in both sync and async Python applications.

Key Features

  • Simple and consistent API
    You can focus on your business logic — HTTP calls, serialization, and gateway-specific details are handled internally.

  • Supports both sync and async
    Compatible with synchronous and asynchronous code, including FastAPI, Flask, scripts, and background tasks.

  • Pydantic models for inputs and outputs
    Type-safe, auto-validating models make integration predictable and IDE-friendly.

  • Modular and extensible design
    Each gateway integration is separated. You can include only what you need or extend the package with your own gateway.

  • Unified error handling
    Common exception classes are used across gateways, with optional gateway-specific errors when needed.

  • Includes test coverage and mock support
    The package includes tests and gateway simulations to help with development and integration.

  • Suitable for real projects
    Designed to be usable in real applications, from small services to larger deployments.

Supported Payment Gateways (Currently)

Installation

pip install payman

Quick Start: ZarinPal Integration (Create, Redirect, Verify)

Here's a simple example using ZarinPal:

from payman.gateways.zarinpal import ZarinPal, Status
from payman.gateways.zarinpal.models import PaymentRequest, VerifyRequest

merchant_id = "YOUR_MERCHANT_ID"
amount = 10000  # IRR

pay = ZarinPal(merchant_id=merchant_id)

# 1. Create Payment
create_resp = pay.payment(
    PaymentRequest(
        amount=amount,
        callback_url="https://your-site.com/callback",
        description="Test Order"
    )
)
    
if create_resp.success:
    authority = create_resp.authority
    print("Redirect user to:", pay.get_payment_redirect_url(authority))
else:
    print(f"Create failed: {create_resp.message} (code {create_resp.code})")

# 2. After user returns to callback_url, verify the payment:
verify_resp = pay.verify(
    VerifyRequest(authority=authority, amount=amount)
)

if verify_resp.success:
    print("Payment successful:", verify_resp.ref_id)
elif verify_resp.already_verified:
    print("Already verified.")
else:
    print("Verification failed:", verify_resp)

Full Documentation

For detailed instructions on using ZarinPal and other gateways with Payman, including all parameters, response codes, and integration tips, please refer to the complete guide:

License

Licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for details.

Contributing

Contributions to Payman are welcome and highly appreciated. If you wish to contribute, please follow these guidelines:

  • Fork the repository and create a new branch for your feature or bugfix.
  • Ensure your code adheres to the project's coding standards and passes all tests.
  • Write clear, concise commit messages and provide documentation for new features.
  • Submit a pull request with a detailed description of your changes for review.

By contributing, you agree that your work will be licensed under the project's license.

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

payman-1.2.0.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

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

payman-1.2.0-py3-none-any.whl (47.0 kB view details)

Uploaded Python 3

File details

Details for the file payman-1.2.0.tar.gz.

File metadata

  • Download URL: payman-1.2.0.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for payman-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1353e749d8588843a0ecd5e57d3852f28b0c7d24ccf775abba24ab69ca3ba2ff
MD5 1d894637c2c3df07887300667271254a
BLAKE2b-256 173b35c1f232657d6fa4e25ca9db2e5b1c7185dc3111fe9eaa80a624945162d7

See more details on using hashes here.

File details

Details for the file payman-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: payman-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 47.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for payman-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c84bef30d2100dee18f42206d97ebbf75a34fe02d65b0539a34cabe90570676
MD5 f037fd750bf21d1b904526d105d64f66
BLAKE2b-256 1c4e498052adc82ef2a85c3f987bd7ea7809cd07615fd55775803ff7623f7d62

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