Skip to main content

A Python client for the API pay.wallet.tg.

Reason this release was yanked:

bug in code

Project description

WalletPay API Client

A Python client for interacting with the WalletPay API.

Installation

Install the package using pip:

pip install WalletPay

Usage

Synchronous Client

from WalletPay import WalletPayAPI

# Initialize the API client
api = WalletPayAPI(api_key="YOUR_API_KEY")

# Create an order
order = api.create_order(
    amount=100,
    currency_code="USD",
    description="Test Order",
    external_id="12345",
    timeout_seconds=3600,
    customer_telegram_user_id="telegram_user_id"
)

# Get order preview
order_preview = api.get_order_preview(order_id="ORDER_ID")

# Check if the order is paid
if order_preview.status == "PAID":
    print("Order has been paid!")
else:
    print("Order is not paid yet.")

# Get order list
orders = api.get_order_list(offset=0, count=10)

# Get order amount
amount = api.get_order_amount()

Asynchronous Client

To work with the asynchronous client, you'll need an async environment, such as asyncio.

import asyncio
from WalletPay import AsyncWalletPayAPI

async def main():
    # Initialize the async API client
    api = AsyncWalletPayAPI(api_key="YOUR_API_KEY")

    # Create an order
    order = await api.create_order(
        amount=100,
        currency_code="USD",
        description="Test Order",
        external_id="12345",
        timeout_seconds=3600,
        customer_telegram_user_id="telegram_user_id"
    )

    # Get order preview
    order_preview = await api.get_order_preview(order_id="ORDER_ID")
    
    # Check if the order is paid
    if order_preview.status == "PAID":
        print("Order has been paid!")
    else:
        print("Order is not paid yet.")
    
    # Get order list
    orders = await api.get_order_list(offset=0, count=10)

    # Get order amount
    amount = await api.get_order_amount()

# Run the async function
asyncio.run(main())

Webhook Integration with Aiogram

To integrate WalletPay webhooks with an Aiogram bot, you can use the WebhookManager class. Here's a basic example:

from aiogram import Bot, Dispatcher, types
from WalletPay import WalletPayAPI, WebhookManager
from WalletPay.types import Event
import asyncio

API_TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'

bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)

# Initialize WalletPay API and WebhookManager
wallet_api = WalletPayAPI(api_key="YOUR_WALLET_API_KEY")
wm = WebhookManager(client=wallet_api)

@wm.successful_handler()
async def handle_successful_event(event: Event):
    # Handle successful payment event
    user_id = "USER_ID"
    await bot.send_message(chat_id=user_id, text=f"Your payment for order {event.payload.id}  was successful!")

@wm.failed_handler()
async def handle_failed_event(event: Event):
    # Handle failed payment event
    user_id = "USER_ID"
    await bot.send_message(chat_id=user_id, text=f"Your payment for order {event.payload.id} failed. Please try again.")

async def on_startup(dp):
    await bot.send_message(chat_id="YOUR_ADMIN_ID", text="Bot has started!")
    # Start the webhook manager in the background
    asyncio.create_task(wm.start())

async def on_shutdown(dp):
    await bot.send_message(chat_id="YOUR_ADMIN_ID", text="Bot is shutting down!")

# Aiogram bot handlers
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    await message.reply("Welcome to our bot!")

# Start the Aiogram bot
if __name__ == '__main__':
    from aiogram import executor
    executor.start_polling(dp, on_startup=on_startup, on_shutdown=on_shutdown)

This example demonstrates how to integrate WalletPay webhooks with an Aiogram bot using asyncio and on_startup. When a payment event occurs, the bot will send a message to the user notifying them of the payment status.

Note: Ensure that you've set the webhook URL on the WalletPay website to match the WEBHOOK_HOST and WEBHOOK_PATH in your code. Additionally, your server must have an SSL certificate issued by trusted certificate authorities (CA), such as Let's Encrypt. Self-signed certificates will not be accepted by WalletPay.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Contact

For any questions or feedback, please reach out to @xdownedx on Telegram.

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

WalletPay-1.2.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

WalletPay-1.2.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file WalletPay-1.2.2.tar.gz.

File metadata

  • Download URL: WalletPay-1.2.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for WalletPay-1.2.2.tar.gz
Algorithm Hash digest
SHA256 8d0cac6284f969ccec7cba30b9805503ee8b8c6977ba100c515f118aa7a0e4a3
MD5 b07d009743217dc214385e7c6d2c3322
BLAKE2b-256 9e716b3161319a5427a40e012605bb32c16c287590c553ff70ce8917aa47e792

See more details on using hashes here.

File details

Details for the file WalletPay-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: WalletPay-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for WalletPay-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe23ddaeea23df6f0ffd8877d6cd9519a339e934cb7ff9c5b13c691d4bb6e601
MD5 762d839772ab4b3b6fd3b453c4598b51
BLAKE2b-256 246784a1c4fb485c55cb740d046e34004cb1c2fd4a6b56d767b0f0f2c6067464

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