Skip to content

Subscribe API Hujjatlari

Payme Subscribe API uchun to'liq havola - karta tokenizatsiyasi va chek boshqaruvi.

PaymeSubscribe Klass

Konstruktor

typescript
new PaymeSubscribe(config: PaymeSubscribeConfig, mode: SubscribeMode)

Parametrlar:

ParametrTurMajburiyTavsif
config.merchantIdstringPayme Business dan savdochi ID
config.passwordstring⚠️ Faqat serverSubscribe API uchun parol
config.baseURLstringAPI asosiy URL (standart: ishlab chiqarish)
config.timeoutnumberSo'rov vaqti tugashi ms da (standart: 60000)
mode'client' | 'server'Operatsiya rejimi

Rejimlar:

  • client: Karta tokenizatsiyasi uchun (frontend/mobil)
  • server: Karta boshqaruvi va cheklar uchun (backend)

Misol:

typescript
import { PaymeSubscribe } from '@joyida/payme';

// Klient tomon rejim
const subscribeClient = new PaymeSubscribe({
  merchantId: 'your_merchant_id'
}, 'client');

// Server tomon rejim
const subscribeServer = new PaymeSubscribe({
  merchantId: 'your_merchant_id',
  password: 'your_password'
}, 'server');

Karta Metodlari

cardsCreate (Klient tomon)

Yangi karta tokeni yaratadi.

typescript
cardsCreate(params: CardsCreateParams): Promise<CardsCreateResult>

Parametrlar:

typescript
interface CardsCreateParams {
  card: {
    number: string;  // Karta raqami (13-19 raqam)
    expire: string;  // Amal qilish muddati (MMYY formati)
  };
  account?: Record<string, unknown>;  // Ixtiyoriy akkaunt ma'lumotlari
  save?: boolean;                     // Karta kelajakda foydalanish uchun saqlansin
  customer?: string;                  // Mijoz identifikatori
}

Qaytaradi:

typescript
interface CardsCreateResult {
  card: {
    number: string;     // Maskalangan karta raqami
    expire: string;     // Amal qilish muddati
    token: string;      // Karta tokenni
    recurrent: boolean; // Takroriy to'lovlarni qo'llab-quvvatlaydi
    verify: boolean;    // Tasdiqlash statusi (dastlab false)
  };
}

Misol:

typescript
const result = await subscribeClient.cardsCreate({
  card: {
    number: '8600069195406311',
    expire: '0399'
  },
  save: true,
  account: { user_id: '12345' }
});

console.log('Token:', result.card.token);
console.log('Tasdiqlangan:', result.card.verify); // false

cardsGetVerifyCode (Klient tomon)

Karta uchun SMS tasdiqlash kodi so'raydi.

typescript
cardsGetVerifyCode(
  params: CardsGetVerifyCodeParams
): Promise<CardsGetVerifyCodeResult>

Parametrlar:

typescript
interface CardsGetVerifyCodeParams {
  token: string; // cardsCreate dan olingan karta tokenni
}

Qaytaradi:

typescript
interface CardsGetVerifyCodeResult {
  sent: boolean;  // SMS yuborilish statusi
  phone: string;  // Maskalangan telefon raqami (masalan, "99890***1234")
  wait: number;   // Keyingi so'rovgacha kutish vaqti (ms)
}

Misol:

typescript
const result = await subscribeClient.cardsGetVerifyCode({
  token: 'card_token_here'
});

console.log(`SMS yuborildi ${result.phone}`);
console.log(`${result.wait}ms kutib qayta urinish`);

cardsVerify (Klient tomon)

SMS kod bilan kartani tasdiqlaydi.

typescript
cardsVerify(params: CardsVerifyParams): Promise<CardsVerifyResult>

Parametrlar:

typescript
interface CardsVerifyParams {
  token: string; // Karta tokenni
  code: string;  // SMS tasdiqlash kodi
}

Qaytaradi:

typescript
interface CardsVerifyResult {
  card: {
    number: string;     // Maskalangan karta raqami
    expire: string;     // Amal qilish muddati
    token: string;      // Karta tokenni (xuddi shu)
    recurrent: boolean; // Takroriy to'lovlarni qo'llab-quvvatlaydi
    verify: boolean;    // Tasdiqlash statusi (muvaffaqiyatli bo'lsa true)
  };
}

Misol:

typescript
const result = await subscribeClient.cardsVerify({
  token: 'card_token_here',
  code: '666666'
});

if (result.card.verify) {
  console.log('✅ Karta tasdiqlandi!');
}

cardsCheck (Server tomon)

Karta tokenni holatini tekshiradi.

typescript
cardsCheck(params: CardsCheckParams): Promise<CardsCheckResult>

Parametrlar:

typescript
interface CardsCheckParams {
  token: string; // Tekshirish kerak bo'lgan karta tokenni
}

Qaytaradi:

typescript
interface CardsCheckResult {
  card: {
    number: string;     // Maskalangan karta raqami
    expire: string;     // Amal qilish muddati
    token: string;      // Karta tokenni
    recurrent: boolean; // Takroriy to'lovlarni qo'llab-quvvatlaydi
    verify: boolean;    // Tasdiqlash statusi
  };
}

Misol:

typescript
const result = await subscribeServer.cardsCheck({
  token: 'card_token_here'
});

console.log('Tasdiqlangan:', result.card.verify);
console.log('Takroriy:', result.card.recurrent);

cardsRemove (Server tomon)

Karta tokenni o'chiradi.

typescript
cardsRemove(params: CardsRemoveParams): Promise<CardsRemoveResult>

Parametrlar:

typescript
interface CardsRemoveParams {
  token: string; // O'chirish kerak bo'lgan karta tokenni
}

Qaytaradi:

typescript
interface CardsRemoveResult {
  success: boolean; // O'chirish statusi
}

Misol:

typescript
const result = await subscribeServer.cardsRemove({
  token: 'card_token_here'
});

if (result.success) {
  console.log('✅ Karta tokenni o\'chirildi');
}

Chek Metodlari

receiptsCreate (Server tomon)

Yangi chek yaratadi.

typescript
receiptsCreate(
  params: ReceiptsCreateParams
): Promise<ReceiptsCreateResult>

Parametrlar:

typescript
interface ReceiptsCreateParams {
  amount: number;                    // Tiyinda suma
  account: Record<string, unknown>;  // Akkaunt identifikatori
  description?: string;              // Chek tavsifi
  detail?: ReceiptDetail;            // Fiskal tafsilotlar
}

interface ReceiptDetail {
  receipt_type?: number;
  shipping?: {
    title: string;
    price: number;
  };
  items: ReceiptItem[];
}

interface ReceiptItem {
  title: string;        // Tovar nomi
  price: number;        // Tovar narxi tiyinda
  count: number;        // Soni
  code: string;         // IKPU kodi
  units?: number;       // Birlik turi
  vat_percent: number;  // QQS foizi
  package_code: string; // Paket kodi
}

Qaytaradi:

typescript
interface ReceiptsCreateResult {
  receipt: {
    _id: string;        // Chek ID
    create_time: number;
    pay_time: number;
    cancel_time: number;
    state: number;      // 0 (to'lov kutmoqda)
  };
}

Misol:

typescript
const result = await subscribeServer.receiptsCreate({
  amount: 500000,
  account: { order_id: '123' },
  description: 'Buyurtma #123 uchun to\'lov',
  detail: {
    receipt_type: 0,
    items: [
      {
        title: 'Tovar Nomi',
        price: 500000,
        count: 1,
        code: '00702001001000001',
        vat_percent: 15,
        package_code: '123456'
      }
    ]
  }
});

console.log('Chek ID:', result.receipt._id);

receiptsPay (Server tomon)

Karta tokenni bilan chek to'laydi.

typescript
receiptsPay(params: ReceiptsPayParams): Promise<ReceiptsPayResult>

Parametrlar:

typescript
interface ReceiptsPayParams {
  id: string;    // Chek ID
  token: string; // Karta tokenni
  payer?: {      // Ixtiyoriy to'lovchi ma'lumotlari
    phone: string;
  };
}

Qaytaradi:

typescript
interface ReceiptsPayResult {
  receipt: {
    _id: string;
    state: number; // 1 (to'langan)
  };
}

Misol:

typescript
const result = await subscribeServer.receiptsPay({
  id: 'receipt_id_here',
  token: 'card_token_here',
  payer: {
    phone: '998901234567'
  }
});

if (result.receipt.state === 1) {
  console.log('✅ To\'lov muvaffaqiyatli!');
}

receiptsSend (Server tomon)

SMS orqali chek invoice yuboradi.

typescript
receiptsSend(params: ReceiptsSendParams): Promise<ReceiptsSendResult>

Parametrlar:

typescript
interface ReceiptsSendParams {
  id: string;    // Chek ID
  phone: string; // Telefon raqami (998XXXXXXXXX)
}

Qaytaradi:

typescript
interface ReceiptsSendResult {
  success: boolean;
}

Misol:

typescript
const result = await subscribeServer.receiptsSend({
  id: 'receipt_id_here',
  phone: '998901234567'
});

if (result.success) {
  console.log('✅ SMS yuborildi');
}

receiptsCancel (Server tomon)

Chekni bekor qiladi.

typescript
receiptsCancel(
  params: ReceiptsCancelParams
): Promise<ReceiptsCancelResult>

Parametrlar:

typescript
interface ReceiptsCancelParams {
  id: string; // Bekor qilish kerak bo'lgan chek ID
}

Qaytaradi:

typescript
interface ReceiptsCancelResult {
  receipt: {
    _id: string;
    cancel_time: number;
    state: number; // 2 (bekor qilingan) yoki 3 (to'lovdan keyin bekor qilingan)
  };
}

Misol:

typescript
const result = await subscribeServer.receiptsCancel({
  id: 'receipt_id_here'
});

console.log('Bekor qilish vaqti:', result.receipt.cancel_time);
console.log('Holat:', result.receipt.state);

receiptsCheck (Server tomon)

Chek holatini tekshiradi.

typescript
receiptsCheck(
  params: ReceiptsCheckParams
): Promise<ReceiptsCheckResult>

Parametrlar:

typescript
interface ReceiptsCheckParams {
  id: string; // Tekshirish kerak bo'lgan chek ID
}

Qaytaradi:

typescript
interface ReceiptsCheckResult {
  state: number; // 0= kutmoqda, 1= to'langan, 2= bekor qilingan, 3= to'lovdan keyin bekor qilingan
}

Misol:

typescript
const result = await subscribeServer.receiptsCheck({
  id: 'receipt_id_here'
});

console.log('Chek holati:', result.state);

receiptsGet (Server tomon)

Chek tafsilotlarini oladi.

typescript
receiptsGet(params: ReceiptsGetParams): Promise<ReceiptsGetResult>

Parametrlar:

typescript
interface ReceiptsGetParams {
  id: string; // Olish kerak bo'lgan chek ID
}

Qaytaradi:

typescript
interface ReceiptsGetResult {
  receipt: Receipt; // To'liq chek obyekti
}

interface Receipt {
  _id: string;
  create_time: number;
  pay_time: number;
  cancel_time: number;
  state: number;
  type: number;
  external: boolean;
  operation: number;
  category: string | null;
  error: string | null;
  description: string;
  detail: ReceiptDetail | null;
  amount: number;
  currency: number;
  commission: number;
  account: Record<string, unknown>[];
  card: CardInfo | null;
  merchant: {
    _id: string;
    name: string;
    organization: string;
    address: string;
    epos: {
      merchantId: string;
      terminalId: string;
    };
    date: number;
    logo: string | null;
    type: string;
    terms: string | null;
  };
  meta: {
    source: string;
    owner: string;
  };
  processing_id: number | null;
}

Misol:

typescript
const result = await subscribeServer.receiptsGet({
  id: 'receipt_id_here'
});

console.log('Suma:', result.receipt.amount);
console.log('Holat:', result.receipt.state);
console.log('Karta:', result.receipt.card?.number);

receiptsGetAll (Server tomon)

Sana oralig'ida barcha cheklarni oladi.

typescript
receiptsGetAll(
  params: ReceiptsGetAllParams
): Promise<ReceiptsGetAllResult>

Parametrlar:

typescript
interface ReceiptsGetAllParams {
  from: number;    // Davr boshhi (Unix timestamp ms da)
  to: number;      // Davr oxiri (Unix timestamp ms da)
  offset?: number; // Sahifalash offset (standart: 0)
  limit?: number;  // Natijalar limit (standart: 50)
}

Qaytaradi:

typescript
interface ReceiptsGetAllResult {
  receipts: Receipt[]; // Cheklar massivi
}

Misol:

typescript
const result = await subscribeServer.receiptsGetAll({
  from: Date.now() - 86400000, // 24 soat oldin
  to: Date.now(),
  limit: 50
});

console.log('Topildi:', result.receipts.length);
result.receipts.forEach(receipt => {
  console.log(`${receipt._id}: ${receipt.state} - ${receipt.amount}`);
});

Konstantalar

Chek Holatlari

typescript
enum RECEIPT_STATES {
  WAITING = 0,              // To'lov kutmoqda
  PAID = 1,                 // To'langan
  CANCELLED = 2,            // Bekor qilingan
  CANCELLED_AFTER_PAY = 3   // To'lovdan keyin bekor qilingan
}

Foydalanish:

typescript
import { RECEIPT_STATES } from '@joyida/payme';

if (receipt.state === RECEIPT_STATES.PAID) {
  console.log('Chek to\'langan');
}

Xato Ishlash

Barcha Subscribe API xatoliklar tavsirli xabarlarga xaritalangan. To'liq xato kodi ro'yxati uchun rasmiy Payme hujjatlarini tekshiring.

Umumiy xatolar:

typescript
import { PaymeError } from '@joyida/payme';

try {
  await subscribeClient.cardsCreate(params);
} catch (error) {
  if (error instanceof PaymeError) {
    console.error('Xato kodi:', error.code);
    console.error('Xabar:', error.message);

    // Muayyan xatolarni ishlash
    if (error.code === -31050) {
      console.error('Noto\'g\'ri karta raqami');
    }
  }
}

Keyingi Qadamlar

MIT Lizenziyasi ostida chiqarilgan.