JSPM

paychat-sdk

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q26357F
  • License MIT

Official PAYchat Partner API SDK for USDT payments via Telegram

Package Exports

  • paychat-sdk

Readme

PAYchat SDK

Official Node.js SDK for PAYchat Partner API - Accept USDT payments via Telegram.

npm version License: MIT

Features

  • 💳 Create Payment Links - Generate USDT payment links instantly
  • 💸 Send Withdrawals - Transfer USDT to any Telegram user
  • 🔔 Webhooks - Real-time payment notifications
  • 📊 Analytics - Track transactions and revenue
  • 🔒 Secure - HMAC-SHA256 webhook verification
  • 📝 TypeScript - Full type definitions included

Installation

npm install paychat-sdk

Quick Start

import PAYchatClient from 'paychat-sdk';

// Initialize client
const client = new PAYchatClient('pk_your_api_key');

// Create a payment link
const payment = await client.createPayment({
  amount: 10,
  description: 'Premium Subscription'
});

console.log(payment.payment.payment_url);
// → https://t.me/paychat_aibot?start=abc123

Usage Examples

Create Payment

const payment = await client.createPayment({
  amount: 25.50,
  description: 'Product Purchase',
  metadata: { orderId: '12345' },
  idempotencyKey: 'unique-order-12345'
});

// Share this URL with your customer
const paymentUrl = payment.payment.payment_url;

Check Payment Status

const status = await client.getPayment('abc123');

if (status.payment.status === 'completed') {
  console.log(`Paid by: ${status.payment.payer.telegram_id}`);
  console.log(`Net amount: ${status.payment.net_amount} USDT`);
}

Send USDT to User

const withdrawal = await client.createWithdrawal({
  telegramId: '123456789',
  amount: 5.00,
  memo: 'Cashback reward'
});

console.log(`Sent ${withdrawal.withdrawal.net_amount} USDT`);

Check Balance

const balance = await client.getBalance();
console.log(`Available: ${balance.balance.available} USDT`);

Get Transaction History

const transactions = await client.getTransactions({
  type: 'payment',
  limit: 20
});

transactions.transactions.forEach(tx => {
  console.log(`${tx.type}: ${tx.amount} USDT`);
});

Webhook Verification

Verify incoming webhooks to ensure they're from PAYchat:

import express from 'express';
import { PAYchatClient } from 'paychat-sdk';

const app = express();
app.use(express.json());

app.post('/webhook', (req, res) => {
  const signature = req.headers['x-paychat-signature'];
  const payload = req.body;
  
  const isValid = PAYchatClient.verifyWebhook(
    payload,
    signature,
    'sk_your_secret_key'
  );
  
  if (!isValid) {
    return res.status(401).json({ error: 'Invalid signature' });
  }
  
  // Process webhook
  if (payload.event === 'payment.completed') {
    console.log('Payment received:', payload.data);
  }
  
  res.json({ received: true });
});

Webhook Events

Event Description
payment.completed Payment has been completed
withdraw.completed Withdrawal has been processed
test Test webhook

Payment Completed Payload

{
  "event": "payment.completed",
  "data": {
    "payment_id": "abc123",
    "amount": 10.00,
    "fee": 0.10,
    "net_amount": 9.90,
    "payer": {
      "telegram_id": "123456789"
    }
  },
  "created_at": "2025-01-07T12:00:00Z"
}

API Reference

Constructor

new PAYchatClient(apiKey, options?)
Option Type Default Description
baseUrl string https://paychat.me API base URL
timeout number 10000 Request timeout (ms)

Methods

Method Description
createPayment(params) Create a payment link
getPayment(id) Get payment status
createWithdrawal(params) Send USDT to a user
getBalance() Get partner balance
getDepositAddress() Get deposit address
getTransactions(params?) Get transaction history
getDashboard() Get dashboard summary
getStats(period?) Get detailed statistics
getCredits() Get credit usage
getPlans() Get available plans
updateWebhook(url) Set webhook URL
testWebhook() Send test webhook
regenerateKeys() Regenerate API keys

Static Methods

Method Description
PAYchatClient.verifyWebhook(payload, signature, secretKey) Verify webhook signature (sync, Node.js)
PAYchatClient.verifyWebhookAsync(payload, signature, secretKey) Verify webhook signature (async, browser)

Error Handling

try {
  const payment = await client.createPayment({ amount: 10 });
} catch (error) {
  console.error('Error:', error.message);
  console.error('Code:', error.code);    // e.g., 'INSUFFICIENT_BALANCE'
  console.error('Status:', error.status); // e.g., 400
}

Error Codes

Code Description
INVALID_API_KEY Invalid or missing API key
INVALID_AMOUNT Invalid payment amount
INSUFFICIENT_BALANCE Not enough balance
PAYMENT_NOT_FOUND Payment not found
RATE_LIMIT_EXCEEDED Too many requests

Rate Limits

Plan Limit
Free / Basic 100 requests/min
Pro 500 requests/min

Support

License

MIT © PAYchat