fatura

repository·master·Indexed 20 days ago

https://github.com/f/fatura

A Node.js library (v0.2.1) for creating, signing, and managing e-Arşiv invoices through the official GİB (Gelir İdaresi Başkanlığı) portal. It provides a FaturaClient to handle authentication, draft invoice creation, digital signing, SMS verification, and retrieval of invoice HTML or download URLs. Requires Node.js 18 or higher.

Tokens
11.3K
Snippets
50
Records
56
Agent score
69%

What's inside fatura

  1. How the SMS verification flow works

    master

    The SMS verification process follows a two-step pattern involving an Operation ID (OID):

    1. Initiation: Call sendSignSMSCode(token, phone). This triggers the SMS and returns an OID.
    2. Verification: Call verifySignSMSCode(token, smsCode, operationId), passing the OID received in the first step to validate the user's input.
  2. Sign a draft invoice

    master

    ☢️ WARNING: Signing a draft invoice creates a legally binding financial transaction. Use with caution.

    To sign an invoice, you must first use findInvoice(token, draftInvoice) to retrieve the necessary signing information (such as the document number) from the draft list. The object returned by findInvoice should be passed to signDraftInvoice.

    // 1. Find the invoice to get signing details
    const invoiceToSign = await client.findInvoice(token, draftInvoice);
    
    // 2. Sign the invoice
    await client.signDraftInvoice(token, invoiceToSign);
  3. Choose between PROD and TEST environments

    master

    When initializing a client with createFaturaClient, you must explicitly specify the environment to prevent mixing test data with live production data. The library supports two environments:

    • PROD: Connects to https://earsivportal.efatura.gov.tr (Live environment)
    • TEST: Connects to https://earsivportaltest.efatura.gov.tr (Testing environment)
    import { createFaturaClient } from "fatura";
    
    const prodClient = createFaturaClient("PROD");
    const testClient = createFaturaClient("TEST");
  4. Run the website development server

    master

    To start the local development environment for the website, run the development command using your preferred package manager. Once running, the application will be accessible at http://localhost:3000.

    npm run dev
    # or
    yarn dev
    # or
    pnpm dev
    # or
    bun dev
  5. Initialize the Fatura client

    master

    After installation, import createFaturaClient from fatura to initialize the client. You must provide an environment string (e.g., "TEST" or "PROD") to the constructor.

    Warning: Do not initiate financial transactions in a PROD environment without proper validation; use the TEST environment for initial verification.

    import { createFaturaClient } from "fatura";
    
    const client = createFaturaClient("TEST");
  6. Understand the GibApiMessage format

    master

    Messages returned from the GİB API can arrive in two different formats depending on the endpoint:

    1. Object format: { type: string; text: string } (used by most endpoints).
    2. String format: A plain string like "Genel Sistem Hatası: ..." (used by some dispatch errors).

    When processing messages in an ApiResponse, ensure your logic can handle both types.

    export type GibApiMessage = string | { type: string; text: string };