PHP code example of stackin-io / stackin-php-sdk

1. Go to this page and download the library: Download stackin-io/stackin-php-sdk 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/ */

    

stackin-io / stackin-php-sdk example snippets


// More than one unit — the note's line is 2 x 120.00 = 240.00
new Product(description: 'Teclado', quantity: 2.0, unitPrice: 120.00, unit: 'UN');

// Legacy: amount alone still means the line's gross total
new Product(description: 'Servico', amount: 150.00, quantity: 3.0);

use Stackin\Address;
use Stackin\Br\Product;
use Stackin\DocumentType;
use Stackin\Invoice;

$invoice = new Invoice(apiKey: 'COMPANY_API_KEY');

$result = $invoice->issue(
    DocumentType::NFE,
    'Buyer Company Ltd',
    '11222333000181',
    [
        new Product(
            description: 'Rosa Holambra Vermelha',
            unitPrice: 112.44,
            ncm: '06031100',
            cfop: '5102',
        ),
    ],
    new Address(
        street: 'Rua das Palmeiras',
        number: '100',
        neighborhood: 'Centro',
        city: 'Florianopolis',
        state: 'SC',
        zipCode: '88010000',
        cityCode: '4205407',
    ),
);

$status = $invoice->consult('ACCESS_KEY...', DocumentType::NFSE);
$invoice->cancel('ACCESS_KEY...', DocumentType::NFSE, 'Typo');

// The authorizer's PDF, as raw bytes. NFS-e only; the XML stays the
// legally valid document, and a 502 here means the authorizer is down.
file_put_contents(
    'nota.pdf',
    $invoice->pdf('ACCESS_KEY...', DocumentType::NFSE),
);

$key = bin2hex(random_bytes(16));

$result = $invoice->issue(
    DocumentType::NFSE,
    'Maria Silva',
    '12345678909',
    [new Product(description: 'Consultoria', unitPrice: 1500.00)],
    idempotencyKey: $key,
);

$result = $invoice->correct(
    '35240912345678000199550010000000011000000017',
    DocumentType::NFE,
    'Transportadora corrigida para Rapido Ltda',
);

$result = $invoice->invalidate(
    '1',
    10,
    12,
    'Numeracao reservada e nao utilizada por falha no ERP',
);

use Stackin\\Manifestation;

$page = $client->received(limit: 20);
echo $page['total'];

$client->manifest($accessKey, Manifestation::CIENCIA);
$client->manifest(
    $accessKey,
    Manifestation::OPERACAO_NAO_REALIZADA,
    'Mercadoria nunca chegou ao endereco',
);

use Stackin\FiscalReference;
use Stackin\Taxpayer;

$ref = new FiscalReference(apiKey: '...');        // country 'BR' by default

$ref->ncm->get('84716052');                       // one code
$ref->ncm->search('teclado', limit: 5);           // a page of matches
$ref->cfop->get('5102');
$ref->kinds();                                    // what this country has
$ref->kind('ibs_cbs_class')->get('000001');       // any kind, named or not
$ref->search('teclado');                          // every kind at once

(new Taxpayer(apiKey: '...'))->get('00000000000191');