PHP code example of fatihsafa / efatura

1. Go to this page and download the library: Download fatihsafa/efatura library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fatihsafa / efatura example snippets


use furkankadioglu\eFatura\InvoiceManager;
$client = new InvoiceManager();

// Production environment
$client->setUsername("XXX")->setPassword("YYY");
// VEYA
$client->setCredentials("XXX", "YYY");

// Test Environment
$client->setDebugMode(true)->setTestCredentials();

$client->getCredentials();

$client->connect();

// Tüm faturaları listele
$client->getInvoicesFromAPI("01/01/2020", "08/02/2020");

$fatura_detaylari  = [
"belgeNumarasi"  =>  "", // Zorunlu değil
"faturaTarihi"  =>  "08/02/2020",
"saat"  =>  "09:07:48",
"paraBirimi"  =>  "TRY",
"dovzTLkur"  =>  "0",
"faturaTipi"  =>  "SATIS",
"vknTckn"  =>  "11111111111",
"aliciUnvan"  =>  "FURKAN KADIOGLU",
"aliciAdi"  =>  "FURKAN",
"aliciSoyadi"  =>  "KADIOGLU",
"binaAdi"  =>  "", // Zorunlu değil
"binaNo"  =>  "", // Zorunlu değil
"kapiNo"  =>  "", // Zorunlu değil
"kasabaKoy"  =>  "", // Zorunlu değil
"vergiDairesi"  =>  "MALTEPE",
"ulke"  =>  "Türkiye",
"bulvarcaddesokak"  =>  "DENEME SK. DENEME MAH.",
"mahalleSemtIlce"  =>  "", // Zorunlu değil
"sehir"  =>  " ",
"postaKodu"  =>  "", // Zorunlu değil
"tel"  =>  "", // Zorunlu değil
"fax"  =>  "", // Zorunlu değil
"eposta"  =>  "", // Zorunlu değil
"websitesi"  =>  "", // Zorunlu değil
"iadeTable"  => [], // Zorunlu değil
"ozelMatrahTutari"  =>  "0", // Zorunlu değil
"ozelMatrahOrani"  =>  0, // Zorunlu değil
"ozelMatrahVergiTutari"  =>  "0", // Zorunlu değil
"vergiCesidi"  =>  " ", // Zorunlu değil
"malHizmetTable"  => [],
"tip"  =>  "İskonto",
"matrah"  =>  100,
"malhizmetToplamTutari"  =>  100,
"toplamIskonto"  =>  "0",
"hesaplanankdv"  =>  18,
"vergilerToplami"  =>  18,
"vergilerDahilToplamTutar"  =>  118,
"odenecekTutar"  =>  118,
"not"  =>  "xxx", // Zorunlu değil
"siparisNumarasi"  =>  "", // Zorunlu değil
"siparisTarihi"  =>  "", // Zorunlu değil
"irsaliyeNumarasi"  =>  "", // Zorunlu değil
"irsaliyeTarihi"  =>  "", // Zorunlu değil
"fisNo"  =>  "", // Zorunlu değil
"fisTarihi"  =>  "", // Zorunlu değil
"fisSaati"  =>  " ", // Zorunlu değil
"fisTipi"  =>  " ", // Zorunlu değil
"zRaporNo"  =>  "", // Zorunlu değil
"okcSeriNo"  =>  "" // Zorunlu değil
];

$fatura_detaylari["malHizmetTable"][] = [
"malHizmet"  =>  "Yazılım Geliştirme",
"miktar"  =>  28,
"birim"  =>  "DAY",
"birimFiyat"  =>  "3",
"fiyat"  =>  "84",
"iskontoArttm"  =>  "İskonto",
"iskontoOrani"  =>  0,
"iskontoTutari"  =>  "0",
"iskontoNedeni"  =>  "",
"malHizmetTutari"  =>  "99",
"kdvOrani"  =>  18,
"kdvTutari"  =>  "15.12",
"vergininKdvTutari"  =>  "0"
];

use furkankadioglu\eFatura\Invoice;
$inv  =  new Invoice();
$inv->mapWithTurkishKeys($fatura_detaylari); // Key yapısı türkçe 🇹🇷
// VEYA
$inv->mapWithEnglishKeys($invoice_details); // Key yapısı ingilizce 🇺🇸

$client->setInvoice($inv);

$client->createDraftBasicInvoice();

$userInformations = $client->getUserInformationsData();

// Sadece vknTckn değiştirilemez.
$userInformations = $userInformations->setUnvan("FRKN Yazılım")->setApartmanNo("4");
$apartmanNo = $userInformations->getApartmanNo(); // 4

$userInformations->export(); // Array olarak tüm değişkenleri döndürür.

$client->setUserInformations($userInformations); // Manager'a tanımla.
$client->sendUserInformationsData(); // Sunucuya gönder.

$client->signDraftInvoice();

$client->getInvoiceHTML();

$client->getInvoicePDF();

$client->getDownloadURL();

$client->cancelInvoice();

$client->sendSMSVerification($telefon); // Operasyon id döndürür.

$client->verifySMSCode($kod, $operasyonId);

$client->getCompanyInfo($TCKimlikNoVeyaVergiNo);

$client->logOutFromAPI();

$oldInvoice = new Invoice();
$oldInvoice->setUuid("e8277cfa-4ac9-11ea-a5b5-acde48001122");
$client->setInvoice($oldInvoice)->getInvoiceFromAPI();
// {"faturaUuid":"8a4423bc-4aca-11ea-8c30-acde48001122","faturaTarihi":"09\/02\/2020"...

$client->setDebugMode(true) // Test urlsine geçtik 
->setTestCredentials() // Test bilgilerini aldık
->connect() // Bilgilerle birlikte sunucuya bağlanıp token aldık.
->setInvoice($inv) // Faturamızı sınıfa tanımladık (Invoice sınıfı kullanılmalı)
->createDraftBasicInvoice() // Taslak faturamızı oluşturduk
->getDownloadURL(); // İndirme adresini aldık

// https://earsivportaltest.efatura.gov.tr/earsiv-services/download?token=b8b6c261c511a9b2757279c0111b538a2f02d98ae2df6205448d002687cab8cf74ce04d187bf0c6ce839dee40a6a8aad003aa6d5946ba02a0942ceb10bde327f&ettn=85933f42-4ab1-11ea-922e-acde48001122&belgeTip=FATURA&onayDurumu=Onaylandı&cmd=downloadResource

use furkankadioglu\eFatura\Models\Country;
use furkankadioglu\eFatura\Models\CurrencyType;
use furkankadioglu\eFatura\Models\InvoiceType;
use furkankadioglu\eFatura\Models\UnitType;

$gunBirim = UnitType::GUN; // DAY
$turkLirasi = CurrencyType::TURK_LIRASI; // TRY
$satisFaturasi = InvoiceType::SATIS; // SATIŞ
$gurcistanUlkesi = Country::GURCISTAN; // Gürcistan

use furkankadioglu\eFatura\Invoice;
$inv  =  new Invoice();

$invoice_details = [
    "uuid" => $uuid,
    "documentNumber" => $documentNumber,
    "date" => $date,
    "time" => $time,
    "currency" => $currency,
    "currencyRate" => $currencyRate,
    "invoiceType" => $invoiceType,
    "taxOrIdentityNumber" => $taxOrIdentityNumber,
    "invoiceAcceptorTitle" => $invoiceAcceptorTitle,
    "invoiceAcceptorName" => $invoiceAcceptorName,
    "invoiceAcceptorLastName" => $invoiceAcceptorLastName,
    "buildingName" => $buildingName,
    "buildingNumber" => $buildingNumber,
    "doorNumber" => $doorNumber,
    "town" => $town,
    "taxAdministration" => $taxAdministration,
    "country" => $country,
    "avenueStreet" => $avenueStreet,
    "district" => $district,
    "city" => $city,
    "postNumber" => $postNumber,
    "telephoneNumber" => $telephoneNumber,
    "faxNumber" => $faxNumber,
    "email" => $email,
    "website" => $website,
    "refundTable" => $refundTable,
    "specialBaseAmount" => $specialBaseAmount,
    "specialBasePercent" => $specialBasePercent,
    "specialBaseTaxAmount" => $specialBaseTaxAmount,
    "taxType" => $taxType,
    "itemOrServiceList" => $itemOrServiceList,
    "type" => $type,
    "base" => $base,
    "itemOrServiceTotalPrice" => $itemOrServiceTotalPrice,
    "totalDiscount" => $totalDiscount,
    "calculatedVAT" => $calculatedVAT,
    "taxTotalPrice" => $taxTotalPrice,
    "

$inv->setUuid("Buraya kendi fatura idniz") 
->setCountry("Türkiye")
->getCurrencyRate(); // TRY

    $inv = new Invoice($data); // data arrayinden keylere göre tüm verileri alır.
    $inv->export(); // tüm verileri çıkartır.