Skip to main content

A simple Python package to integrate bots or apps with payment gateways like ZarinPal.

Project description

Pardakht 🏦

Pardakht is a simple Python library to integrate bots or applications with payment gateways. Currently, it supports ZarinPal and is designed for Telegram bots.

Downloads

⚡ Coming soon: Support for web applications and other platforms. For now, you can use it directly in your bot projects.


Installation

pip install pardakht

Usage

1️⃣ Import and Initialize

from pardakht.dargah import ZarinPal

# Settings
MERCHANT_ID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
CALLBACK_URL = "https://yourdomain.com/check-payment"

# Create an instance of ZarinPalBot
zarinpal = ZarinPalBot(merchant_id=MERCHANT_ID, callback_url=CALLBACK_URL, sandbox=True)

2️⃣ Create a Payment and Get the Payment Link

amount = 10000  # Amount in Tomans
uuid_code = "some-unique-id-1234"  # You can use uuid.uuid4() for unique transactions
description = "Premium subscription purchase"

pay_url = zarinpal.make_payment(amount, uuid_code, description)

if pay_url.startswith("http"):
    print("Payment link:", pay_url)
else:
    print("Error:", pay_url)

⚡ If there is an issue connecting to the gateway, it will return: "Failed to connect to the payment gateway."


3️⃣ Verify the Payment After User Returns from Gateway

authority = "A1B2C3D4E5"  # Obtained from query params or gateway payload
result = zarinpal.verify_payment(authority, amount)

if result["success"]:
    print("Payment successful ✅")
    print("Tracking code:", result["ref_id"])
else:
    print("Payment failed ❌")
    print("Message:", result["message"])

4️⃣ Notes

  • Always generate a unique ID (uuid) for each transaction to track it in your database.
  • In Telegram bots, you can use pay_url as an inline button for users to click.
  • Use sandbox=True during testing to avoid real transactions.

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

pardakht-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

pardakht-0.1.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file pardakht-0.1.1.tar.gz.

File metadata

  • Download URL: pardakht-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pardakht-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2b73e87760391c157db77f96e128f670b3a146c3362d27aaadf8c895f6a70b74
MD5 7d3fe70644e62a76c413008978765036
BLAKE2b-256 5a601177a2e706b2e7339170340eceee64b06d1646a2f1e1c2ad22c8e7012e05

See more details on using hashes here.

File details

Details for the file pardakht-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pardakht-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pardakht-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3843ed999e0ac73af75a04ec6b602927d45b3ab2aecd3c7e36361b8ecdac7cd
MD5 49dbd6af357b88b0bb165063f2a7bffd
BLAKE2b-256 4cd4cbba5e13fb469e22e67806db367d172d48e158b2b0db1715968a06d00a7a

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