Skip to main content

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

Reason this release was yanked:

mistake 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.3.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.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: WalletPay-1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 2c1182e676270341060038d1493eca70af70a8b95451b344472b387f15b992bd
MD5 2cbebd64eaa09dcaaec04aa9ac9e1828
BLAKE2b-256 38c1936cb33a53672877afd2be52eb41a557e5a5ba05ab970cfd560ffec360da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: WalletPay-1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6878f1d2bbcab2ef8148a36da5893eb220f950a92bd872b3b0e4a00d1efd73b8
MD5 f8e933532acf5bb34318a294de01c1bb
BLAKE2b-256 88b350d4c0841c1051808f95bcf8c33b1e4603a026a5e2414e77bf29d43febce

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