Pientegra API
Integration Guide

Money Format

Tutarlar minor unit olarak amount alanında taşınır; float kullanılmaz.

Pientegra para tutarlarını amount alanında minor unit olarak taşır. 1 TRY = 100 kuruş. API seviyesinde float kabul edilmez; finansal hesaplamalarda binary floating point rounding hatası kabul edilebilir değildir.

100.00 TRY  -> 10000
2500.50 TRY -> 250050

Wire format

Request tarafında amount number veya string olarak gönderilebilir. Response tarafında değer BigInt-safe olması için string döner.

Request
{
  "amount": "250050",
  "currency": "TRY"
}
Response
{
  "amount": "250050",
  "currency": "TRY"
}

currency ISO 4217 alpha-3 formatındadır. Bugün aktif currency TRY'dir; field generic tutulur.

Conversion

Amount input'unuz decimal string ise önce parse edip minor unit'e çevirin. Float ile hesap yapmak yerine decimal parser kullanmak daha doğrudur.

Decimal string -> kuruş
function tryToKurus(input: string): string {
  const normalized = input.trim().replace(',', '.');
  const match = normalized.match(/^(\d+)(?:\.(\d{1,2}))?$/);
  if (!match) throw new Error('invalid amount');

  const lira = BigInt(match[1]);
  const fraction = (match[2] ?? '').padEnd(2, '0');
  return (lira * 100n + BigInt(fraction)).toString();
}

tryToKurus('2500.50'); // "250050"
tryToKurus('25');      // "2500"

Display için string'i BigInt olarak okuyup formatlayın.

kuruş -> display
function formatKurus(amount: string, currency = 'TRY'): string {
  const value = BigInt(amount);
  const major = value / 100n;
  const minor = value % 100n;

  return new Intl.NumberFormat('tr-TR', {
    style: 'currency',
    currency,
    minimumFractionDigits: 2,
  }).format(Number(major) + Number(minor) / 100);
}

Common mistakes

Do not use float arithmetic
const amount = 25.10 * 100; // 2509.9999999999995 olabilir
Prefer decimal parsing
const amount = tryToKurus('25.10'); // "2510"
Do not rely on JSON number for very large values
JSON.parse('{"amount":9999999999999999}'); // precision kaybı
Use string
JSON.parse('{"amount":"9999999999999999"}');

On this page