Skip to main content

TSPay uchun rasmiy Python klienti

Project description

TsPay Python Client

PyPI version Python Version License: MIT

Examples

🔹 1. Minimal Example

from tspay import TsPayClient
from tspay.exceptions import TsPayError

# Do'kon access_token (shaxsiy kabinetingizdan olasiz)
SHOP_ACCESS_TOKEN = "your_shop_access_token"

client = TsPayClient()

try:
    # 1) Tranzaksiya yaratish
    transaction = client.create_transaction(
        amount=50000,  # so'm
        redirect_url="https://yourwebsite.com/payment/callback",
        comment="Order #1001",
        access_token=SHOP_ACCESS_TOKEN
    )

    print("✅ Tranzaksiya yaratildi!")
    print("Payment URL:", transaction["payment_url"])
    print("Cheque ID:", transaction["cheque_id"])

    # 2) Tranzaksiya holatini tekshirish
    status = client.check_transaction(
        access_token=SHOP_ACCESS_TOKEN,
        cheque_id=transaction["cheque_id"]
    )

    print("Transaction status:", status["status"])

except TsPayError as e:
    print("❌ Xato:", str(e))

🔹 2. Transaction Status Check Example

from tspay import TsPayClient
from tspay.exceptions import TsPayError

SHOP_ACCESS_TOKEN = "your_shop_access_token"

client = TsPayClient()

try:
    # Oldindan mavjud tranzaksiya (masalan DB yoki callback orqali olingan)
    cheque_id = "e3b0c442-98fc-4b01-a3f7-7c4e4f8d6f2a"

    # Tranzaksiya holatini tekshirish
    status = client.check_transaction(
        access_token=SHOP_ACCESS_TOKEN,
        cheque_id=cheque_id
    )

    print("✅ Tranzaksiya topildi")
    print("Cheque ID:", cheque_id)
    print("Holati:", status["status"])
    print("Summa:", status["amount"])
    print("Vaqti:", status["created_at"])

except TsPayError as e:
    print("❌ Tekshirishda xato:", str(e))

#ErrorHandling #PaymentIntegration #PythonSDK

🔹 3. Full Example with Error Handling

from tspay import TsPayClient
from tspay.exceptions import AuthenticationError, TransactionNotFound, NetworkError

client = TsPayClient()
SHOP_ACCESS_TOKEN = "invalid_token"

try:
    txn = client.create_transaction(
        amount=20000,
        redirect_url="https://example.com/callback",
        comment="Test order",
        access_token=SHOP_ACCESS_TOKEN
    )
except AuthenticationError as e:
    print("❌ Access token noto‘g‘ri:", e)
except TransactionNotFound as e:
    print("❌ Tranzaksiya topilmadi:", e)
except NetworkError as e:
    print("❌ Internet muammo:", e)

🔹 4. To‘liq Payment Flow (production)

from tspay import TsPayClient
from tspay.exceptions import TsPayError
SHOP_ACCESS_TOKEN = "your_shop_access_token"

def process_payment(amount: float, comment: str):
    client = TsPayClient()
    try:
        # 1) Tranzaksiya yaratish
        transaction = client.create_transaction(
            amount=amount,
            redirect_url="https://example.com/payment/callback",
            comment=comment,
            access_token=SHOP_ACCESS_TOKEN
        )

        # 2) Foydalanuvchiga to‘lov sahifasini yuborish
        return {
            "success": True,
            "payment_url": transaction["payment_url"],
            "cheque_id": transaction["cheque_id"]
        }

    except TsPayError as e:
        return {"success": False, "error": str(e)}

# --- Usage ---
result = process_payment(10000, "Order #500")
if result["success"]:
    print("Payment URL:", result["payment_url"])
else:
    print("❌ Error:", result["error"])

MIT License

MIT License

Copyright (c) 2025 Muhammadakbar Komilov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Social Links

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

tspay_client-0.2.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

tspay_client-0.2.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file tspay_client-0.2.3.tar.gz.

File metadata

  • Download URL: tspay_client-0.2.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for tspay_client-0.2.3.tar.gz
Algorithm Hash digest
SHA256 aa5ed6634b76d80e0eba8f814c5d1cba64dc98616c8c4d5cf86c463cb788ea62
MD5 4cab56c57d7843a5f39c7bb23d69ed2b
BLAKE2b-256 e9b4ec722958f727f42151cc47d616a906c4708d71bfb467f47caec346c01053

See more details on using hashes here.

File details

Details for the file tspay_client-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: tspay_client-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for tspay_client-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 49c6d25c15fb11d55ef3a4fd021fc418d107d0f47b03da7b76292bac3c637b8f
MD5 09c49207e50021cc0aea9bcd18f47a14
BLAKE2b-256 719c6adbe625edf9a4946123250786380349f0b09c1d220cd095188f39a62c22

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