2017 © Pedro Peláez
 

library w-firma-api

wFirma.pl API

image

webit/w-firma-api

wFirma.pl API

  • Tuesday, February 13, 2018
  • by dbojdo
  • Repository
  • 2 Watchers
  • 2 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 20 % Grown

The README.md

wFirma API

High level implementation of wFirma API. Provides object oriented SDK to operate on the most of wFirma modules., (*1)

Installation

Use composer:, (*2)

composer require webit/w-firma-api

For PHP 5.4 and 7.0 use ^1.0 version., (*3)

Usage

The current version of the package provides full support for the following modules:, (*4)

Configure Annotation Registry

This is not needed if you use AnnotationRegistry 2.0., (*5)

<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = include __DIR__.'/vendor/autoload.php'; // composer's autoload.php
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

Authentication

The library supports only BasicAuth., (*6)

BasicAuth

<?php
use Webit\WFirmaSDK\Auth\BasicAuth;

$auth = new BasicAuth('your-user-name', 'your-password', $companyId = 1123); // $companyId is optional

ApiFactory

In order to create API for given module use ModuleApiFactory., (*7)

<?php

use Webit\WFirmaSDK\Entity\ModuleApiFactory;
use Webit\WFirmaSDK\Entity\EntityApiFactory;

$entityApiFactory = new EntityApiFactory();
$entityApi = $entityApiFactory->create($auth);

$apiFactory = new ModuleApiFactory($entityApi);

Module APIs

Every main module has it's own instance of the API exposing supported methods., (*8)

  • Company Accounts: find, findAll, get, count,
  • Contractors: add, edit, delete, find, findAll, get, count
  • Declaration Countries: find, findAll, get, count
  • Invoice Deliveries: add, delete, find, findAll, get, count
  • Invoice Descriptions: find, findAll, get, count
  • Invoices: add, edit, delete, find, findAll, get, count, fiscalise, unfiscalise, download, send
  • Notes: add, edit, delete, find, findAll, get, count
  • Series: add, edit, delete, find, findAll, get, count
  • Tags: add, edit, delete, find, findAll, get, count
  • TranslationLanguages: find, findAll, get, count
  • VatCodes: find, findAll, get, count

Find / FindAll / Count APIs

APIs exposing find / findAll / count method takes and optional Parameters argument., (*9)

<?php
use Webit\WFirmaSDK\Entity\Parameters\Parameters;
use Webit\WFirmaSDK\Entity\Parameters\Order;
use Webit\WFirmaSDK\Entity\Parameters\Pagination;
use Webit\WFirmaSDK\Entity\Parameters\Fields;

$parameters = Parameters::findParameters(
    null, // filtering by conditions is not supported yet
    Order::ascending("name")->thenDescending("created"), // optional - ordering
    Pagination::create(20, 2), // optional - limit, page no
    Fields::fromArray(array("id", "name")) // optional - subset of fields to select
);

$seriesApi = $apiFactory->seriesApi();

$series = $seriesApi->find($parameters); // returns array of 20 Series (page 2)

// returns EntityIterator, allows to iterate over all the matching Series loaded in batches of 20
$series = $seriesApi->findAll($parameters);
/**
* @var int $i
* @var \Webit\WFirmaSDK\Series\Series $seriesItem */
foreach ($series as $i => $seriesItem) {
    // do some stuff on ALL the matching elements
}

$seriesCount = $seriesApi->count($parameters); // return number of matching series

InvoicesApi

<?php
use Webit\WFirmaSDK\Contractors\Contractor;
use Webit\WFirmaSDK\Contractors\InvoiceAddress;
use Webit\WFirmaSDK\Invoices\InvoicesContent;
use Webit\WFirmaSDK\Goods\GoodId;

/** @var \Webit\WFirmaSDK\Invoices\InvoicesApi $api */
$api = $apiFactory->invoicesApi();

// add a new invoice
$invoice = \Webit\WFirmaSDK\Invoices\Invoice::forContractor(
    new Contractor(
        'client name',
        'alt name',
        '1234565432', // vat no
        null, // regon
        new InvoiceAddress(
            'ul. Mokra 12',
            '01-006',
            'Warszawa',
            'PL'
        )
    )
);

$invoice->addInvoiceContent(
    InvoicesContent::fromGoodId(
        GoodId::create(123),
        3,
        123.32,
        23
    )
);

$invoice->addInvoiceContent(
    InvoicesContent::fromName(
        'some stuff',
        'szt.',
        3,
        123.32,
        23
    )
);

$invoice = $api->add($invoice);

// get invoice by id
$invoice = $api->get(\Webit\WFirmaSDK\Invoices\InvoiceId::create(123));

// edit the invoice
$invoice->changePayment(
    $invoice->payment()->withPaymentDate(new \DateTime())
);

// do some more edits
$invoice = $api->edit($invoice);

// delete the invoice
$api->delete($invoice->id());

ContractorsApi


<?php use Webit\WFirmaSDK\Contractors\Contractor; /** @var \Webit\WFirmaSDK\Contractors\ContractorsApi $api */ $api = $apiFactory->contractorsApi($auth); // add a new contractor $contractor = new Contractor('my-new-contractor'); $contractor = $api->add($contractor); // edit the contractor $contractor->rename('new name', 'new alt name'); $contractor = $api->edit($contractor); // delete the contractor $api->delete($contractor->id()); // get contractor by id $contractor = $api->get(\Webit\WFirmaSDK\Contractors\ContractorId::create(123));

Further development

Feel free to add any other modules support. Also filtering by Conditions is not supported yet - any help is welcome., (*10)

Tests

cp phpunit.xml.dist phpunit.xml
vim phpunit.xml // edit your username and password

docker-compose run --rm composer
docker-compose run --rm phpunit

The Versions

13/02 2018

dev-master

9999999-dev

wFirma.pl API

  Sources   Download

MIT

The Requires

 

The Development Requires

api sdk wfirma w-firma

13/02 2018
13/02 2018
11/02 2018
27/01 2018

dev-develop

dev-develop

  Sources   Download

MIT

The Requires

 

The Development Requires

api sdk wfirma w-firma