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 PayPing.

Downloads


Installation

pip install pardakht

Usage

1️⃣ ZarinPal Integration

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 ZarinPal
zarinpal = ZarinPal(merchant_id=MERCHANT_ID, callback_url=CALLBACK_URL, sandbox=True)

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."

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"])

2️⃣ PayPing Integration

Import and Initialize

from pardakht.dargah import PayPing

# Settings
API_KEY = "YOUR_PAYPING_API_KEY"

# Create an instance of PayPing
payping = PayPing(api_key=API_KEY)

Create a Payment and Get the Payment Link

amount = 10000  # Amount in your currency unit
return_url = "https://yourdomain.com/callback"
payer_identity = "user@example.com"
description = "Premium subscription purchase"

payment_data = payping.create_payment(
    amount=amount,
    return_url=return_url,
    payer_identity=payer_identity,
    description=description
)

# Extract payment code to start the payment
payment_code = payment_data.get("metaData", {}).get("code")

if payment_code:
    pay_url = payping.start_payment(payment_code)
    print("Payment link:", pay_url)
else:
    print("Error creating payment:", payment_data)

Verify the Payment After User Returns from Gateway

ref_id = "REF_ID_FROM_CALLBACK"  # Obtained from callback parameters
payment_code = "PAYMENT_CODE"    # The same code returned from create_payment

result = payping.verify_payment(ref_id, payment_code)

if result.get("status") == 0:
    print("Payment verified successfully ✅")
else:
    print("Payment verification failed ❌")
    print("Details:", result)

3️⃣ Notes

  • Always generate a unique ID (uuid) for each ZarinPal transaction to track it in your database.
  • Store payment code and ref_id for PayPing transactions to verify later.
  • In Telegram bots, you can use pay_url as an inline button for users to click.
  • Use sandbox=True during testing in ZarinPal to avoid real transactions.
  • Handle errors gracefully and validate the response from each gateway before confirming the transaction.

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.2.0.tar.gz (3.6 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.2.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pardakht-0.2.0.tar.gz
Algorithm Hash digest
SHA256 66246e9f1da079e107b3f0f125cc8f6a5295cc2354eeb9d6671020b4ea76f3b1
MD5 025f08a537be9d8761a6a80f999c4b1b
BLAKE2b-256 59ffdb85ca6e2b20fd0eab6a7667a0239329918003a8b351bc252508b3ece9ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pardakht-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42eddd99cf7fbd77d0613d3b0f4cb4f4e6961bfd8efa902ffe7cb44ebc7cef79
MD5 3508a9c2cb0ff9920d08e925234abed4
BLAKE2b-256 cdfeb12729ec7cf0d7d341b2579c4d802799922307303d69396fe331116fa574

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