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.4.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.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tspay_client-0.2.4.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.4.tar.gz
Algorithm Hash digest
SHA256 3d1e09fc032907bb3fcd9c8382fb864d703734806113f17314e8ce6a7c0ac9fe
MD5 9d535919e47902a17a751b00ed98b571
BLAKE2b-256 a489d72a2b3995408545fcb2725d099e2e087bf64d716633a10c82db2deecc23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tspay_client-0.2.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 af946bc4200a56f37f3fb74e6be39fd61058f474027e8541348d8433aa20a30f
MD5 741a991b7e686f71143327f74b2e6c10
BLAKE2b-256 a3cb30789213d55e5e6eb08fa23170b69df7d0940969be8b112b53a2bba03592

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