একাই চালাতে পারবেন পুরো ব্যবসা ৭ দিনের ফ্রি ট্রায়াল
ToPay

Developers

ToPay API

Create invoices, verify payments and receive signed webhooks. Copy-paste examples for cURL, PHP and Node.js.

Base URL: https://topay.smoemi.com. All responses are JSON in the form {"status": true|false, "message": "...", "data": {...}}.

Quick start

  1. Create an account, add your wallet numbers and pair your Android phone.
  2. Go to Dashboard → Developers and create a live and a sandbox API key.
  3. Call Create payment from your server and redirect the customer to payment_url.
  4. When the customer comes back to your success_url (or your webhook is called), verify the payment on your server before delivering the order.

Authentication

Send your secret key in the X-API-KEY header. For old SMM panel scripts the key may also be sent as an api_key form/body field. Keys start with sk_live_ (real payments) or sk_test_ (sandbox). Keep keys on your server only — never in JavaScript or mobile apps.

Create payment

POST /api/v1/payment/create

FieldTypeDescription
amountnumber, requiredAmount in BDT (min 1).
success_urlurl, requiredCustomer is sent here after paying, with ?invoice_id=…&status=… added.
cancel_urlurl, requiredCustomer is sent here if they cancel or the invoice expires.
webhook_urlurl, optionalOverrides the webhook URL set in the dashboard for this invoice.
customer_name, customer_email, customer_phonestring, optionalShown in your dashboard and sent back in webhooks.
metadataobject, optionalAny JSON (max 5 KB), e.g. your order ID. Returned unchanged.

cURL

curl -X POST https://topay.smoemi.com/api/v1/payment/create \
  -H "X-API-KEY: sk_live_xxxxxxxxxxxx_xxxxxxxx" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 500,
    "customer_name": "Rahim",
    "customer_email": "rahim@example.com",
    "metadata": {"order_id": 1001},
    "success_url": "https://yourshop.com/payment/success",
    "cancel_url": "https://yourshop.com/payment/cancel",
    "webhook_url": "https://yourshop.com/payment/webhook"
  }'

Response

{
  "status": true,
  "message": "Payment created.",
  "data": {
    "invoice_id": "SPQ7W2KX9M4T1ZB8RC",
    "payment_url": "https://topay.smoemi.com/pay/SPQ7W2KX9M4T1ZB8RC",
    "amount": 500,
    "mode": "live",
    "expires_at": "2026-10-03T15:30:00+06:00"
  }
}

PHP (SDK)

<?php
require 'ToPay.php'; // from /sdk/php in the ToPay repository

$topay = new ToPay('sk_live_xxxxxxxxxxxx_xxxxxxxx', 'https://topay.smoemi.com');

// 1. Create an invoice and send the customer to the checkout page
$payment = $topay->createPayment([
    'amount'      => 500,
    'customer_name'  => 'Rahim',
    'metadata'    => ['order_id' => 1001],
    'success_url' => 'https://yourshop.com/payment/success',
    'cancel_url'  => 'https://yourshop.com/payment/cancel',
]);
header('Location: ' . $payment['payment_url']);

// 2. On success_url, always verify on the server before delivering
$result = $topay->verifyPayment($_GET['invoice_id']);
if ($result['status'] === 'completed') {
    // mark order 1001 as paid
}

Node.js

// Node.js 18+ (built-in fetch)
const API_KEY = process.env.TOPAY_KEY;

const res = await fetch('https://topay.smoemi.com/api/v1/payment/create', {
  method: 'POST',
  headers: { 'X-API-KEY': API_KEY, 'Content-Type': 'application/json', 'Accept': 'application/json' },
  body: JSON.stringify({
    amount: 500,
    metadata: { order_id: 1001 },
    success_url: 'https://yourshop.com/payment/success',
    cancel_url: 'https://yourshop.com/payment/cancel',
  }),
});
const { status, data, message } = await res.json();
if (!status) throw new Error(message);
// redirect the customer to data.payment_url

Verify payment

POST /api/v1/payment/verify with invoice_id. Possible status values: pending, processing (customer submitted a TrxID, waiting for the SMS), completed, partial (customer paid less — decide manually), expired, cancelled.

curl -X POST https://topay.smoemi.com/api/v1/payment/verify \
  -H "X-API-KEY: sk_live_xxxxxxxxxxxx_xxxxxxxx" \
  -H "Accept: application/json" \
  -d "invoice_id=SPQ7W2KX9M4T1ZB8RC"
{
  "status": true,
  "message": "Payment completed.",
  "data": {
    "invoice_id": "SPQ7W2KX9M4T1ZB8RC",
    "status": "completed",
    "mode": "live",
    "amount": 500,
    "paid_amount": 500,
    "currency": "BDT",
    "method": "bkash",
    "trx_id": "BJK7A1B2C3",
    "customer_name": "Rahim",
    "customer_email": "rahim@example.com",
    "customer_phone": null,
    "metadata": {"order_id": 1001},
    "paid_at": "2026-10-03T15:02:11+06:00",
    ...
  }
}

List transactions

GET /api/v1/transactions — optional filters status, from, to (YYYY-MM-DD), per_page (max 100), page.

curl "https://topay.smoemi.com/api/v1/transactions?status=completed&from=2026-10-01&to=2026-10-31&per_page=50" \
  -H "X-API-KEY: sk_live_xxxxxxxxxxxx_xxxxxxxx" -H "Accept: application/json"

Webhooks

When an invoice becomes completed, partial or expired, ToPay sends a POST request to your webhook URL. Respond with any 2xx status. Failed deliveries are retried after 1, 5, 30 and 120 minutes. You can see every delivery, resend it, and send a test webhook from Dashboard → Developers.

Always check the signature: X-TOPAY-Signature: sha256=HMAC_SHA256(raw_body, webhook_secret). Handle webhooks idempotently — the same event can arrive more than once.

POST /payment/webhook
Content-Type: application/json
X-TOPAY-Event: payment.completed
X-TOPAY-Signature: sha256=5f1c0e...a9

{
  "event": "payment.completed",
  "invoice_id": "SPQ7W2KX9M4T1ZB8RC",
  "status": "completed",
  "mode": "live",
  "amount": 500,
  "paid_amount": 500,
  "currency": "BDT",
  "trx_id": "BJK7A1B2C3",
  "method": "bkash",
  "customer_name": "Rahim",
  "customer_email": "rahim@example.com",
  "customer_phone": null,
  "metadata": {"order_id": 1001},
  "timestamp": 1790850131
}

Verify the signature — PHP

<?php
$raw       = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_TOPAY_SIGNATURE'] ?? '';
$expected  = 'sha256=' . hash_hmac('sha256', $raw, 'whsec_your_webhook_secret');

if (!hash_equals($expected, $signature)) {
    http_response_code(401);
    exit('Invalid signature');
}

$event = json_decode($raw, true);
if ($event['status'] === 'completed') {
    // mark order $event['metadata']['order_id'] as paid (do it idempotently)
}
http_response_code(200);
echo 'OK';

Verify the signature — Node.js

import crypto from 'node:crypto';
import express from 'express';

const app = express();
app.post('/payment/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const expected = 'sha256=' + crypto.createHmac('sha256', process.env.TOPAY_WEBHOOK_SECRET)
    .update(req.body).digest('hex');
  const given = req.get('X-TOPAY-Signature') || '';
  if (given.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
    return res.status(401).send('Invalid signature');
  }
  const event = JSON.parse(req.body);
  if (event.status === 'completed') { /* mark order paid */ }
  res.send('OK');
});

Sandbox

Use your sk_test_ key to create sandbox invoices. On the sandbox checkout page, enter any Transaction ID that starts with TEST (for example TEST12345) and the invoice completes instantly — no SMS and no real money. Webhooks are sent exactly like in live mode, with "mode": "sandbox". Sandbox and live data are completely separate.

Errors & limits

HTTPMeaning
401Missing or invalid API key
402Your ToPay plan has expired
403Merchant account suspended
404Invoice not found (or belongs to the other mode)
422Validation error — see data.errors
429Rate limit (120 requests/minute per key) or monthly plan limit reached

Plugins & SDK

  • WooCommerce — plugins/woocommerce/topay-woocommerce: zip the folder and upload in WordPress → Plugins → Add new.
  • WHMCS — copy plugins/whmcs/modules into your WHMCS root and activate “ToPay” in Payment Gateways.
  • SMM panels (PHP scripts) — plugins/smm-panel contains a drop-in add-funds example. Hosted panels such as Perfect Panel do not allow custom gateways.
  • PHP SDK — sdk/php/ToPay.php, a single file without Composer.

All of these are in the ToPay source repository; ask support if you need a copy.

ToPay Support