Skip to main content

A Python SDK for Zarinpal Payment Gateway

Project description

Zarinpal Python SDK Documentation

Introduction

The Zarinpal Python SDK provides an easy and flexible way to interact with Zarinpal’s payment gateway APIs. With features like payment initiation, transaction management, refunds, and reversals, it helps streamline integration with Zarinpal’s platform in both live and sandbox environments.


Installation

Requirements:

  • Python >= 3.12

Install:

From PyPI:

pip install zarinpal-py-sdk

From TestPyPI (for testing purposes):

pip install -i https://test.pypi.org/simple/ zarinpal-py-sdk

Features:

  1. Manage Payments:

    Easily initiate and verify payments using secure APIs.

    Example:

    payment = zarinpal.payment_gateway.create({  
        "amount": 10000,  
        "description": "Order #1234",  
        "callback_url": "https://example.com/callback",  
    })
    
  2. Calculate Fee:

    Calculate the transaction fee

    Example:

        fee = zarinpal.fee.calculate({
            "amount": 90000,
            "currency": "IRR"
        })
        print("Fee Calculation Result:", fee)
    
  3. Transaction Management:

    Fetch transaction details with filters, limits, and pagination using GraphQL.

    Example:

    transactions = zarinpal.transactions.list({  
        "terminal_id": "YourTerminalID",  
        "filter": "PAID",  
        "limit": 10,  
        "offset": 0,  
    })
    
  4. Refunds & Reversals:

    Easily process refunds or reverse a transaction with a single API call.

    Example - Refund:

    refund = zarinpal.refunds.create({  
        "session_id": "Session1234",  
        "amount": 5000,  
        "description": "Refund for Order #1234",  
        "reason": "CUSTOMER_REQUEST",  
    })
    
    Example - Reversal:
    
    response = zarinpal.reversals.reverse({  
        "authority": "AUTHORITY_CODE",  
    })
    
  5. Sandbox Support:

    Easily switch between sandbox and live environments for development and production.

How to Use:

  1. Initialize SDK:
from zarinpal_utils.Config import Config
from zarinpal import ZarinPal

config = Config(  
    access_token="YourAccessToken",  
    merchant_id="YourMerchantId"
    sandbox=True,  # Use sandbox environment  
)  
zarinpal = ZarinPal(config)  

Full Example: Fetching Transactions

from zarinpal_utils.Config import Config
from zarinpal import ZarinPal

def get_transactions():  
    try:  
        config = Config(  
            access_token="YourAccessToken",  
        )  
        zarinpal = ZarinPal(config)  

        transactions = zarinpal.transactions.list({  
            "terminal_id": "YourTerminalID",  
            "filter": "PAID",  
            "limit": 10,  
            "offset": 0,  
        })  

        print("Transactions List:", transactions)  
    except Exception as e:  
        print("Error fetching transactions:", e)  

if __name__ == "__main__":  
    get_transactions()

Contribute:

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.

GitHub Repository: Zarinpal Python SDK

By simplifying integration, this SDK ensures smooth payment workflows, enabling developers to focus on building excellent user experiences.

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

zarinpal_py_sdk-0.1.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

zarinpal_py_sdk-0.1.4-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file zarinpal_py_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: zarinpal_py_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for zarinpal_py_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ee5608b96bd207332239030bbae75c2c30448a79ed4bbb78f641c17d5c3140d9
MD5 84f5e34ef6b8b27e4f83f010960629c2
BLAKE2b-256 205134404a815abd09d3ccfcb35f7de5cc9a3232e6684d8e696fe884f5595609

See more details on using hashes here.

File details

Details for the file zarinpal_py_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for zarinpal_py_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c579bc3c2f85a065e3d48e169877de82b4af18942b229ec1d3b8d7a00d970d5b
MD5 96f61538abbcdb789df625b71405095c
BLAKE2b-256 8d1e0a6fa2df624a3f63e5fb5396fec35203adc5833fffaba021a7646bf3295a

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