Один API-запрос. Готовые сниппеты под популярные стеки — копируйте и деплойте.
Асинхронный фреймворк для Telegram-ботов
pip install aiogram httpximport asyncio, os, httpx
from aiogram import Bot, Dispatcher, F
from aiogram.types import Message
BOT_TOKEN = os.getenv("BOT_TOKEN")
MEFOS_KEY = os.getenv("MEFOS_API_KEY")
API = "https://pay.mefos.mom/api/v1/payments"
bot = Bot(BOT_TOKEN)
dp = Dispatcher()
@dp.message(F.text == "/buy")
async def buy(message: Message):
async with httpx.AsyncClient(timeout=15) as c:
r = await c.post(
API,
headers={"X-API-Key": MEFOS_KEY},
json={"amount": 500, "order_id": f"tg_{message.from_user.id}"},
)
data = r.json()
await message.answer(f"Оплатить: {data['payment_link']}")
asyncio.run(dp.start_polling(bot))
pyTelegramBotAPI — простой старт
pip install pyTelegramBotAPI requestsimport os, telebot, requests
bot = telebot.TeleBot(os.getenv("BOT_TOKEN"))
KEY = os.getenv("MEFOS_API_KEY")
@bot.message_handler(commands=["buy"])
def buy(message):
r = requests.post(
"https://pay.mefos.mom/api/v1/payments",
headers={"X-API-Key": KEY},
json={"amount": 500, "order_id": f"tg_{message.from_user.id}"},
timeout=15,
)
bot.send_message(message.chat.id, r.json()["payment_link"])
bot.polling(none_stop=True)
Веб-фреймворк для сайтов и API
settings.py: MEFOS_API_KEY = "..."import uuid, requests
from django.conf import settings
from django.http import JsonResponse
def create_payment(request):
r = requests.post(
"https://pay.mefos.mom/api/v1/payments",
headers={"X-API-Key": settings.MEFOS_API_KEY},
json={
"amount": float(request.GET.get("amount", 500)),
"order_id": f"dj_{uuid.uuid4().hex[:12]}",
},
timeout=15,
)
return JsonResponse({"payment_link": r.json()["payment_link"]})
Асинхронный веб-фреймворк
import os, uuid, httpx
from fastapi import FastAPI, Request
from fastapi.responses import RedirectResponse
app = FastAPI()
KEY = os.getenv("MEFOS_API_KEY")
@app.post("/buy")
async def buy(request: Request):
body = await request.json()
async with httpx.AsyncClient(timeout=15) as c:
r = await c.post(
"https://pay.mefos.mom/api/v1/payments",
headers={"X-API-Key": KEY},
json={
"amount": body.get("amount", 500),
"order_id": f"fa_{uuid.uuid4().hex[:12]}",
},
)
return RedirectResponse(r.json()["payment_link"])
Современный PHP-фреймворк
.env: MEFOS_API_KEY=...<?php
use Illuminate\Support\Facades\Http;
Route::post('/buy', function (Request $request) {
$resp = Http::withHeaders([
'X-API-Key' => env('MEFOS_API_KEY'),
])->post('https://pay.mefos.mom/api/v1/payments', [
'amount' => (float) $request->input('amount', 500),
'order_id' => 'laravel_' . uniqid(),
]);
return redirect($resp->json('payment_link'));
});
Шорткод для оплаты на любой странице
<?php
// Шорткод: [mefos_buy amount="500"]
add_shortcode('mefos_buy', function ($atts) {
$response = wp_remote_post('https://pay.mefos.mom/api/v1/payments', [
'headers' => [
'X-API-Key' => get_option('mefos_api_key'),
'Content-Type' => 'application/json',
],
'body' => json_encode([
'amount' => (float) $atts['amount'],
'order_id' => 'wp_' . uniqid(),
]),
'timeout' => 15,
]);
$data = json_decode(wp_remote_retrieve_body($response), true);
return '<a href="' . esc_url($data['payment_link']) . '">Оплатить</a>';
});
Лёгкий backend на JavaScript
const express = require("express");
const axios = require("axios");
const app = express();
app.use(express.json());
app.post("/buy", async (req, res) => {
const { data } = await axios.post(
"https://pay.mefos.mom/api/v1/payments",
{ amount: req.body.amount || 500, order_id: "node_" + Date.now() },
{
headers: { "X-API-Key": process.env.MEFOS_API_KEY },
timeout: 15000,
}
);
res.redirect(data.payment_link);
});
app.listen(3000);
React-фреймворк с API routes
// app/api/buy/route.js
import { NextResponse } from "next/server";
export async function POST(request) {
const body = await request.json();
const r = await fetch("https://pay.mefos.mom/api/v1/payments", {
method: "POST",
headers: {
"X-API-Key": process.env.MEFOS_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: body.amount || 500,
order_id: "next_" + Date.now(),
}),
});
const data = await r.json();
return NextResponse.redirect(data.payment_link);
}