О библиотеке 💙
Библиотека CrystalPayIO предоставит удобное использование и интеграцию CrystalPay API в ваши проекты.
В данном репозитории вы найдете способы установки и использования библиотеки. Если вы обнаружите баги или какие-либо проблемы при использовании прошу отписать в телеграм. Данный модуль будет поддерживаться и обновляться. Спасибо, хорошего настроения!
Установка 🧡
- Установка, используя пакетный менеджер pip
$ pip install crystalpayio
- Установка с GitHub (требуется git)
$ git clone https://github.com/Fsoky/crystalpayio
$ cd crystalpayio
$ python setup.py install
- Или
$ pip install git+https://github.com/Fsoky/crystalpayio
Примеры использования 💜
- Шаблон
import asyncio
from crystalpayio import CrystalPayIO
async def main() -> None:
async with CrystalPayIO("AUTH_LOGIN", "AUTH_SECRET") as crystal:
...
if __name__ == "__main__":
asyncio.run(main())
- Доступные методы
checkout- Касса
payment- Платежи
invoice- Инвойсы (чеки)
payoff- Вывод средств
ticker- Доступные валюты и курс
history- История платежей/выводов/общая
async with CrystalPayIO("AUTH_LOGIN", "AUTH_SECRET") as crystal:
# Каждый метод хранится в свойстве, например касса:
checkout = await crystal.checkout.me()
Пример интеграции в телеграм-бота (aiogram 3.x) ❤
import asyncio
from aiogram import Router, Bot, Dispatcher, F
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
from aiogram.filters import CommandStart
from crystalpayio import CrystalPayIO
router = Router()
crystal = CrystalPayIO("AUTH_LOGIN", "AUTH_SECRET")
async def create_invoice() -> tuple:
invoice = await crystal.invoice.create(
100, # Цена
5, # Время жизни чека (в минутах)
amount_currency="RUB" # Валюта
)
return (invoice.url, invoice.id)
async def invoice_handler(id: str, message: Message) -> None:
while True:
invoice = await crystal.invoice.get(id)
if invoice.state != "notpayed":
await message.answer("Счёт успешно оплачен!")
await asyncio.sleep(15) # Задержка
@router.message(CommandStart())
async def show_goods(message: Message) -> None:
await message.answer(
"🎃 Тыква - 100 РУБ.",
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text="КУПИТЬ", callback_data="buy")]
]
)
)
@router.callback_query(F.data == "buy")
async def buy_handler(query: CallbackQuery) -> None:
invoice_task = asyncio.create_task(create_invoice())
invoice_result = await invoice_task
await query.message.answer(f"Перейди по ссылке и оплати: {invoice_result[0]}")
await query.answer()
asyncio.create_task(invoice_handler(invoice_result[1], query.message))
async def main() -> None:
bot = Bot("TOKEN")
dp = Dispatcher()
dp.include_router(router)
await bot.delete_webhook(True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
Пример использования Webhook'ов 🕸
import asyncio
from crystalpayio import CrystalPayIO, WebhookManager, PaymentEvent
from fastapi import FastAPI # pip install fastapi[all]
import uvicorn # pip install uvicorn
WEBHOOK_URL = "https://xxx-xxx-xxx.ngrok-free.app" # ngrok url
WEBHOOK_ENDPOINT = "/my-endpoint"
app = FastAPI()
crystal = CrystalPayIO("AUTH_LOGIN", "AUTH_SECRET")
wm = WebhookManager(app)
wm.register_webhook_endpoint(WEBHOOK_ENDPOINT) # Регистрируем путь к вебхуку
@wm.successfull_payment()
async def handle_successfull_event(event: PaymentEvent) -> None:
print(event)
async def create_invoice() -> None:
order = await crystal.invoice.create(
10, # Сумма (в рублях)
5, # Время жизни чека (в минутах)
callback_url=f"{WEBHOOK_URL}{WEBHOOK_ENDPOINT}"
)
print(order.url)
if __name__ == "__main__":
asyncio.run(create_invoice()) # Запуск функции
uvicorn.run("test:app")
Metadata
Release files for crystalpayio 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crystalpayio-1.0.5.tar.gz | 10.9 kB | Without provenance | Details for crystalpayio-1.0.5.tar.gz |
Release files / crystalpayio-1.0.5.tar.gz
| Download URL | crystalpayio-1.0.5.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ece27c207b3e9af96867673787474c33404c50080c8a84701e917cd66570f8fc
|
|
BLAKE2b-256 checksum How to use checksums |
75a8edec0d99b8cfa2cdd4b47fbfc12413cba88f8f12e7cb1230ba017c80cf2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for crystalpayio 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.