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.2.tar.gz (5.0 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.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tspay_client-0.2.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for tspay_client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6aada6de059bf9d7dcf17438905bed4c8bc3117c4bbb5d86ae2861112e4ff4d1
MD5 e14fb35b5af28ed8a2d0c6fc8eac7ced
BLAKE2b-256 c5a3807ae0b74d9fbc1503b3ce66b70df737b31b46a88b8097942402cf072956

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tspay_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for tspay_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf92e06208b7c826fb135249c1ab0917f8c45cf9524aa95446d17032a0868aeb
MD5 535bc27985cf9efebc51e8d42ad9f760
BLAKE2b-256 e76ec92ab59f139e234fd557e970820a90a805a1375c71ed9fb46f450b639863

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