├── .gitignore ├── tests ├── bootstrap.php ├── Entity │ ├── Series │ │ └── resources │ │ │ ├── series.add.request.xml │ │ │ ├── series.add.response.ok.xml │ │ │ └── series.add.response.error.xml │ ├── Infrastructure │ │ └── Buzz │ │ │ ├── BaseUrlMiddlewareTest.php │ │ │ └── CompanyIdMiddlewareTest.php │ └── AbstractApiTestCase.php ├── Vat │ ├── Repository │ │ ├── VatCodeIdApiMapProviderTest.php │ │ ├── VatCodeIdCachingMapProviderTest.php │ │ ├── VatCodeIdRepositoryTest.php │ │ └── VatCodeIdRepositoryFactoryTest.php │ ├── VatCodesApiIntegrationTest.php │ └── VatCodeSerialisationTest.php ├── Auth │ ├── BasicAuthTest.php │ └── ApiKeysAuthTest.php ├── AbstractTestCase.php ├── TranslationLanguages │ ├── TranslationLanguageSerialisationTest.php │ └── TranslationLanguagesApiIntegrationTest.php ├── Contractors │ └── ContractorSerialisationTest.php ├── DeclarationCountries │ └── DeclarationCountriesApiTest.php ├── AbstractSerialisationTest.php ├── Invoices │ └── InvoiceStubTrait.php ├── Goods │ └── GoodsApiTest.php └── Tags │ └── TagIdsTest.php ├── src ├── Auth │ ├── Auth.php │ ├── ApiKeysAuth.php │ └── BasicAuth.php ├── Invoices │ ├── PaymentMethod.php │ ├── CompanyDetailId.php │ ├── InvoiceContentId.php │ ├── ContractorDetailId.php │ ├── InvoiceId.php │ ├── InvoicePage.php │ ├── TypeOfSale.php │ ├── PriceType.php │ ├── AutoSend.php │ ├── Discount.php │ ├── Correction.php │ ├── PaymentState.php │ ├── Totals.php │ ├── Schema.php │ ├── Disposal.php │ ├── DownloadParameters.php │ ├── SendParameters.php │ ├── Currency.php │ └── Type.php ├── Vat │ ├── Repository │ │ ├── VatCodeIdMapProvider.php │ │ ├── VatCodeIdRepositoryFactory.php │ │ ├── VatCodeIdApiMapProvider.php │ │ ├── VatCodeIdCachingMapProvider.php │ │ └── VatCodeIdRepository.php │ ├── VatContentId.php │ ├── VatMossDetailsId.php │ ├── VatCodeId.php │ ├── Type.php │ ├── Evidence.php │ ├── VatCodePeriod.php │ ├── EvidenceType.php │ ├── VatCodesApi.php │ ├── VatContent.php │ └── ServiceCode.php ├── Entity │ ├── EntityId.php │ ├── Infrastructure │ │ ├── Serialiser │ │ │ ├── Exception │ │ │ │ ├── ApiSerialiserException.php │ │ │ │ ├── UnsupportedModuleOrActionException.php │ │ │ │ ├── SerialisationException.php │ │ │ │ └── DeserialisationException.php │ │ │ ├── ApiSerialiser.php │ │ │ ├── FileResponseSerialiser.php │ │ │ ├── EmptyRequestApiSerialiser.php │ │ │ ├── JMS │ │ │ │ ├── OrderHandler.php │ │ │ │ ├── DateDeserializationListener.php │ │ │ │ ├── SerializerFactory.php │ │ │ │ ├── JmsApiSerialiser.php │ │ │ │ └── RequestResponseSerializationListener.php │ │ │ ├── ApiSerialiserFactory.php │ │ │ ├── FallingBackApiSerialiser.php │ │ │ └── ByModuleAndActionApiSerialiser.php │ │ ├── RequestExecutorFactory.php │ │ ├── RequestExecutor.php │ │ ├── Buzz │ │ │ ├── ApiKeysAuthMiddleware.php │ │ │ ├── BaseUrlMiddleware.php │ │ │ ├── CompanyIdMiddleware.php │ │ │ ├── BuzzRequestExecutorFactory.php │ │ │ ├── BrowserFactory.php │ │ │ └── BuzzRequestExecutor.php │ │ └── ResponseValidator.php │ ├── Entity.php │ ├── Exception │ │ ├── FatalException.php │ │ ├── NotFoundException.php │ │ ├── InputErrorException.php │ │ ├── ActionNotFound.php │ │ ├── ValidationException.php │ │ ├── DeniedScopeRequested.php │ │ ├── AccessDenied.php │ │ ├── ApiCallExecutionException.php │ │ ├── OutOfServiceException.php │ │ ├── AuthException.php │ │ ├── TotalRequestsLimitExceededException.php │ │ ├── CompanyIdRequiredException.php │ │ ├── SnapshotLockException.php │ │ ├── TotalExecutionTimeLimitExceededException.php │ │ ├── AuthFailedLimitWait5MinutesException.php │ │ └── ApiException.php │ ├── AbstractResponse.php │ ├── File.php │ ├── AbstractEnum.php │ ├── ErrorMethod.php │ ├── EntityApiFactory.php │ ├── Parameters │ │ ├── Field.php │ │ ├── Parameter.php │ │ ├── Fields.php │ │ ├── OrderByField.php │ │ ├── Pagination.php │ │ └── Order.php │ ├── DateAwareEntity.php │ ├── AbstractEntity.php │ ├── Status.php │ ├── AbstractEntityId.php │ ├── Error.php │ ├── EntityWrapper.php │ ├── EntityApi.php │ └── Response.php ├── Tags │ ├── TagId.php │ ├── Colour.php │ ├── TagsApi.php │ └── TagIds.php ├── Notes │ ├── NoteId.php │ ├── Note.php │ └── NotesApi.php ├── Goods │ ├── GoodId.php │ ├── PriceType.php │ ├── WarehouseType.php │ ├── Type.php │ ├── Dimensions.php │ ├── GoodsApi.php │ └── Stock.php ├── Series │ ├── SeriesId.php │ ├── ResetMode.php │ ├── TemplateTokens.php │ └── SeriesApi.php ├── Expenses │ └── ExpenseId.php ├── InvoiceDescriptions │ ├── InvoiceDescription.php │ ├── InvoiceDescriptionId.php │ └── InvoiceDescriptionsApi.php ├── Payments │ ├── PaymentId.php │ ├── PaymentMethod.php │ ├── PaymentsApi.php │ └── PaymentAmount.php ├── Contractors │ ├── ContractorId.php │ ├── InvoiceAddress.php │ ├── PaymentSettings.php │ ├── TaxIdType.php │ ├── ContactDetails.php │ ├── ContactAddress.php │ └── ContractorsApi.php ├── CompanyAccounts │ ├── CompanyAccountId.php │ └── CompanyAccountsApi.php ├── InvoiceDeliveries │ ├── InvoiceDeliveryId.php │ ├── Type.php │ ├── InvoiceDelivery.php │ └── InvoiceDeliveriesApi.php ├── PaymentCashboxes │ └── PaymentCashboxId.php ├── DeclarationCountries │ ├── DeclarationCountryId.php │ ├── DeclarationCountriesApi.php │ └── DeclarationCountry.php └── TranslationLanguages │ ├── TranslationLanguageId.php │ ├── TranslationLanguage.php │ └── TranslationLanguagesApi.php ├── docker └── php │ ├── config │ └── php.ini │ └── Dockerfile ├── docker-compose.yml ├── LICENSE ├── phpunit.xml.dist └── composer.json /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | /vendor/ 3 | composer.lock 4 | phpunit.xml 5 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BurlyWood_7522 6 | 7 | 1 8 | normal 9 | yearly 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/DeclarationCountries/DeclarationCountryId.php: -------------------------------------------------------------------------------- 1 | entityApi())); 16 | 17 | $this->assertNotEmpty($provider->getMap()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/ApiSerialiser.php: -------------------------------------------------------------------------------- 1 | status = $status; 20 | } 21 | 22 | /** 23 | * @return Status 24 | */ 25 | public function status() 26 | { 27 | return $this->status; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Goods/Type.php: -------------------------------------------------------------------------------- 1 | content = (string)$content; 16 | } 17 | 18 | /** 19 | * @return string 20 | */ 21 | public function content() 22 | { 23 | return $this->content; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function __toString() 30 | { 31 | return $this->content; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Vat/Type.php: -------------------------------------------------------------------------------- 1 | faker()->userName, 16 | $password = $this->faker()->password, 17 | $companyId = $this->faker()->randomNumber() 18 | ); 19 | 20 | $this->assertEquals($user, $auth->username()); 21 | $this->assertEquals($password, $auth->password()); 22 | $this->assertEquals($companyId, $auth->companyId()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/AbstractEnum.php: -------------------------------------------------------------------------------- 1 | value = (string)$value; 16 | } 17 | 18 | /** 19 | * @param string $value 20 | * @return static 21 | * @internal 22 | */ 23 | final public static function fromString($value) 24 | { 25 | return new static($value); 26 | } 27 | 28 | /** 29 | * @inheritdoc 30 | */ 31 | final public function __toString() 32 | { 33 | return $this->value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Tags/Colour.php: -------------------------------------------------------------------------------- 1 | text = $text; 20 | $this->background = $background; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function text() 27 | { 28 | return $this->text; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function background() 35 | { 36 | return $this->background; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Vat/Evidence.php: -------------------------------------------------------------------------------- 1 | type = $type; 20 | $this->description = $description; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function type() 27 | { 28 | return $this->type; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function description() 35 | { 36 | return $this->description; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Entity/ErrorMethod.php: -------------------------------------------------------------------------------- 1 | name = $name; 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function name() 34 | { 35 | return $this->name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/Entity/Series/resources/series.add.response.ok.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 5466745 6 | BurlyWood_7522 7 | 8 | 1 9 | visible 10 | normal 11 | yearly 12 | 2018-01-22 15:59:07 13 | 2018-01-22 15:59:07 14 | 15 | 16 | 20 17 | 1 18 | 1 19 | 20 | 21 | 22 | OK 23 | 24 | -------------------------------------------------------------------------------- /tests/Auth/ApiKeysAuthTest.php: -------------------------------------------------------------------------------- 1 | faker()->uuid, 16 | $secretKey = $this->faker()->uuid, 17 | $appKey = $this->faker()->uuid, 18 | $companyId = $this->faker()->randomNumber() 19 | ); 20 | 21 | $this->assertEquals($accessKey, $auth->accessKey()); 22 | $this->assertEquals($secretKey, $auth->secretKey()); 23 | $this->assertEquals($appKey, $auth->appKey()); 24 | $this->assertEquals($companyId, $auth->companyId()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Vat/Repository/VatCodeIdRepositoryFactory.php: -------------------------------------------------------------------------------- 1 | getMap()); 21 | } 22 | 23 | public static function createWithMap(array $map): VatCodeIdRepository 24 | { 25 | return new VatCodeIdRepository($map); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entity/EntityApiFactory.php: -------------------------------------------------------------------------------- 1 | executorFactory = $executorFactory ?: new BuzzRequestExecutorFactory(); 17 | } 18 | 19 | /** 20 | * @param Auth $auth 21 | * @return DefaultEntityApi 22 | */ 23 | public function create(Auth $auth) 24 | { 25 | return new DefaultEntityApi( 26 | $this->executorFactory->create($auth) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/FileResponseSerialiser.php: -------------------------------------------------------------------------------- 1 | module(), $request->action()); 18 | } 19 | 20 | /** 21 | * @inheritdoc 22 | */ 23 | public function deserialise($response, Request $request) 24 | { 25 | return Response::fileResponse(new File($response)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entity/Parameters/Field.php: -------------------------------------------------------------------------------- 1 | name = $name; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function name() 31 | { 32 | return $this->name; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function __toString() 39 | { 40 | return (string)$this->name; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Entity/Series/resources/series.add.response.error.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SaddleBrown_56506241 6 | 7 | 1 8 | normal 9 | yearly 10 | 11 | 12 | template 13 | Brak obligatoryjnego znacznika [numer]. 14 | 15 | require 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | ERROR 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Entity/DateAwareEntity.php: -------------------------------------------------------------------------------- 1 | ") 12 | * @JMS\SerializedName("created") 13 | * @JMS\Groups({"response"}) 14 | */ 15 | private $created; 16 | 17 | /** 18 | * @var \DateTime 19 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") 20 | * @JMS\SerializedName("created") 21 | * @JMS\Groups({"response"}) 22 | */ 23 | private $modified; 24 | 25 | /** 26 | * @return \DateTime 27 | */ 28 | public function created() 29 | { 30 | return $this->created; 31 | } 32 | 33 | /** 34 | * @return \DateTime 35 | */ 36 | public function modified() 37 | { 38 | return $this->modified; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/Exception/SerialisationException.php: -------------------------------------------------------------------------------- 1 | request = $request; 22 | 23 | return $e; 24 | } 25 | 26 | /** 27 | * @return Request 28 | */ 29 | public function request() 30 | { 31 | return $this->request; 32 | } 33 | } -------------------------------------------------------------------------------- /src/Entity/AbstractEntity.php: -------------------------------------------------------------------------------- 1 | ") 21 | * @JMS\XmlList(entry="error") 22 | * @JMS\Groups({"addResponse", "editResponse"}) 23 | */ 24 | private $errors = array(); 25 | 26 | /** 27 | * @return int 28 | */ 29 | protected function plainId() 30 | { 31 | return $this->id; 32 | } 33 | 34 | /** 35 | * @return Error[] 36 | */ 37 | public function errors() 38 | { 39 | return $this->errors; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/Exception/DeserialisationException.php: -------------------------------------------------------------------------------- 1 | request = $request; 22 | 23 | return $e; 24 | } 25 | 26 | /** 27 | * @return Request 28 | */ 29 | public function request() 30 | { 31 | return $this->request; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Invoices/InvoicePage.php: -------------------------------------------------------------------------------- 1 | mode = $mode; 16 | } 17 | 18 | /** 19 | * @return InvoicePage 20 | */ 21 | public static function all() 22 | { 23 | return new self('all'); 24 | } 25 | 26 | /** 27 | * @return InvoicePage 28 | */ 29 | public static function invoice() 30 | { 31 | return new self('invoice'); 32 | } 33 | 34 | /** 35 | * @return InvoicePage 36 | */ 37 | public static function invoiceCopy() 38 | { 39 | return new self('invoiceCopy'); 40 | } 41 | 42 | /** 43 | * @inheritdoc 44 | */ 45 | public function __toString() 46 | { 47 | return $this->mode; 48 | } 49 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/EmptyRequestApiSerialiser.php: -------------------------------------------------------------------------------- 1 | apiSerialiser = $apiSerialiser; 15 | } 16 | 17 | /** 18 | * @inheritdoc 19 | */ 20 | public function serialise(Request $request) 21 | { 22 | if ($request->isBodyEmpty()) { 23 | return null; 24 | } 25 | 26 | return $this->apiSerialiser->serialise($request); 27 | } 28 | 29 | /** 30 | * @inheritdoc 31 | */ 32 | public function deserialise($response, Request $request) 33 | { 34 | return $this->apiSerialiser->deserialise($response, $request); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Vat/VatCodePeriod.php: -------------------------------------------------------------------------------- 1 | ") 15 | * @JMS\SerializedName("start") 16 | * @JMS\Groups({"response"}) 17 | */ 18 | private $start; 19 | 20 | /** 21 | * @var \DateTime 22 | * @JMS\Type("DateTime<'Y-m-d'>") 23 | * @JMS\SerializedName("stop") 24 | * @JMS\Groups({"response"}) 25 | */ 26 | private $stop; 27 | 28 | private function __construct() 29 | { 30 | } 31 | 32 | /** 33 | * @return \DateTime 34 | */ 35 | public function start() 36 | { 37 | return $this->start; 38 | } 39 | 40 | /** 41 | * @return \DateTime 42 | */ 43 | public function stop() 44 | { 45 | return $this->stop; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/InvoiceDeliveries/Type.php: -------------------------------------------------------------------------------- 1 | type = $type; 16 | } 17 | 18 | /** 19 | * @return Type 20 | */ 21 | public static function good() 22 | { 23 | return new self('good'); 24 | } 25 | 26 | /** 27 | * @return Type 28 | */ 29 | public static function correction() 30 | { 31 | return new self('correction'); 32 | } 33 | 34 | /** 35 | * @param string $type 36 | * @return Type 37 | * @internal 38 | */ 39 | public static function fromString($type) 40 | { 41 | return new self($type); 42 | } 43 | 44 | /** 45 | * @inheritdoc 46 | */ 47 | public function __toString() 48 | { 49 | return $this->type; 50 | } 51 | } -------------------------------------------------------------------------------- /src/Vat/Repository/VatCodeIdApiMapProvider.php: -------------------------------------------------------------------------------- 1 | vatCodesApi = $vatCodesApi; 21 | } 22 | 23 | public function getMap(): array 24 | { 25 | $map = []; 26 | /** @var VatCode $vatCode */ 27 | foreach ($this->vatCodesApi->findAll(Parameters::findParameters(Conditions::isNotNull('code'))) as $vatCode) { 28 | $map[strtoupper($vatCode->code())] = $vatCode->id()->id(); 29 | } 30 | 31 | return $map; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Vat/Repository/VatCodeIdCachingMapProvider.php: -------------------------------------------------------------------------------- 1 | provider = $provider; 24 | $this->cache = $cache; 25 | } 26 | 27 | public function getMap(): array 28 | { 29 | if (!$this->cache->has(self::CACHE_KEY)) { 30 | $this->cache->set(self::CACHE_KEY, $this->provider->getMap()); 31 | } 32 | 33 | return $this->cache->get(self::CACHE_KEY); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Invoices/TypeOfSale.php: -------------------------------------------------------------------------------- 1 | typeOfSale = (string)$typeOfSale; 16 | } 17 | 18 | /** 19 | * @return TypeOfSale 20 | */ 21 | public static function EE() 22 | { 23 | return new self('EE'); 24 | } 25 | 26 | /** 27 | * @return TypeOfSale 28 | */ 29 | public static function SW() 30 | { 31 | return new self('SW'); 32 | } 33 | 34 | /** 35 | * @param string $typeOfSale 36 | * @return TypeOfSale 37 | * @internal 38 | */ 39 | public static function fromString($typeOfSale) 40 | { 41 | return new self($typeOfSale); 42 | } 43 | 44 | /** 45 | * @inheritdoc 46 | */ 47 | public function __toString() 48 | { 49 | return $this->typeOfSale; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Invoices/PriceType.php: -------------------------------------------------------------------------------- 1 | priceType = strtolower($priceType); 16 | } 17 | 18 | /** 19 | * @return PriceType 20 | */ 21 | public static function netto(): PriceType 22 | { 23 | return new self('netto'); 24 | } 25 | 26 | /** 27 | * @return PriceType 28 | */ 29 | public static function brutto(): PriceType 30 | { 31 | return new self('brutto'); 32 | } 33 | 34 | /** 35 | * @param string $priceType 36 | * @return PriceType 37 | * @internal 38 | */ 39 | public static function fromString(string $priceType): PriceType 40 | { 41 | return new self($priceType); 42 | } 43 | 44 | public function __toString() 45 | { 46 | return $this->priceType; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Invoices/AutoSend.php: -------------------------------------------------------------------------------- 1 | email = (bool)$email; 24 | $this->postivo = (bool)$postivo; 25 | $this->sms = (bool)$sms; 26 | } 27 | 28 | /** 29 | * @return bool 30 | */ 31 | public function isEmailEnabled() 32 | { 33 | return $this->email; 34 | } 35 | 36 | /** 37 | * @return bool 38 | */ 39 | public function isPostivoEnabled() 40 | { 41 | return $this->postivo; 42 | } 43 | 44 | /** 45 | * @return bool 46 | */ 47 | public function isSmsEnabled() 48 | { 49 | return $this->sms; 50 | } 51 | } -------------------------------------------------------------------------------- /src/Invoices/Discount.php: -------------------------------------------------------------------------------- 1 | percent = $percent; 20 | $this->amount = $amount; 21 | } 22 | 23 | /** 24 | * @param float $amount 25 | * @return Discount 26 | */ 27 | public static function amountDiscount($amount) 28 | { 29 | return new self(null, $amount); 30 | } 31 | 32 | /** 33 | * @param float $percent 34 | * @return Discount 35 | */ 36 | public static function percentDiscount($percent) 37 | { 38 | return new self($percent, null); 39 | } 40 | 41 | public function amount() 42 | { 43 | return $this->amount; 44 | } 45 | 46 | public function percent() 47 | { 48 | return $this->percent; 49 | } 50 | } -------------------------------------------------------------------------------- /src/Auth/ApiKeysAuth.php: -------------------------------------------------------------------------------- 1 | accessKey = $accessKey; 22 | $this->secretKey = $secretKey; 23 | $this->appKey = $appKey; 24 | $this->companyId = $companyId; 25 | } 26 | 27 | public function accessKey(): string 28 | { 29 | return $this->accessKey; 30 | } 31 | 32 | public function secretKey(): string 33 | { 34 | return $this->secretKey; 35 | } 36 | 37 | public function appKey(): string 38 | { 39 | return $this->appKey; 40 | } 41 | 42 | public function companyId(): ?int 43 | { 44 | return $this->companyId; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Invoices/Correction.php: -------------------------------------------------------------------------------- 1 | type = $type; 24 | $this->number = (int)$number; 25 | $this->formalDataNumber = (int)$formalDataNumber; 26 | } 27 | 28 | /** 29 | * @return string 30 | */ 31 | public function type() 32 | { 33 | return $this->type; 34 | } 35 | 36 | /** 37 | * @return int 38 | */ 39 | public function number() 40 | { 41 | return $this->number; 42 | } 43 | 44 | /** 45 | * @return int 46 | */ 47 | public function formalDataNumber() 48 | { 49 | return $this->formalDataNumber; 50 | } 51 | } -------------------------------------------------------------------------------- /src/Vat/EvidenceType.php: -------------------------------------------------------------------------------- 1 | code = $code; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function code() 41 | { 42 | return $this->code ? StatusCode::fromString($this->code) : null; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function message() 49 | { 50 | return $this->message; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Daniel Bojdo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Entity/Parameters/Parameter.php: -------------------------------------------------------------------------------- 1 | name = $name; 36 | $this->value = $value; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function name() 43 | { 44 | return $this->name; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function value() 51 | { 52 | return $this->value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | tests/ 23 | 24 | 25 | 26 | 27 | 28 | ./src 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Invoices/PaymentState.php: -------------------------------------------------------------------------------- 1 | state = strtolower($state); 16 | } 17 | 18 | /** 19 | * @return PaymentState 20 | */ 21 | public static function paid() 22 | { 23 | return new self('paid'); 24 | } 25 | 26 | /** 27 | * @return PaymentState 28 | */ 29 | public static function unpaid() 30 | { 31 | return new self('unpaid'); 32 | } 33 | 34 | /** 35 | * @return PaymentState 36 | */ 37 | public static function undefined() 38 | { 39 | return new self('undefined'); 40 | } 41 | 42 | /** 43 | * @param string $status 44 | * @return PaymentState 45 | * @internal 46 | */ 47 | public static function fromString($status) 48 | { 49 | return new self($status); 50 | } 51 | 52 | public function __toString() 53 | { 54 | return $this->state; 55 | } 56 | } -------------------------------------------------------------------------------- /src/Series/ResetMode.php: -------------------------------------------------------------------------------- 1 | mode = $mode; 16 | } 17 | 18 | /** 19 | * @return ResetMode 20 | */ 21 | public static function yearly() 22 | { 23 | return new self('yearly'); 24 | } 25 | 26 | /** 27 | * @return ResetMode 28 | */ 29 | public static function monthly() 30 | { 31 | return new self('monthly'); 32 | } 33 | 34 | /** 35 | * @return ResetMode 36 | */ 37 | public static function daily() 38 | { 39 | return new self('daily'); 40 | } 41 | 42 | /** 43 | * @param string $mode 44 | * @return ResetMode 45 | * @internal 46 | */ 47 | public static function fromString($mode) 48 | { 49 | return new self($mode); 50 | } 51 | 52 | /** 53 | * @inheritdoc 54 | */ 55 | public function __toString() 56 | { 57 | return $this->mode; 58 | } 59 | } -------------------------------------------------------------------------------- /src/Entity/Parameters/Fields.php: -------------------------------------------------------------------------------- 1 | fields = $fields; 22 | } 23 | 24 | /** 25 | * @param Field $field 26 | * @return Fields 27 | */ 28 | public function withField(Field $field): Fields 29 | { 30 | $fields = $this->fields; 31 | $fields[] = $field; 32 | 33 | return new self($fields); 34 | } 35 | 36 | /** 37 | * @param string[]|Field[] $fields 38 | * @return Fields 39 | */ 40 | public static function fromArray(array $fields): Fields 41 | { 42 | return new self( 43 | array_map(function ($field) { 44 | return new Field((string)$field); 45 | }, 46 | $fields) 47 | ); 48 | } 49 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/JMS/OrderHandler.php: -------------------------------------------------------------------------------- 1 | GraphNavigatorInterface::DIRECTION_SERIALIZATION, 19 | 'format' => 'xml', 20 | 'type' => Order::class, 21 | 'method' => 'serialiseToXml', 22 | ], 23 | ]; 24 | } 25 | 26 | public function serialiseToXml( 27 | XmlSerializationVisitor $visitor, 28 | Order $order, 29 | array $type, 30 | SerializationContext $context 31 | ) { 32 | foreach ($order->orders() as $orderByField) { 33 | $context->getNavigator()->accept($orderByField, null, $context); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/AbstractTestCase.php: -------------------------------------------------------------------------------- 1 | create(); 24 | } 25 | 26 | /** 27 | * @return Entity\Infrastructure\Serialiser\ApiSerialiser 28 | */ 29 | protected function apiSerialiser() 30 | { 31 | $serialiserFactory = new ApiSerialiserFactory(); 32 | 33 | return $serialiserFactory->create(); 34 | } 35 | 36 | protected function faker() 37 | { 38 | if (!$this->faker) { 39 | $this->faker = Factory::create('pl_PL'); 40 | } 41 | 42 | return $this->faker; 43 | } 44 | } -------------------------------------------------------------------------------- /src/Entity/Parameters/OrderByField.php: -------------------------------------------------------------------------------- 1 | asc = $field; 38 | 39 | return $order; 40 | } 41 | 42 | /** 43 | * @param string $field 44 | * @return OrderByField 45 | */ 46 | public static function descending($field) 47 | { 48 | $order = new self(); 49 | $order->desc = $field; 50 | 51 | return $order; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/JMS/DateDeserializationListener.php: -------------------------------------------------------------------------------- 1 | 'serializer.pre_deserialize', 19 | 'method' => 'onPreDeserialize', 20 | 'class' => $type, 21 | 'format' => 'xml' 22 | ]; 23 | } 24 | 25 | return $events; 26 | } 27 | 28 | public function onPreDeserialize(PreDeserializeEvent $event) 29 | { 30 | /** @var \SimpleXMLElement $data */ 31 | $data = $event->getData(); 32 | if (!(string)$data) { 33 | $data->addAttribute("xsi:nil", "true", "http://www.w3.org/2001/XMLSchema-instance"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/TranslationLanguages/TranslationLanguageSerialisationTest.php: -------------------------------------------------------------------------------- 1 | 25 | 1 26 | pol-ang 27 | en 28 | 1 29 | 30 | XML; 31 | /** @var TranslationLanguage $translationLanguage */ 32 | $translationLanguage = $this->deserialiseEntity($xml); 33 | 34 | $this->assertEquals(TranslationLanguageId::create(1), $translationLanguage->id()); 35 | $this->assertSame('pol-ang', $translationLanguage->name()); 36 | $this->assertSame('en', $translationLanguage->code()); 37 | $this->assertSame(true, $translationLanguage->active()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entity/AbstractEntityId.php: -------------------------------------------------------------------------------- 1 | id = $id; 23 | } 24 | 25 | /** 26 | * @return int 27 | */ 28 | public function id() 29 | { 30 | return $this->id; 31 | } 32 | 33 | /** 34 | * @return bool 35 | */ 36 | public function isEmpty() 37 | { 38 | return $this->id == 0; 39 | } 40 | 41 | /** 42 | * @inheritdoc 43 | */ 44 | public function __toString() 45 | { 46 | return (string)$this->id; 47 | } 48 | 49 | /** 50 | * @param int|null $id 51 | * @return null|static 52 | */ 53 | public static function create($id) 54 | { 55 | if ($id === null) { 56 | return null; 57 | } 58 | 59 | return new static($id); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Auth/BasicAuth.php: -------------------------------------------------------------------------------- 1 | username = $username; 27 | $this->password = $password; 28 | $this->companyId = $companyId; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function username() 35 | { 36 | return $this->username; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function password() 43 | { 44 | return $this->password; 45 | } 46 | 47 | /** 48 | * @return null|int 49 | */ 50 | public function companyId(): ?int 51 | { 52 | return $this->companyId; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/ApiKeysAuthMiddleware.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 21 | } 22 | 23 | /** 24 | * @inheritDoc 25 | */ 26 | public function handleRequest(RequestInterface $request, callable $next) 27 | { 28 | $request = $request 29 | ->withHeader("accessKey", $this->auth->accessKey()) 30 | ->withHeader("secretKey", $this->auth->secretKey()) 31 | ->withHeader("appKey", $this->auth->appKey()); 32 | 33 | return $next($request); 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | public function handleResponse(RequestInterface $request, ResponseInterface $response, callable $next) 40 | { 41 | return $next($request, $response); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/BaseUrlMiddleware.php: -------------------------------------------------------------------------------- 1 | baseUrl = $baseUrl ?: self::$defaultBaseUrl; 21 | } 22 | 23 | /** 24 | * @inheritdoc 25 | */ 26 | public function handleRequest(RequestInterface $request, callable $next) 27 | { 28 | return $next( 29 | $request->withUri( 30 | new Uri( 31 | sprintf('%s/%s', $this->baseUrl, ltrim($request->getUri(), '/')) 32 | ) 33 | ) 34 | ); 35 | } 36 | 37 | /** 38 | * @inheritdoc 39 | */ 40 | public function handleResponse(RequestInterface $request, ResponseInterface $response, callable $next) 41 | { 42 | return $next($request, $response); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Entity/Infrastructure/Buzz/BaseUrlMiddlewareTest.php: -------------------------------------------------------------------------------- 1 | faker()->url); 17 | 18 | /** @var RequestInterface $newRequest */ 19 | $newRequest = $listener->handleRequest( 20 | new Request('GET', $path = '/some-uri?query=xyz'), 21 | function ($r) {return $r;} 22 | ); 23 | 24 | $this->assertEquals($baseUrl . $path, (string)$newRequest->getUri()); 25 | } 26 | 27 | /** 28 | * @test 29 | */ 30 | public function it_sets_wfirma_host_by_default() 31 | { 32 | $listener = new BaseUrlMiddleware(); 33 | /** @var RequestInterface $newRequest */ 34 | $newRequest = $listener->handleRequest(new Request('GET', $path = '/some-uri?query=xyz'), function ($r) {return $r;}); 35 | 36 | $this->assertEquals('https://api2.wfirma.pl'.$path, (string)$newRequest->getUri()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Invoices/Totals.php: -------------------------------------------------------------------------------- 1 | original = $original; 28 | $this->composed = $composed; 29 | $this->tax = $tax; 30 | $this->netto = $netto; 31 | } 32 | 33 | /** 34 | * @return float 35 | */ 36 | public function original() 37 | { 38 | return $this->original; 39 | } 40 | 41 | /** 42 | * @return float 43 | */ 44 | public function composed() 45 | { 46 | return $this->composed; 47 | } 48 | 49 | /** 50 | * @return float 51 | */ 52 | public function tax() 53 | { 54 | return $this->tax; 55 | } 56 | 57 | /** 58 | * @return float 59 | */ 60 | public function netto() 61 | { 62 | return $this->netto; 63 | } 64 | } -------------------------------------------------------------------------------- /tests/Contractors/ContractorSerialisationTest.php: -------------------------------------------------------------------------------- 1 | faker()->company(), 20 | $this->faker()->company(), 21 | null, 22 | null, 23 | null, 24 | null, 25 | null, 26 | null, 27 | true, 28 | false, 29 | null, 30 | null, 31 | null, 32 | new TagIds([ 33 | new TagId($tag1 = $this->faker()->word()), 34 | new TagId($tag2 = $this->faker()->word()), 35 | ]) 36 | ); 37 | 38 | $xmlContractor = $this->jmsSerializer()->serialize($contractor, 'xml', SerializationContext::create()->setGroups(['request', 'response'])); 39 | 40 | $this->assertStringContainsString($tag1, $xmlContractor); 41 | $this->assertStringContainsString($tag2, $xmlContractor); 42 | } 43 | } -------------------------------------------------------------------------------- /src/Contractors/InvoiceAddress.php: -------------------------------------------------------------------------------- 1 | street = $street; 28 | $this->zip = $zip; 29 | $this->city = $city; 30 | $this->country = $country; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function street() 37 | { 38 | return $this->street; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function zip() 45 | { 46 | return $this->zip; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function city() 53 | { 54 | return $this->city; 55 | } 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function country() 61 | { 62 | return $this->country; 63 | } 64 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webit/w-firma-api", 3 | "description": "wFirma.pl API", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords": ["sdk", "api", "wfirma", "w-firma"], 7 | "require": { 8 | "php": "^8.1 || ^8.2 || ^8.3", 9 | "jms/serializer": "^1.0|^2.0|^3.0", 10 | "kriswallsmith/buzz": "^1.2", 11 | "nyholm/psr7": "^1.0", 12 | "psr/log": "^2.0|^3.0", 13 | "psr/simple-cache": "^2.0|^3.0", 14 | "doctrine/annotations": "^2.0" 15 | }, 16 | "require-dev": { 17 | "phpunit/phpunit": "^10.0", 18 | "monolog/monolog": "^3.0", 19 | "nette/php-generator": "^4.0", 20 | "fakerphp/faker": "^1.20.0", 21 | "phpspec/prophecy": "^1.20", 22 | "phpspec/prophecy-phpunit": "^2.3" 23 | }, 24 | "suggest": { 25 | "symfony/cache": "To use VatCodeIdResolver with caching feature" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Webit\\WFirmaSDK\\": "src/" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "Webit\\WFirmaSDK\\": "tests/" 35 | } 36 | }, 37 | "extra": { 38 | "branch-alias": { 39 | "dev-1.x": "1.x-dev", 40 | "dev-2.x": "2.x-dev", 41 | "dev-master": "3.x-dev" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Invoices/Schema.php: -------------------------------------------------------------------------------- 1 | schema = strtolower($schema); 16 | } 17 | 18 | /** 19 | * @return Schema 20 | */ 21 | public static function normal() 22 | { 23 | return new self('normal'); 24 | } 25 | 26 | /** 27 | * @return Schema 28 | */ 29 | public static function vatInvoiceDate() 30 | { 31 | return new self('vat_invoice_date'); 32 | } 33 | 34 | /** 35 | * @return Schema 36 | */ 37 | public static function vatBuyerConstructionService() 38 | { 39 | return new self('vat_buyer_construction_service'); 40 | } 41 | 42 | /** 43 | * @return Schema 44 | */ 45 | public static function assessor() 46 | { 47 | return new self('vat_buyer_construction_service'); 48 | } 49 | 50 | /** 51 | * @param $schema 52 | * @return Schema 53 | * @internal 54 | */ 55 | public static function fromString($schema) 56 | { 57 | return new self($schema); 58 | } 59 | 60 | public function __toString() 61 | { 62 | return $this->schema; 63 | } 64 | } -------------------------------------------------------------------------------- /tests/Vat/VatCodesApiIntegrationTest.php: -------------------------------------------------------------------------------- 1 | vatCodesApi = new VatCodesApi($this->entityApi()); 15 | } 16 | 17 | /** 18 | * @test 19 | */ 20 | public function testFind() 21 | { 22 | $vatCodes = $this->vatCodesApi->find(null); 23 | foreach ($vatCodes as $vatCode) { 24 | $this->assertInstanceOf('Webit\WFirmaSDK\Vat\VatCode', $vatCode); 25 | } 26 | } 27 | 28 | /** 29 | * @test 30 | */ 31 | public function testGet() 32 | { 33 | $this->assertInstanceOf( 34 | 'Webit\WFirmaSDK\Vat\VatCode', 35 | $this->vatCodesApi->get(VatCodeId::create(222)) 36 | ); 37 | } 38 | 39 | /** 40 | * @test 41 | */ 42 | public function testFindAll() 43 | { 44 | $this->assertInstanceOf('Webit\WFirmaSDK\Entity\EntityIterator', $this->vatCodesApi->findAll()); 45 | } 46 | 47 | /** 48 | * @test 49 | */ 50 | public function testCount() 51 | { 52 | $this->assertInternalType('integer', $this->vatCodesApi->count()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Entity/Infrastructure/Buzz/CompanyIdMiddlewareTest.php: -------------------------------------------------------------------------------- 1 | handleRequest( 19 | $request = new Request('POST', $resource), function ($r) {return $r;} 20 | ); 21 | 22 | $this->assertEquals($expectedResource, (string)$newRequest->getUri()); 23 | } 24 | 25 | public function resources() 26 | { 27 | return array( 28 | array( 29 | '/some/resource/without-query-string', 30 | $id = $this->faker()->randomNumber(), 31 | sprintf('/some/resource/without-query-string?company_id=%s', $id), 32 | ), 33 | array( 34 | '/some/resource/with-query-string?some=value', 35 | $id = $this->faker()->randomNumber(), 36 | sprintf('/some/resource/with-query-string?some=value&company_id=%s', $id), 37 | ) 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Invoices/Disposal.php: -------------------------------------------------------------------------------- 1 | dateEmpty = $dateEmpty; 35 | $this->date = $date; 36 | $this->dateFormat = $dateFormat; 37 | } 38 | 39 | /** 40 | * @return bool 41 | */ 42 | public function dateEmpty() 43 | { 44 | return $this->dateEmpty; 45 | } 46 | 47 | /** 48 | * @return \DateTime 49 | */ 50 | public function date() 51 | { 52 | return $this->date; 53 | } 54 | 55 | /** 56 | * @return string 57 | */ 58 | public function dateFormat() 59 | { 60 | return $this->dateFormat; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/CompanyIdMiddleware.php: -------------------------------------------------------------------------------- 1 | companyId = $companyId; 21 | } 22 | 23 | /** 24 | * @inheritdoc 25 | */ 26 | public function handleRequest(RequestInterface $request, callable $next) 27 | { 28 | $resource = $request->getUri(); 29 | $parsed = parse_url($resource); 30 | if (isset($parsed['query'])) { 31 | $resource .= sprintf('&company_id=%d', (string)$this->companyId); 32 | } else { 33 | $resource .= sprintf('?company_id=%d', (string)$this->companyId); 34 | } 35 | 36 | return $next( 37 | $request->withUri( 38 | new Uri($resource) 39 | ) 40 | ); 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function handleResponse(RequestInterface $request, ResponseInterface $response, callable $next) 47 | { 48 | return $next($request, $response); 49 | } 50 | } -------------------------------------------------------------------------------- /tests/TranslationLanguages/TranslationLanguagesApiIntegrationTest.php: -------------------------------------------------------------------------------- 1 | api = new TranslationLanguagesApi($this->entityApi()); 17 | } 18 | 19 | /** 20 | * @test 21 | */ 22 | public function testFind() 23 | { 24 | foreach ($this->api->find() as $translationLanguage) { 25 | $this->assertInstanceOf('Webit\WFirmaSDK\TranslationLanguages\TranslationLanguage', $translationLanguage); 26 | } 27 | } 28 | 29 | 30 | /** 31 | * @test 32 | */ 33 | public function testGet() 34 | { 35 | $translationLanguages = $this->api->find( 36 | Parameters::findParameters( 37 | null, 38 | null, 39 | new Pagination(1) 40 | ) 41 | ); 42 | 43 | $expectedLanguage = array_shift($translationLanguages); 44 | 45 | $this->assertEquals( 46 | $expectedLanguage, 47 | $this->api->get($expectedLanguage->id()) 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Goods/Dimensions.php: -------------------------------------------------------------------------------- 1 | weight = $weight; 32 | $this->length = $length; 33 | $this->width = $width; 34 | $this->height = $height; 35 | } 36 | 37 | /** 38 | * @return ?float 39 | */ 40 | public function weight(): ?float 41 | { 42 | return $this->weight; 43 | } 44 | 45 | /** 46 | * @return ?float 47 | */ 48 | public function length(): ?float 49 | { 50 | return $this->length; 51 | } 52 | 53 | /** 54 | * @return ?float 55 | */ 56 | public function width(): ?float 57 | { 58 | return $this->width; 59 | } 60 | 61 | /** 62 | * @return ?float 63 | */ 64 | public function height(): ?float 65 | { 66 | return $this->height; 67 | } 68 | } -------------------------------------------------------------------------------- /src/Entity/Exception/ApiException.php: -------------------------------------------------------------------------------- 1 | apiResponse = $response; 29 | $exception->apiRequest = $request; 30 | 31 | return $exception; 32 | } 33 | 34 | /** 35 | * @return Response 36 | */ 37 | public function apiResponse() 38 | { 39 | return $this->apiResponse; 40 | } 41 | 42 | /** 43 | * @return Request 44 | */ 45 | public function apiRequest() 46 | { 47 | return $this->apiRequest; 48 | } 49 | 50 | /** 51 | * @param Request $request 52 | * @param Response $response 53 | * @return string 54 | */ 55 | protected static function message(Request $request, Response $response = null) 56 | { 57 | throw new \RuntimeException(get_class().'::message method must be implemented.'); 58 | } 59 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/BuzzRequestExecutorFactory.php: -------------------------------------------------------------------------------- 1 | browserFactory = $browserFactory ?: new BrowserFactory(); 28 | $this->apiSerialiserFactory = $apiSerialiserFactory ?: new ApiSerialiserFactory(); 29 | $this->logger = $logger; 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public function create(Auth $auth): RequestExecutor 36 | { 37 | return new BuzzRequestExecutor( 38 | $this->browserFactory->create($auth), 39 | $this->apiSerialiserFactory->create(), 40 | $this->logger 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Parameters/Pagination.php: -------------------------------------------------------------------------------- 1 | limit = $limit < 0 ? 20 : (int)$limit; 34 | $this->page = $page < 1 ? 20 : (int)$page; 35 | $this->total = $total; 36 | } 37 | 38 | /** 39 | * @return Pagination 40 | */ 41 | public function nextPage() 42 | { 43 | return new self($this->limit, $this->page + 1); 44 | } 45 | 46 | /** 47 | * @return int 48 | */ 49 | public function limit() 50 | { 51 | return $this->limit; 52 | } 53 | 54 | /** 55 | * @return int 56 | */ 57 | public function page() 58 | { 59 | return $this->page; 60 | } 61 | 62 | /** 63 | * @return int 64 | */ 65 | public function total() 66 | { 67 | return $this->total; 68 | } 69 | } -------------------------------------------------------------------------------- /src/Contractors/PaymentSettings.php: -------------------------------------------------------------------------------- 1 | days = $days; 30 | $this->method = $method; 31 | $this->discountPercent = $discountPercent; 32 | $this->remind = $remind; 33 | } 34 | 35 | /** 36 | * @return int 37 | */ 38 | public function days() 39 | { 40 | return $this->days; 41 | } 42 | 43 | /** 44 | * @return PaymentMethod 45 | */ 46 | public function method() 47 | { 48 | return $this->method; 49 | } 50 | 51 | /** 52 | * @return float 53 | */ 54 | public function discountPercent() 55 | { 56 | return $this->discountPercent; 57 | } 58 | 59 | /** 60 | * @return bool 61 | */ 62 | public function remind() 63 | { 64 | return (bool)$this->remind; 65 | } 66 | } -------------------------------------------------------------------------------- /src/Series/TemplateTokens.php: -------------------------------------------------------------------------------- 1 | 0) { 14 | return sprintf('[numer:zera_wiodące=%d]', $leadingZeros); 15 | } 16 | 17 | return '[numer]'; 18 | } 19 | 20 | /** 21 | * @return string 22 | */ 23 | public static function day() 24 | { 25 | return '[dzień]'; 26 | } 27 | 28 | /** 29 | * @param bool $leadingZero 30 | * @return string 31 | */ 32 | public static function month($leadingZero = false) 33 | { 34 | if ($leadingZero) { 35 | return '[miesiąc:zera_wiodące=2]'; 36 | } 37 | 38 | return '[miesiąc]'; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public static function quarter() 45 | { 46 | return '[kwartał]'; 47 | } 48 | 49 | /** 50 | * @param bool $twoDigits 51 | * @return string 52 | */ 53 | public static function year($twoDigits = false) 54 | { 55 | if ($twoDigits) { 56 | return '[rok:format_dwucyfrowy]'; 57 | } 58 | 59 | return '[rok]'; 60 | } 61 | 62 | /** 63 | * @return string 64 | */ 65 | public static function dayOfYear() 66 | { 67 | return '[dzień_roku]'; 68 | } 69 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/ApiSerialiserFactory.php: -------------------------------------------------------------------------------- 1 | timezone = $timezone ?: 'Europe/Warsaw'; 20 | } 21 | 22 | /** 23 | * @return ApiSerialiser 24 | */ 25 | public function create() 26 | { 27 | $serializerFactory = new SerializerFactory($this->timezone); 28 | 29 | $jmsSerialiser = new JmsApiSerialiser($serializerFactory->create()); 30 | 31 | $byModuleAndActionSerialiser = new ByModuleAndActionApiSerialiser(); 32 | $byModuleAndActionSerialiser->registerSerialiser( 33 | new FallingBackApiSerialiser( 34 | $jmsSerialiser, 35 | new FileResponseSerialiser() 36 | ), 37 | Module::invoices()->name(), 38 | 'download' 39 | ); 40 | 41 | return new EmptyRequestApiSerialiser( 42 | new FallingBackApiSerialiser( 43 | $byModuleAndActionSerialiser, 44 | $jmsSerialiser 45 | ) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/JMS/SerializerFactory.php: -------------------------------------------------------------------------------- 1 | timezone = $timezone; 19 | } 20 | 21 | /** 22 | * @return SerializerInterface 23 | */ 24 | public function create() 25 | { 26 | $serializerBuilder = SerializerBuilder::create(); 27 | 28 | $timezone = $this->timezone; 29 | $serializerBuilder->configureHandlers(function (HandlerRegistryInterface $registry) use ($timezone) { 30 | $registry->registerSubscribingHandler(new DateHandler(\DateTime::ISO8601, $timezone)); 31 | $registry->registerSubscribingHandler(new OrderHandler()); 32 | }); 33 | 34 | $serializerBuilder->configureListeners(function (EventDispatcherInterface $eventDispatcher) { 35 | $eventDispatcher->addSubscriber(new DateDeserializationListener()); 36 | $eventDispatcher->addSubscriber(new RequestResponseSerializationListener()); 37 | }); 38 | 39 | return $serializerBuilder->build(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Payments/PaymentMethod.php: -------------------------------------------------------------------------------- 1 | method = strtolower($method); 16 | } 17 | 18 | /** 19 | * @return PaymentMethod 20 | */ 21 | public static function cash() 22 | { 23 | return new self('cash'); 24 | } 25 | 26 | /** 27 | * @return PaymentMethod 28 | */ 29 | public static function transfer() 30 | { 31 | return new self('transfer'); 32 | } 33 | 34 | /** 35 | * @return PaymentMethod 36 | */ 37 | public static function compensation() 38 | { 39 | return new self('compensation'); 40 | } 41 | 42 | /** 43 | * @return PaymentMethod 44 | */ 45 | public static function cod() 46 | { 47 | return new self('cod'); 48 | } 49 | 50 | /** 51 | * @return PaymentMethod 52 | */ 53 | public static function paymentCard() 54 | { 55 | return new self('payment_card'); 56 | } 57 | 58 | /** 59 | * @param string $method 60 | * @return PaymentMethod 61 | * @internal 62 | */ 63 | public static function fromString($method) 64 | { 65 | return new self($method); 66 | } 67 | 68 | public function __toString() 69 | { 70 | return $this->method; 71 | } 72 | } -------------------------------------------------------------------------------- /src/Invoices/DownloadParameters.php: -------------------------------------------------------------------------------- 1 | page = $page ?: InvoicePage::invoice(); 35 | $this->printAddress = (bool)$printAddress; 36 | $this->paymentLeaflet = (bool)$paymentLeaflet; 37 | $this->duplicate = (bool)$duplicate; 38 | } 39 | 40 | /** 41 | * @return Parameters 42 | */ 43 | public function toActionParameters() 44 | { 45 | return Parameters::actionParameters(array( 46 | new Parameter('page', (string)$this->page), 47 | new Parameter('address', (int)$this->printAddress), 48 | new Parameter('leaflet', (int)$this->paymentLeaflet), 49 | new Parameter('duplicate', (int)$this->duplicate) 50 | )); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Vat/VatCodesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 19 | } 20 | 21 | /** 22 | * @param Parameters|null $parameters 23 | * @return VatCode[]|Entity[] 24 | */ 25 | public function find(Parameters $parameters = null) 26 | { 27 | return $this->entityApi->find(Module::vatCodes(), $parameters); 28 | } 29 | 30 | /** 31 | * @param Parameters|null $parameters 32 | * @return EntityIterator|Entity[] 33 | */ 34 | public function findAll(Parameters $parameters = null) 35 | { 36 | return $this->entityApi->findAll(Module::vatCodes(), $parameters); 37 | } 38 | 39 | /** 40 | * @param VatCodeId $id 41 | * @return VatCode|Entity 42 | */ 43 | public function get(VatCodeId $id) 44 | { 45 | return $this->entityApi->get($id->id(), Module::vatCodes()); 46 | } 47 | 48 | /** 49 | * @param Parameters|null $parameters 50 | * @return int 51 | */ 52 | public function count(Parameters $parameters = null) 53 | { 54 | return $this->entityApi->count(Module::vatCodes(), $parameters); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/FallingBackApiSerialiser.php: -------------------------------------------------------------------------------- 1 | serialiser = $serialiser; 23 | $this->fallbackSerialiser = $fallbackSerialiser; 24 | } 25 | 26 | /** 27 | * @inheritdoc 28 | */ 29 | public function serialise(Request $request) 30 | { 31 | try { 32 | return $this->serialiser->serialise($request); 33 | } catch (ApiSerialiserException $e) { 34 | return $this->fallbackSerialiser->serialise($request); 35 | } 36 | } 37 | 38 | /** 39 | * @inheritdoc 40 | */ 41 | public function deserialise($response, Request $request) 42 | { 43 | try { 44 | return $this->serialiser->deserialise($response, $request); 45 | } catch (ApiSerialiserException $e) { 46 | return $this->fallbackSerialiser->deserialise($response, $request); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Entity/Error.php: -------------------------------------------------------------------------------- 1 | field = $field; 44 | $this->message = $message; 45 | $this->method = $method; 46 | } 47 | 48 | /** 49 | * @return string 50 | */ 51 | public function field() 52 | { 53 | return $this->field; 54 | } 55 | 56 | /** 57 | * @return string 58 | */ 59 | public function message() 60 | { 61 | return $this->message; 62 | } 63 | 64 | /** 65 | * @return ErrorMethod 66 | */ 67 | public function method() 68 | { 69 | return $this->method; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/TranslationLanguages/TranslationLanguage.php: -------------------------------------------------------------------------------- 1 | plainId()); 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function name() 53 | { 54 | return $this->name; 55 | } 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function code() 61 | { 62 | return $this->code; 63 | } 64 | 65 | /** 66 | * @return string 67 | */ 68 | public function active() 69 | { 70 | return (bool)$this->active; 71 | } 72 | } -------------------------------------------------------------------------------- /src/Contractors/TaxIdType.php: -------------------------------------------------------------------------------- 1 | type = strtolower($type); 16 | } 17 | 18 | /** 19 | * @return TaxIdType 20 | */ 21 | public static function nip() 22 | { 23 | return new self('nip'); 24 | } 25 | 26 | /** 27 | * @return TaxIdType 28 | */ 29 | public static function vat() 30 | { 31 | return new self('vat'); 32 | } 33 | 34 | /** 35 | * @return TaxIdType 36 | */ 37 | public static function pesel() 38 | { 39 | return new self('pesel'); 40 | } 41 | 42 | /** 43 | * @return TaxIdType 44 | */ 45 | public static function regon() 46 | { 47 | return new self('regon'); 48 | } 49 | 50 | /** 51 | * @return TaxIdType 52 | */ 53 | public static function custom() 54 | { 55 | return new self('custom'); 56 | } 57 | 58 | /** 59 | * @return TaxIdType 60 | */ 61 | public static function none() 62 | { 63 | return new self('none'); 64 | } 65 | 66 | /** 67 | * @param string $type 68 | * @return TaxIdType 69 | * @internal 70 | */ 71 | public static function fromString($type) 72 | { 73 | return new self($type); 74 | } 75 | 76 | /** 77 | * @inheritdoc 78 | */ 79 | public function __toString() 80 | { 81 | return $this->type; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Goods/GoodsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 20 | } 21 | 22 | /** 23 | * @param Good $good 24 | * @return \Webit\WFirmaSDK\Entity\Entity|Good 25 | */ 26 | public function add(Good $good) 27 | { 28 | return $this->entityApi->add($good); 29 | } 30 | 31 | /** 32 | * @param Good $good 33 | * @return \Webit\WFirmaSDK\Entity\Entity|Good 34 | */ 35 | public function edit(Good $good) 36 | { 37 | return $this->entityApi->edit($good); 38 | } 39 | 40 | /** 41 | * @param GoodId $id 42 | */ 43 | public function delete(GoodId $id) 44 | { 45 | $this->entityApi->delete($id->id(), Module::goods()); 46 | } 47 | 48 | /** 49 | * @param Parameters|null $parameters 50 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Good[] 51 | */ 52 | public function find(Parameters $parameters = null) 53 | { 54 | return $this->entityApi->find(Module::goods(), $parameters); 55 | } 56 | 57 | /** 58 | * @param GoodId $id 59 | * @return \Webit\WFirmaSDK\Entity\Entity|Good 60 | */ 61 | public function get(GoodId $id) 62 | { 63 | return $this->entityApi->get($id->id(), Module::goods()); 64 | } 65 | } -------------------------------------------------------------------------------- /src/CompanyAccounts/CompanyAccountsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 17 | } 18 | 19 | /** 20 | * @param Parameters|null $parameters 21 | * @return \Webit\WFirmaSDK\Entity\Entity[]|CompanyAccount[] 22 | */ 23 | public function find(Parameters $parameters = null) 24 | { 25 | return $this->entityApi->find(Module::companyAccounts(), $parameters); 26 | } 27 | 28 | /** 29 | * @param Parameters|null $parameters 30 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|CompanyAccount[] 31 | */ 32 | public function findAll(Parameters $parameters = null) 33 | { 34 | return $this->entityApi->findAll(Module::companyAccounts(), $parameters); 35 | } 36 | 37 | /** 38 | * @param CompanyAccountId $id 39 | * @return \Webit\WFirmaSDK\Entity\Entity|CompanyAccount 40 | */ 41 | public function get(CompanyAccountId $id) 42 | { 43 | return $this->entityApi->get($id->id(), Module::companyAccounts()); 44 | } 45 | 46 | /** 47 | * @param Parameters|null $parameters 48 | * @return int 49 | */ 50 | public function count(Parameters $parameters = null) 51 | { 52 | return $this->entityApi->count(Module::companyAccounts(), $parameters); 53 | } 54 | } -------------------------------------------------------------------------------- /src/DeclarationCountries/DeclarationCountriesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 19 | } 20 | 21 | /** 22 | * @param Parameters|null $parameters 23 | * @return DeclarationCountry[]|Entity[] 24 | */ 25 | public function find(Parameters $parameters = null) { 26 | return $this->entityApi->find(Module::declarationCountries(), $parameters); 27 | } 28 | 29 | /** 30 | * @param Parameters|null $parameters 31 | * @return DeclarationCountry[]|Entity[]|EntityIterator 32 | */ 33 | public function findAll(Parameters $parameters = null) 34 | { 35 | return $this->entityApi->findAll(Module::declarationCountries(), $parameters); 36 | } 37 | 38 | /** 39 | * @param DeclarationCountryId $id 40 | * @return DeclarationCountry|Entity 41 | */ 42 | public function get(DeclarationCountryId $id) 43 | { 44 | return $this->entityApi->get($id->id(), Module::declarationCountries()); 45 | } 46 | 47 | /** 48 | * @param Parameters|null $parameters 49 | * @return int 50 | */ 51 | public function count(Parameters $parameters = null) 52 | { 53 | return $this->entityApi->count(Module::declarationCountries(), $parameters); 54 | } 55 | } -------------------------------------------------------------------------------- /src/InvoiceDescriptions/InvoiceDescriptionsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 17 | } 18 | 19 | /** 20 | * @param Parameters|null $parameters 21 | * @return \Webit\WFirmaSDK\Entity\Entity[]|InvoiceDescription[] 22 | */ 23 | public function find(Parameters $parameters = null) 24 | { 25 | return $this->entityApi->find(Module::invoiceDescriptions(), $parameters); 26 | } 27 | 28 | /** 29 | * @param Parameters|null $parameters 30 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|InvoiceDescription[] 31 | */ 32 | public function findAll(Parameters $parameters = null) 33 | { 34 | return $this->entityApi->findAll(Module::invoiceDescriptions(), $parameters); 35 | } 36 | 37 | /** 38 | * @param InvoiceDescriptionId $id 39 | * @return \Webit\WFirmaSDK\Entity\Entity|InvoiceDescription 40 | */ 41 | public function get(InvoiceDescriptionId $id) 42 | { 43 | return $this->entityApi->get($id->id(), Module::invoiceDescriptions()); 44 | } 45 | 46 | /** 47 | * @param Parameters|null $parameters 48 | * @return int 49 | */ 50 | public function count(Parameters $parameters = null) 51 | { 52 | return $this->entityApi->count(Module::invoiceDescriptions(), $parameters); 53 | } 54 | } -------------------------------------------------------------------------------- /src/Entity/EntityWrapper.php: -------------------------------------------------------------------------------- 1 | ") 18 | * @JMS\XmlList(entry="entity", inline=true) 19 | * @JMS\Groups({"addRequest", "editRequest", "response"}) 20 | */ 21 | private $entities; 22 | 23 | /** 24 | * @var Parameters 25 | * @JMS\SerializedName("parameters") 26 | * @JMS\Type("Webit\WFirmaSDK\Entity\Parameters\Parameters") 27 | * @JMS\Groups({"request", "response"}) 28 | */ 29 | private $parameters; 30 | 31 | /** 32 | * RecordWrapper constructor. 33 | * @param Entity $entity 34 | * @param Parameters $parameters 35 | */ 36 | public function __construct(Entity $entity = null, Parameters $parameters = null) 37 | { 38 | $this->entities = $entity ? array($entity) : array(); 39 | $this->parameters = $parameters; 40 | } 41 | 42 | /** 43 | * @return Parameters 44 | */ 45 | public function parameters() 46 | { 47 | return $this->parameters ?: Parameters::defaultParameters(); 48 | } 49 | 50 | /** 51 | * @return Entity 52 | */ 53 | public function entity() 54 | { 55 | return $this->entities ? $this->entities[0] : null; 56 | } 57 | 58 | /** 59 | * @return Entity[] 60 | */ 61 | public function entities() 62 | { 63 | return $this->entities; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/TranslationLanguages/TranslationLanguagesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 17 | } 18 | 19 | /** 20 | * @param Parameters|null $parameters 21 | * @return \Webit\WFirmaSDK\Entity\Entity[]|TranslationLanguage[] 22 | */ 23 | public function find(Parameters $parameters = null) 24 | { 25 | return $this->entityApi->find(Module::translationLanguages(), $parameters); 26 | } 27 | 28 | /** 29 | * @param Parameters|null $parameters 30 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|TranslationLanguage[] 31 | */ 32 | public function findAll(Parameters $parameters = null) 33 | { 34 | return $this->entityApi->findAll(Module::translationLanguages(), $parameters); 35 | } 36 | 37 | /** 38 | * @param TranslationLanguageId $id 39 | * @return \Webit\WFirmaSDK\Entity\Entity|TranslationLanguage 40 | */ 41 | public function get(TranslationLanguageId $id) 42 | { 43 | return $this->entityApi->get($id->id(), Module::translationLanguages()); 44 | } 45 | 46 | /** 47 | * @param Parameters|null $parameters 48 | * @return int 49 | */ 50 | public function count(Parameters $parameters = null) 51 | { 52 | return $this->entityApi->count(Module::translationLanguages(), $parameters); 53 | } 54 | } -------------------------------------------------------------------------------- /src/Vat/Repository/VatCodeIdRepository.php: -------------------------------------------------------------------------------- 1 | codeToIdMap = []; 19 | foreach ($codeToIdMap as $key => $id) { 20 | $this->codeToIdMap[strtoupper($key)] = (int)$id; 21 | } 22 | } 23 | 24 | /** 25 | * Gets the VatCodeId by its string code 26 | * 27 | * @param string $code 28 | * @return ?VatCodeId 29 | */ 30 | public function getByCode(string $code): ?VatCodeId 31 | { 32 | $code = strtoupper($code); 33 | if (isset($this->codeToIdMap[$code])) { 34 | return new VatCodeId($this->codeToIdMap[$code]); 35 | } 36 | 37 | return null; 38 | } 39 | 40 | /** 41 | * Gets the VatCodeId by the given VatRate 42 | * 43 | * @param VatRate $vatRate 44 | * @return ?VatCodeId 45 | */ 46 | public function getByVatRate(VatRate $vatRate): ?VatCodeId 47 | { 48 | return $vatRate->vatCodeId() ?: $this->getByCode((string)$vatRate->code()); 49 | } 50 | 51 | /** 52 | * Returns all known VatCodeId mapped by their string code 53 | * 54 | * @return VatCodeId[] 55 | */ 56 | public function getAll(): array 57 | { 58 | $codes = []; 59 | foreach ($this->codeToIdMap as $code => $id) { 60 | $codes[$code] = new VatCodeId($id); 61 | } 62 | 63 | return $codes; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/DeclarationCountries/DeclarationCountriesApiTest.php: -------------------------------------------------------------------------------- 1 | declarationCountriesApi = new DeclarationCountriesApi( 17 | $this->entityApi() 18 | ); 19 | } 20 | 21 | /** 22 | * @test 23 | */ 24 | public function it_gets_declaration_country() 25 | { 26 | $country = $this->declarationCountriesApi->get(DeclarationCountryId::create(20)); 27 | $this->assertInstanceOf('Webit\WFirmaSDK\DeclarationCountries\DeclarationCountry', $country); 28 | } 29 | 30 | /** 31 | * @test 32 | */ 33 | public function it_finds_declaration_country() 34 | { 35 | foreach ($this->declarationCountriesApi->find() as $i => $country) { 36 | $this->assertInstanceOf('Webit\WFirmaSDK\DeclarationCountries\DeclarationCountry', $country); 37 | } 38 | } 39 | 40 | /** 41 | * @test 42 | */ 43 | public function it_finds_all_declaration_country() 44 | { 45 | foreach ($this->declarationCountriesApi->findAll() as $i => $country) { 46 | $this->assertInstanceOf('Webit\WFirmaSDK\DeclarationCountries\DeclarationCountry', $country); 47 | } 48 | } 49 | 50 | /** 51 | * @test 52 | */ 53 | public function it_counts_declaration_countries() 54 | { 55 | $this->assertInternalType('integer', $this->declarationCountriesApi->count()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/ByModuleAndActionApiSerialiser.php: -------------------------------------------------------------------------------- 1 | serialisers = array(); 16 | } 17 | 18 | public function registerSerialiser(ApiSerialiser $serialiser, $moduleName, $action) 19 | { 20 | $this->serialisers[sprintf('%s:%s', $moduleName, $action)] = $serialiser; 21 | } 22 | 23 | /** 24 | * @param Request $request 25 | * @return string 26 | */ 27 | public function serialise(Request $request) 28 | { 29 | $serialiser = $this->selectSerialiser($request); 30 | 31 | return $serialiser->serialise($request); 32 | } 33 | 34 | /** 35 | * @inheritdoc 36 | */ 37 | public function deserialise($response, Request $request) 38 | { 39 | $serialiser = $this->selectSerialiser($request); 40 | 41 | return $serialiser->deserialise($response, $request); 42 | } 43 | 44 | /** 45 | * @param Request $request 46 | * @return ApiSerialiser 47 | */ 48 | private function selectSerialiser(Request $request) 49 | { 50 | $key = sprintf('%s:%s', $request->module(), $request->action()); 51 | if (isset($this->serialisers[$key])) { 52 | return $this->serialisers[$key]; 53 | } 54 | 55 | throw UnsupportedModuleOrActionException::create((string)$request->module(), $request->action()); 56 | } 57 | } -------------------------------------------------------------------------------- /tests/AbstractSerialisationTest.php: -------------------------------------------------------------------------------- 1 | module(); 22 | 23 | $idClass = $module->entityClass() . 'Id'; 24 | 25 | $translationLanguageId = new $idClass($id = $this->faker()->randomNumber()); 26 | 27 | $context = SerializationContext::create(); 28 | $context->setGroups(array('request')); 29 | 30 | $expectedResult = << 32 | <%s> 33 | %s 34 | 35 | XML; 36 | $expectedResult = sprintf($expectedResult, $module->entityName(), $id, $module->entityName()); 37 | 38 | $this->assertEquals( 39 | $expectedResult, 40 | trim($this->jmsSerializer()->serialize($translationLanguageId, 'xml', $context)) 41 | ); 42 | } 43 | 44 | /** 45 | * @param string $xml 46 | * @return array|\JMS\Serializer\scalar|object 47 | */ 48 | protected function deserialiseEntity($xml) 49 | { 50 | $context = DeserializationContext::create(); 51 | $context->setGroups(array('response')); 52 | 53 | /** @var Entity $translationLanguage */ 54 | return $this->jmsSerializer()->deserialize( 55 | $xml, 56 | $this->module()->entityClass(), 57 | 'xml', 58 | $context 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Entity/EntityApi.php: -------------------------------------------------------------------------------- 1 | ") 21 | * @JMS\SerializedName("date") 22 | * @JMS\Groups({"request", "response"}) 23 | */ 24 | private $date; 25 | 26 | /** 27 | * @var string 28 | * @JMS\Type("string") 29 | * @JMS\SerializedName("type") 30 | * @JMS\Groups({"response"}) 31 | */ 32 | private $type; 33 | 34 | /** 35 | * @param InvoiceId $invoiceId 36 | * @param \DateTime $date 37 | */ 38 | public function __construct(InvoiceId $invoiceId, \DateTime $date = null) 39 | { 40 | $this->invoiceId = $invoiceId; 41 | $this->date = $date ?: new \DateTime(); 42 | } 43 | 44 | /** 45 | * @return null|\Webit\WFirmaSDK\Entity\EntityId|InvoiceDeliveryId 46 | */ 47 | public function id() 48 | { 49 | return InvoiceDeliveryId::create($this->plainId()); 50 | } 51 | 52 | /** 53 | * @return InvoiceId 54 | */ 55 | public function invoiceId() 56 | { 57 | return $this->invoiceId; 58 | } 59 | 60 | /** 61 | * @return \DateTime 62 | */ 63 | public function date() 64 | { 65 | return $this->date; 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function type() 72 | { 73 | return $this->type; 74 | } 75 | } -------------------------------------------------------------------------------- /src/Entity/Parameters/Order.php: -------------------------------------------------------------------------------- 1 | orders = $orders; 19 | } 20 | 21 | /** 22 | * @param string $field 23 | * @return Order 24 | */ 25 | public static function ascending($field) 26 | { 27 | $order = new self(); 28 | $order->thenAscending($field); 29 | 30 | return $order; 31 | } 32 | 33 | /** 34 | * @param string $field 35 | * @return Order 36 | */ 37 | public static function descending($field) 38 | { 39 | $order = new self(); 40 | $order->thenDescending($field); 41 | 42 | return $order; 43 | } 44 | 45 | /** 46 | * @param string $field 47 | * @return Order 48 | */ 49 | public function thenAscending($field) 50 | { 51 | $this->orders[] = OrderByField::ascending($field); 52 | return $this; 53 | } 54 | 55 | /** 56 | * @param string $field 57 | * @return Order 58 | */ 59 | public function thenDescending($field) 60 | { 61 | $this->orders[$field] = OrderByField::descending($field); 62 | return $this; 63 | } 64 | 65 | /** 66 | * @return OrderByField[] 67 | */ 68 | public function orders() 69 | { 70 | return $this->orders; 71 | } 72 | 73 | /** 74 | * @param OrderByField[] $orders 75 | * @return Order 76 | */ 77 | public static function fromOrders(array $orders) 78 | { 79 | return new self($orders); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Payments/PaymentsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 22 | } 23 | 24 | /** 25 | * @param Payment $payment 26 | * @return Payment|Entity 27 | */ 28 | public function add(Payment $payment) 29 | { 30 | return $this->entityApi->add($payment); 31 | } 32 | 33 | /** 34 | * @param Payment $payment 35 | * @return Payment|Entity 36 | */ 37 | public function edit(Payment $payment) 38 | { 39 | return $this->entityApi->edit($payment); 40 | } 41 | 42 | /** 43 | * @param PaymentId $id 44 | */ 45 | public function delete(PaymentId $id) 46 | { 47 | $this->entityApi->delete($id->id(), Module::payments()); 48 | } 49 | 50 | /** 51 | * @param PaymentId $id 52 | * @return Payment|Entity 53 | */ 54 | public function get(PaymentId $id) 55 | { 56 | return $this->entityApi->get($id->id(), Module::payments()); 57 | } 58 | 59 | /** 60 | * @return Payment[] 61 | */ 62 | public function find(Parameters $parameters = null): array 63 | { 64 | return $this->entityApi->find(Module::payments(), $parameters); 65 | } 66 | 67 | /** 68 | * @return Payment[]|EntityIterator 69 | */ 70 | public function findAll(Parameters $parameters = null): EntityIterator 71 | { 72 | return $this->entityApi->findAll(Module::payments(), $parameters); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Contractors/ContactDetails.php: -------------------------------------------------------------------------------- 1 | phone = $phone; 32 | $this->skype = $skype; 33 | $this->fax = $fax; 34 | $this->email = $email; 35 | $this->url = $url; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function phone() 42 | { 43 | return $this->phone; 44 | } 45 | 46 | /** 47 | * @return string 48 | */ 49 | public function skype() 50 | { 51 | return $this->skype; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function fax() 58 | { 59 | return $this->fax; 60 | } 61 | 62 | /** 63 | * @return string 64 | */ 65 | public function email() 66 | { 67 | return $this->email; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function url() 74 | { 75 | return $this->url; 76 | } 77 | 78 | /** 79 | * @param string $phone 80 | * @return ContactDetails 81 | */ 82 | public function withPhone(string $phone) 83 | { 84 | return new self( 85 | $phone, 86 | $this->skype, 87 | $this->fax, 88 | $this->email, 89 | $this->url 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Contractors/ContactAddress.php: -------------------------------------------------------------------------------- 1 | name = $name; 42 | $this->street = $street; 43 | $this->zip = $zip; 44 | $this->city = $city; 45 | $this->country = $country; 46 | $this->person = $person; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function name() 53 | { 54 | return $this->name; 55 | } 56 | 57 | /** 58 | * @return string 59 | */ 60 | public function street() 61 | { 62 | return $this->street; 63 | } 64 | 65 | /** 66 | * @return string 67 | */ 68 | public function zip() 69 | { 70 | return $this->zip; 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function city() 77 | { 78 | return $this->city; 79 | } 80 | 81 | /** 82 | * @return string 83 | */ 84 | public function country() 85 | { 86 | return $this->country; 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function person() 93 | { 94 | return $this->person; 95 | } 96 | } -------------------------------------------------------------------------------- /src/Notes/Note.php: -------------------------------------------------------------------------------- 1 | objectName = (string)$module; 46 | $this->objectId = $objectId; 47 | $this->text = $text; 48 | } 49 | 50 | /** 51 | * @return null|\Webit\WFirmaSDK\Entity\EntityId|NoteId 52 | */ 53 | public function id() 54 | { 55 | return NoteId::create($this->plainId()); 56 | } 57 | 58 | /** 59 | * @return string 60 | */ 61 | public function objectName() 62 | { 63 | return $this->objectName; 64 | } 65 | 66 | /** 67 | * @return int 68 | */ 69 | public function objectId() 70 | { 71 | return $this->objectId; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function text() 78 | { 79 | return $this->text; 80 | } 81 | 82 | /** 83 | * @param string $text 84 | */ 85 | public function changeText($text) 86 | { 87 | $this->text = $text; 88 | } 89 | } -------------------------------------------------------------------------------- /tests/Vat/Repository/VatCodeIdCachingMapProviderTest.php: -------------------------------------------------------------------------------- 1 | innerProvider = $this->prophesize(VatCodeIdMapProvider::class); 27 | $this->cache = $this->prophesize(CacheInterface::class); 28 | $this->provider = new VatCodeIdCachingMapProvider( 29 | $this->innerProvider->reveal(), 30 | $this->cache->reveal() 31 | ); 32 | } 33 | 34 | /** 35 | * @test 36 | */ 37 | public function itUsesInnerProviderIfCacheNotPopulated() 38 | { 39 | $this->cache->has(Argument::type('string'))->willReturn(false); 40 | $this->innerProvider->getMap()->willReturn($map = ['A' => 1, 'B' => 2]); 41 | $this->cache->set(Argument::type('string'), $map)->shouldBeCalled(); 42 | $this->cache->get(Argument::type('string'))->willReturn($map); 43 | 44 | $this->assertEquals($map, $this->provider->getMap()); 45 | } 46 | 47 | /** 48 | * @test 49 | */ 50 | public function itUsesCacheIfPopulated() 51 | { 52 | $this->cache->has(Argument::type('string'))->willReturn(true); 53 | $this->cache->get(Argument::type('string'))->willReturn($map = ['A' => 1, 'B' => 2]); 54 | $this->innerProvider->getMap()->shouldNotBeCalled(); 55 | $this->cache->get(Argument::type('string'))->willReturn($map); 56 | 57 | $this->assertEquals($map, $this->provider->getMap()); 58 | } 59 | } -------------------------------------------------------------------------------- /src/Invoices/SendParameters.php: -------------------------------------------------------------------------------- 1 | page = $page ?: InvoicePage::invoice(); 45 | $this->leaflet = (bool)$leaflet; 46 | $this->duplicate = (bool)$duplicate; 47 | $this->email = $email; 48 | $this->subject = $subject; 49 | $this->body = $body; 50 | } 51 | 52 | /** 53 | * @return Parameters 54 | */ 55 | public function toActionParameters() 56 | { 57 | $params = array( 58 | new Parameter('page', (string)$this->page), 59 | new Parameter('leaflet', (int)$this->leaflet), 60 | new Parameter('duplicate', (int)$this->duplicate) 61 | ); 62 | 63 | if ($this->email) { 64 | $params[] = new Parameter('email', $this->email); 65 | } 66 | 67 | if ($this->subject) { 68 | $params[] = new Parameter('subject', $this->subject); 69 | } 70 | 71 | if ($this->body) { 72 | $params[] = new Parameter('body', $this->body); 73 | } 74 | 75 | return Parameters::actionParameters($params); 76 | } 77 | } -------------------------------------------------------------------------------- /tests/Vat/Repository/VatCodeIdRepositoryTest.php: -------------------------------------------------------------------------------- 1 | 222, 13 | 'ZW' => 235 14 | ]; 15 | 16 | /** @var VatCodeIdRepository */ 17 | private $repository; 18 | 19 | protected function setUp(): void 20 | { 21 | $this->repository = new VatCodeIdRepository(self::CODE_MAP); 22 | } 23 | 24 | /** 25 | * @param string $code 26 | * @param VatCodeId|null $expectedVatCodeId 27 | * @dataProvider codes 28 | * @test 29 | */ 30 | public function itGetsVatCodeIdByItsStringCode(string $code, ?VatCodeId $expectedVatCodeId) 31 | { 32 | $this->assertEquals($expectedVatCodeId, $this->repository->getByCode($code)); 33 | } 34 | 35 | /** 36 | * @param VatRate $vatRate 37 | * @param VatCodeId|null $expectedVatCodeId 38 | * @dataProvider vatRates 39 | * @test 40 | */ 41 | public function itGetsVatCodeIdByVatRate(VatRate $vatRate, ?VatCodeId $expectedVatCodeId) 42 | { 43 | $this->assertEquals($expectedVatCodeId, $this->repository->getByVatRate($vatRate)); 44 | } 45 | 46 | public function codes() 47 | { 48 | return [ 49 | ['23', new VatCodeId(self::CODE_MAP['23'])], 50 | ['not-mapped', null] 51 | ]; 52 | } 53 | 54 | /** 55 | * @test 56 | */ 57 | public function itGetsAllCodes() 58 | { 59 | $this->assertEquals( 60 | ['23' => new VatCodeId(self::CODE_MAP['23']), 'ZW' => new VatCodeId(self::CODE_MAP['ZW'])], 61 | $this->repository->getAll() 62 | ); 63 | } 64 | 65 | public function vatRates() 66 | { 67 | return [ 68 | [VatRate::fromCode('23'), new VatCodeId(self::CODE_MAP['23'])], 69 | [VatRate::fromVatCodeId($id = new VatCodeId(645)), $id] 70 | ]; 71 | } 72 | } -------------------------------------------------------------------------------- /tests/Vat/Repository/VatCodeIdRepositoryFactoryTest.php: -------------------------------------------------------------------------------- 1 | 222 24 | ]; 25 | 26 | $this->assertInstanceOf(VatCodeIdRepository::class, $repo = VatCodeIdRepositoryFactory::createWithMap($map)); 27 | $this->assertEquals(new VatCodeId(222), $repo->getByCode('23')); 28 | } 29 | 30 | /** 31 | * @test 32 | */ 33 | public function itCreatesRepositoryWithApi() 34 | { 35 | /** @var VatCodesApi|ObjectProphecy $api */ 36 | $api = $this->prophesize(VatCodesApi::class); 37 | $api->findAll(Argument::any())->willReturn([]); 38 | 39 | $this->assertInstanceOf( 40 | VatCodeIdRepository::class, 41 | $repo = VatCodeIdRepositoryFactory::createWithApi($api->reveal()) 42 | ); 43 | $this->assertNull($repo->getByCode('23')); 44 | } 45 | 46 | /** 47 | * @test 48 | */ 49 | public function itCreatesRepositoryWithApiAndCache() 50 | { 51 | /** @var VatCodesApi|ObjectProphecy $api */ 52 | $api = $this->prophesize(VatCodesApi::class); 53 | 54 | $cache = $this->prophesize(CacheInterface::class); 55 | $cache->has(Argument::type('string'))->willReturn(true); 56 | $cache->get(Argument::type('string'))->willReturn(['23' => 222]); 57 | 58 | $this->assertInstanceOf( 59 | VatCodeIdRepository::class, 60 | $repo = VatCodeIdRepositoryFactory::createWithApi($api->reveal(), $cache->reveal()) 61 | ); 62 | 63 | $this->assertEquals(new VatCodeId(222), $repo->getByCode('23')); 64 | } 65 | } -------------------------------------------------------------------------------- /src/InvoiceDeliveries/InvoiceDeliveriesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 17 | } 18 | 19 | /** 20 | * @param InvoiceDelivery $invoiceDelivery 21 | * @return \Webit\WFirmaSDK\Entity\Entity|InvoiceDelivery 22 | */ 23 | public function add(InvoiceDelivery $invoiceDelivery) 24 | { 25 | return $this->entityApi->add($invoiceDelivery); 26 | } 27 | 28 | /** 29 | * @param InvoiceDeliveryId $id 30 | */ 31 | public function delete(InvoiceDeliveryId $id) 32 | { 33 | $this->entityApi->delete($id->id(), Module::invoiceDeliveries()); 34 | } 35 | 36 | /** 37 | * @param Parameters|null $parameters 38 | * @return \Webit\WFirmaSDK\Entity\Entity[]|InvoiceDelivery[] 39 | */ 40 | public function find(Parameters $parameters = null) 41 | { 42 | return $this->entityApi->find(Module::invoiceDeliveries(), $parameters); 43 | } 44 | 45 | /** 46 | * @param Parameters|null $parameters 47 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|InvoiceDelivery[] 48 | */ 49 | public function findAll(Parameters $parameters = null) 50 | { 51 | return $this->entityApi->findAll(Module::invoiceDeliveries(), $parameters); 52 | } 53 | 54 | /** 55 | * @param InvoiceDeliveryId $id 56 | * @return \Webit\WFirmaSDK\Entity\Entity|InvoiceDelivery 57 | */ 58 | public function get(InvoiceDeliveryId $id) 59 | { 60 | return $this->entityApi->get($id->id(), Module::invoiceDeliveries()); 61 | } 62 | 63 | /** 64 | * @param Parameters|null $parameters 65 | * @return int 66 | */ 67 | public function count(Parameters $parameters = null) 68 | { 69 | return $this->entityApi->count(Module::invoiceDeliveries(), $parameters); 70 | } 71 | } -------------------------------------------------------------------------------- /src/Tags/TagsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 20 | } 21 | 22 | /** 23 | * @param Tag $tag 24 | * @return \Webit\WFirmaSDK\Entity\Entity|Tag 25 | */ 26 | public function add(Tag $tag) 27 | { 28 | return $this->entityApi->add($tag); 29 | } 30 | 31 | /** 32 | * @param Tag $tag 33 | * @return \Webit\WFirmaSDK\Entity\Entity|Tag 34 | */ 35 | public function edit(Tag $tag) 36 | { 37 | return $this->entityApi->edit($tag); 38 | } 39 | 40 | /** 41 | * @param TagId $id 42 | */ 43 | public function delete(TagId $id) 44 | { 45 | $this->entityApi->delete($id->id(), Module::tags()); 46 | } 47 | 48 | /** 49 | * @param TagId $id 50 | * @return \Webit\WFirmaSDK\Entity\Entity|Tag 51 | */ 52 | public function get(TagId $id) 53 | { 54 | return $this->entityApi->get($id->id(), Module::tags()); 55 | } 56 | 57 | /** 58 | * @param Parameters|null $parameters 59 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Tag[] 60 | */ 61 | public function find(Parameters $parameters = null) 62 | { 63 | return $this->entityApi->find(Module::tags(), $parameters); 64 | } 65 | 66 | /** 67 | * @param Parameters|null $parameters 68 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|Tag[] 69 | */ 70 | public function findAll(Parameters $parameters = null) 71 | { 72 | return $this->entityApi->findAll(Module::tags(), $parameters); 73 | } 74 | 75 | /** 76 | * @param Parameters|null $parameters 77 | * @return int 78 | */ 79 | public function count(Parameters $parameters = null) 80 | { 81 | return $this->entityApi->count(Module::tags(), $parameters); 82 | } 83 | } -------------------------------------------------------------------------------- /src/Notes/NotesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 20 | } 21 | 22 | /** 23 | * @param Note $note 24 | * @return \Webit\WFirmaSDK\Entity\Entity|Note 25 | */ 26 | public function add(Note $note) 27 | { 28 | return $this->entityApi->add($note); 29 | } 30 | 31 | /** 32 | * @param Note $note 33 | * @return \Webit\WFirmaSDK\Entity\Entity|Note 34 | */ 35 | public function edit(Note $note) 36 | { 37 | return $this->entityApi->edit($note); 38 | } 39 | 40 | /** 41 | * @param NoteId $id 42 | */ 43 | public function delete(NoteId $id) 44 | { 45 | $this->entityApi->delete($id->id(), Module::notes()); 46 | } 47 | 48 | /** 49 | * @param Parameters|null $parameters 50 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Note[] 51 | */ 52 | public function find(Parameters $parameters = null) 53 | { 54 | return $this->entityApi->find(Module::notes(), $parameters); 55 | } 56 | 57 | /** 58 | * @param Parameters|null $parameters 59 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|Note[] 60 | */ 61 | public function findAll(Parameters $parameters = null) 62 | { 63 | return $this->entityApi->findAll(Module::notes(), $parameters); 64 | } 65 | 66 | /** 67 | * @param NoteId $id 68 | * @return \Webit\WFirmaSDK\Entity\Entity|Note 69 | */ 70 | public function get(NoteId $id) 71 | { 72 | return $this->entityApi->get($id->id(), Module::notes()); 73 | } 74 | 75 | /** 76 | * @param Parameters|null $parameters 77 | * @return int 78 | */ 79 | public function count(Parameters $parameters = null) 80 | { 81 | return $this->entityApi->count(Module::notes(), $parameters); 82 | } 83 | } -------------------------------------------------------------------------------- /src/Entity/Response.php: -------------------------------------------------------------------------------- 1 | status = $status; 42 | $this->entityWrapper = new EntityWrapper($entity); 43 | } 44 | 45 | /** 46 | * @return Status 47 | */ 48 | public function status() 49 | { 50 | return $this->status; 51 | } 52 | 53 | /** 54 | * @return Entity 55 | */ 56 | public function entity() 57 | { 58 | return $this->entityWrapper ? $this->entityWrapper->entity() : null; 59 | } 60 | 61 | /** 62 | * @return Entity[] 63 | */ 64 | public function entities() 65 | { 66 | return $this->entityWrapper ? $this->entityWrapper->entities() : array(); 67 | } 68 | 69 | /** 70 | * @return Parameters 71 | */ 72 | public function parameters() 73 | { 74 | return $this->entityWrapper ? $this->entityWrapper->parameters() : null; 75 | } 76 | 77 | /** 78 | * @return File 79 | */ 80 | public function file() 81 | { 82 | return $this->file; 83 | } 84 | 85 | /** 86 | * @param File $file 87 | * @return Response 88 | */ 89 | public static function fileResponse(File $file) 90 | { 91 | $response = new self(new Status((string)StatusCode::ok())); 92 | $response->file = $file; 93 | 94 | return $response; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/JMS/JmsApiSerialiser.php: -------------------------------------------------------------------------------- 1 | serializer = $serializer; 25 | } 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function serialise(Request $request) 31 | { 32 | $context = SerializationContext::create(); 33 | $context->setAttribute('module', $request->module()); 34 | $context->setGroups(array('request', sprintf('%sRequest', $request->action()))); 35 | 36 | try { 37 | return $this->serializer->serialize($request, 'xml', $context); 38 | } catch (RuntimeException $e) { 39 | throw SerialisationException::createForRequest($request, 0, $e); 40 | } 41 | 42 | } 43 | 44 | /** 45 | * @inheritdoc 46 | */ 47 | public function deserialise($response, Request $request) 48 | { 49 | $context = DeserializationContext::create(); 50 | $context->setAttribute('module', $request->module()); 51 | $context->setGroups(array("response", sprintf('%sResponse', $request->action()))); 52 | 53 | try { 54 | return $this->serializer->deserialize( 55 | $response, 56 | 'Webit\WFirmaSDK\Entity\Response', 57 | 'xml', 58 | $context 59 | ); 60 | } catch (RuntimeException $e) { 61 | throw DeserialisationException::createForRequest($request, 0, $e); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Series/SeriesApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 21 | } 22 | 23 | /** 24 | * @param Series $series 25 | * @return Series|Entity 26 | */ 27 | public function add(Series $series) 28 | { 29 | return $this->entityApi->add($series); 30 | } 31 | 32 | /** 33 | * @param Series $series 34 | * @return Series|Entity 35 | */ 36 | public function edit(Series $series) 37 | { 38 | return $this->entityApi->edit($series); 39 | } 40 | 41 | /** 42 | * @param SeriesId $id 43 | * @return \Webit\WFirmaSDK\Entity\Response 44 | */ 45 | public function delete(SeriesId $id) 46 | { 47 | return $this->entityApi->delete($id->id(), Module::series()); 48 | } 49 | 50 | /** 51 | * @param Parameters|null $parameters 52 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Series[] 53 | */ 54 | public function find(Parameters $parameters = null) 55 | { 56 | return $this->entityApi->find(Module::series(), $parameters); 57 | } 58 | 59 | /** 60 | * @param Parameters|null $parameters 61 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Series[] 62 | */ 63 | public function findAll(Parameters $parameters = null) 64 | { 65 | return $this->entityApi->findAll(Module::series(), $parameters); 66 | } 67 | 68 | /** 69 | * @param SeriesId $id 70 | * @return \Webit\WFirmaSDK\Entity\Entity|Series 71 | */ 72 | public function get(SeriesId $id) 73 | { 74 | return $this->entityApi->get($id->id(), Module::series()); 75 | } 76 | 77 | /** 78 | * @param Parameters|null $parameters 79 | * @return int 80 | */ 81 | public function count(Parameters $parameters = null) 82 | { 83 | return $this->entityApi->count(Module::series(), $parameters); 84 | } 85 | } -------------------------------------------------------------------------------- /tests/Vat/VatCodeSerialisationTest.php: -------------------------------------------------------------------------------- 1 | 26 | 27 | 613 28 | 29 | 14.00 30 | 31 | reduced 32 | 63 33 | 2014-10-23 12:39:11 34 | 2014-10-23 12:39:12 35 | 36 | 170 37 | 38 | 39 | 40 | 2012-01-01 41 | 2012-12-31 42 | 43 | 44 | 45 | XML; 46 | 47 | /** @var VatCode $vatCode */ 48 | $vatCode = $this->deserialiseEntity($xml); 49 | 50 | $this->assertInstanceOf('Webit\WFirmaSDK\Vat\VatCode', $vatCode); 51 | $this->assertEquals(VatCodeId::create(613), $vatCode->id()); 52 | $this->assertSame('14%', $vatCode->label()); 53 | $this->assertSame(14.00, $vatCode->rate()); 54 | $this->assertSame('', $vatCode->code()); 55 | $this->assertEquals(Type::reduced(), $vatCode->type()); 56 | $this->assertSame(63, $vatCode->priority()); 57 | $this->assertEquals(new DeclarationCountryId(170), $vatCode->declarationCountryId()); 58 | 59 | $periods = $vatCode->periods(); 60 | $this->assertEquals(1, count($periods)); 61 | 62 | $this->assertEquals( 63 | \DateTime::createFromFormat('Y-m-d', '2012-01-01', new \DateTimeZone('Europe/Warsaw')), 64 | $periods[0]->start() 65 | ); 66 | 67 | $this->assertEquals( 68 | \DateTime::createFromFormat('Y-m-d', '2012-12-31', new \DateTimeZone('Europe/Warsaw')), 69 | $periods[0]->stop() 70 | ); 71 | } 72 | } -------------------------------------------------------------------------------- /src/Contractors/ContractorsApi.php: -------------------------------------------------------------------------------- 1 | entityApi = $entityApi; 20 | } 21 | 22 | /** 23 | * @param Contractor $contractor 24 | * @return \Webit\WFirmaSDK\Entity\Entity|Contractor 25 | */ 26 | public function add(Contractor $contractor) 27 | { 28 | return $this->entityApi->add($contractor); 29 | } 30 | 31 | /** 32 | * @param Contractor $contractor 33 | * @return \Webit\WFirmaSDK\Entity\Entity|Contractor 34 | */ 35 | public function edit(Contractor $contractor) 36 | { 37 | return $this->entityApi->edit($contractor); 38 | } 39 | 40 | /** 41 | * @param ContractorId $id 42 | */ 43 | public function delete(ContractorId $id) 44 | { 45 | $this->entityApi->delete($id->id(), Module::contractors()); 46 | } 47 | 48 | /** 49 | * @param Parameters|null $parameters 50 | * @return \Webit\WFirmaSDK\Entity\Entity[]|Contractor[] 51 | */ 52 | public function find(Parameters $parameters = null) 53 | { 54 | return $this->entityApi->find(Module::contractors(), $parameters); 55 | } 56 | 57 | /** 58 | * @param Parameters|null $parameters 59 | * @return \Webit\WFirmaSDK\Entity\Entity[]|\Webit\WFirmaSDK\Entity\EntityIterator|Contractor[] 60 | */ 61 | public function findAll(Parameters $parameters = null) 62 | { 63 | return $this->entityApi->findAll(Module::contractors(), $parameters); 64 | } 65 | 66 | /** 67 | * @param ContractorId $id 68 | * @return \Webit\WFirmaSDK\Entity\Entity|Contractor 69 | */ 70 | public function get(ContractorId $id) 71 | { 72 | return $this->entityApi->get($id->id(), Module::contractors()); 73 | } 74 | 75 | /** 76 | * @param Parameters|null $parameters 77 | * @return int 78 | */ 79 | public function count(Parameters $parameters = null) 80 | { 81 | return $this->entityApi->count(Module::contractors(), $parameters); 82 | } 83 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/BrowserFactory.php: -------------------------------------------------------------------------------- 1 | baseUrl = $baseUrl; 29 | $this->curlOptions = $curlOptions; 30 | } 31 | 32 | /** 33 | * @param Auth $auth 34 | * @return Browser 35 | */ 36 | public function create(Auth $auth): Browser 37 | { 38 | $httpFactory = new Psr17Factory(); 39 | $browser = new Browser(new Curl($httpFactory, $this->curlOptions), $httpFactory); 40 | 41 | $browser->addMiddleware(new BaseUrlMiddleware($this->baseUrl)); 42 | $browser->addMiddleware($this->authMiddleware($auth)); 43 | 44 | if ($companyId = $auth->companyId()) { 45 | $browser->addMiddleware(new CompanyIdMiddleware($companyId)); 46 | } 47 | 48 | return $browser; 49 | } 50 | 51 | /** 52 | * Creates the middleware supporting given Auth implementation 53 | * 54 | * @param Auth $auth the auth implementation 55 | * @return MiddlewareInterface the middleware supporting given auth implementation 56 | * @throws \InvalidArgumentException when given auth implementation is not supported 57 | */ 58 | private function authMiddleware(Auth $auth): MiddlewareInterface 59 | { 60 | switch (true) { 61 | case $auth instanceof BasicAuth: 62 | return new BasicAuthMiddleware($auth->username(), $auth->password()); 63 | case $auth instanceof ApiKeysAuth: 64 | return new ApiKeysAuthMiddleware($auth); 65 | default: 66 | throw new \InvalidArgumentException( 67 | sprintf("Auth method of \"%s\" is not supported.", get_class($auth)) 68 | ); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/DeclarationCountries/DeclarationCountry.php: -------------------------------------------------------------------------------- 1 | ") 41 | * @JMS\SerializedName("created") 42 | * @JMS\Groups({"response"}) 43 | */ 44 | private $created; 45 | 46 | /** 47 | * @var \DateTime 48 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") 49 | * @JMS\SerializedName("created") 50 | * @JMS\Groups({"response"}) 51 | */ 52 | private $modified; 53 | 54 | private function __construct() 55 | { 56 | } 57 | 58 | /** 59 | * @return null|EntityId|DeclarationCountryId 60 | */ 61 | public function id() 62 | { 63 | return DeclarationCountryId::create($this->plainId()); 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function name() 70 | { 71 | return $this->name; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function code() 78 | { 79 | return $this->code; 80 | } 81 | 82 | /** 83 | * @return int 84 | */ 85 | public function priority() 86 | { 87 | return $this->priority; 88 | } 89 | 90 | /** 91 | * @return \DateTime 92 | */ 93 | public function created() 94 | { 95 | return $this->created; 96 | } 97 | 98 | /** 99 | * @return \DateTime 100 | */ 101 | public function modified() 102 | { 103 | return $this->modified; 104 | } 105 | } -------------------------------------------------------------------------------- /src/Invoices/Currency.php: -------------------------------------------------------------------------------- 1 | currency = $currency; 43 | $this->currencyExchange = $currencyExchange; 44 | $this->currencyLabel = $currencyLabel; 45 | $this->currencyDate = $currencyDate; 46 | $this->priceCurrencyExchange = $priceCurrencyExchange; 47 | $this->goodPriceGroupCurrencyExchange = $goodPriceGroupCurrencyExchange; 48 | } 49 | 50 | /** 51 | * @return string 52 | */ 53 | public function currency() 54 | { 55 | return $this->currency; 56 | } 57 | 58 | /** 59 | * @return float 60 | */ 61 | public function currencyExchange() 62 | { 63 | return $this->currencyExchange; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function currencyLabel() 70 | { 71 | return $this->currencyLabel; 72 | } 73 | 74 | /** 75 | * @return \DateTime 76 | */ 77 | public function currencyDate() 78 | { 79 | return $this->currencyDate; 80 | } 81 | 82 | /** 83 | * @return float 84 | */ 85 | public function priceCurrencyExchange() 86 | { 87 | return $this->priceCurrencyExchange; 88 | } 89 | 90 | /** 91 | * @return float 92 | */ 93 | public function goodPriceGroupCurrencyExchange() 94 | { 95 | return $this->goodPriceGroupCurrencyExchange; 96 | } 97 | } -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Buzz/BuzzRequestExecutor.php: -------------------------------------------------------------------------------- 1 | browser = $browser; 38 | $this->serialiser = $serialiser; 39 | $this->responseValidator = new ResponseValidator(); 40 | $this->logger = $logger ?: new NullLogger(); 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function execute(Request $request) 47 | { 48 | try { 49 | $input = (string)$this->serialiser->serialise($request); 50 | 51 | $this->logger->debug( 52 | $input, 53 | array( 54 | 'request' => $request->requestUrl() 55 | ) 56 | ); 57 | 58 | /** @var ResponseInterface $response */ 59 | $response = $this->browser->post( 60 | $url = $request->requestUrl(), 61 | array(), 62 | $input 63 | ); 64 | } catch (\Exception $e) { 65 | throw ApiCallExecutionException::create($request, null, $e); 66 | } 67 | 68 | $this->logger->debug( 69 | (string)$response->getBody(), 70 | array( 71 | 'response' => $request->requestUrl() 72 | ) 73 | ); 74 | 75 | $this->responseValidator->validate( 76 | $request, 77 | $apiResponse = $this->serialiser->deserialise((string)$response->getBody(), $request) 78 | ); 79 | 80 | return $apiResponse; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/Serialiser/JMS/RequestResponseSerializationListener.php: -------------------------------------------------------------------------------- 1 | Events::PRE_SERIALIZE, 22 | 'method' => 'preRequestSerialize', 23 | 'class' => 'Webit\WFirmaSDK\Entity\Request', 24 | 'format' => 'xml' 25 | ), 26 | array( 27 | 'event' => Events::PRE_DESERIALIZE, 28 | 'method' => 'preResponseDeserialize', 29 | 'class' => 'Webit\WFirmaSDK\Entity\Response', 30 | 'format' => 'xml' 31 | ) 32 | ); 33 | } 34 | 35 | public function preRequestSerialize(PreSerializeEvent $event) 36 | { 37 | $this->updateEntityWrapper('Webit\WFirmaSDK\Entity\Request', $event->getContext()); 38 | } 39 | 40 | public function preResponseDeserialize(PreDeserializeEvent $event) 41 | { 42 | $this->updateEntityWrapper('Webit\WFirmaSDK\Entity\Response', $event->getContext()); 43 | } 44 | 45 | private function updateEntityWrapper($className, Context $context) 46 | { 47 | /** @var Module $module */ 48 | $module = $context->getAttribute('module'); 49 | if (!$module) { 50 | new \InvalidArgumentException('Missing module'); 51 | } 52 | 53 | $metaClass = $context->getMetadataFactory()->getMetadataForClass($className); 54 | $metaClass->propertyMetadata['entityWrapper']->serializedName = $module->name(); 55 | 56 | $metaWrapperClass = $context->getMetadataFactory()->getMetadataForClass('Webit\WFirmaSDK\Entity\EntityWrapper'); 57 | $metaWrapperClass->propertyMetadata['entities']->serializedName = (string)$module; 58 | $metaWrapperClass->propertyMetadata['entities']->type = array( 59 | 'name' => 'array', 60 | 'params' => array( 61 | array( 62 | 'name' => $module->entityClass() 63 | ) 64 | ) 65 | ); 66 | 67 | $metaWrapperClass->propertyMetadata['entities']->xmlEntryName = $module->entityName(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Tags/TagIds.php: -------------------------------------------------------------------------------- 1 | setIds($ids); 27 | } 28 | 29 | /** 30 | * @return TagId[] 31 | */ 32 | public function ids() 33 | { 34 | $arIds = $this->ids ? explode(',', $this->ids) : array(); 35 | 36 | array_walk($arIds, function (&$item) { 37 | $item = new TagId(trim($item, '()')); 38 | }); 39 | 40 | return $arIds; 41 | } 42 | 43 | /** 44 | * @param TagId $tagId 45 | * @return TagIds 46 | */ 47 | public function withTagId(TagId $tagId) 48 | { 49 | $ids = $this->ids(); 50 | $ids[] = $tagId; 51 | $ids = array_unique($ids); 52 | 53 | return new self($ids); 54 | } 55 | 56 | /** 57 | * @param TagId $tagId 58 | * @return $this|TagIds 59 | */ 60 | public function withoutTagId(TagId $tagId) 61 | { 62 | $ids = $this->ids(); 63 | $key = array_search($tagId, $ids); 64 | if ($key === false) { 65 | return $this; 66 | } 67 | 68 | unset($ids[$key]); 69 | 70 | return new self(array_values($ids)); 71 | } 72 | 73 | /** 74 | * @inheritdoc 75 | */ 76 | public function getIterator(): \Traversable 77 | { 78 | return new \ArrayIterator($this->ids()); 79 | } 80 | 81 | private function setIds(array $ids) 82 | { 83 | if (!$ids) { 84 | $this->ids = null; 85 | return; 86 | } 87 | 88 | $arTags = array(); 89 | /** @var TagId $tagId */ 90 | foreach ($ids as $tagId) { 91 | if (!($tagId instanceof TagId)) { 92 | throw new \InvalidArgumentException('Id must be an instance of TagId.'); 93 | } 94 | 95 | $arTags[] = sprintf('(%s)', $tagId); 96 | } 97 | 98 | $this->ids = implode(',', array_unique($arTags)); 99 | } 100 | 101 | /** 102 | * @inheritdoc 103 | */ 104 | public function count(): int 105 | { 106 | $ids = $this->ids(); 107 | 108 | return count($ids); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Vat/VatContent.php: -------------------------------------------------------------------------------- 1 | plainId()); 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function objectName() 77 | { 78 | return $this->objectName; 79 | } 80 | 81 | /** 82 | * @return int 83 | */ 84 | public function objectId() 85 | { 86 | return $this->objectId; 87 | } 88 | 89 | /** 90 | * @return float 91 | */ 92 | public function netto() 93 | { 94 | return $this->netto; 95 | } 96 | 97 | /** 98 | * @return float 99 | */ 100 | public function tax() 101 | { 102 | return $this->tax; 103 | } 104 | 105 | /** 106 | * @return float 107 | */ 108 | public function brutto() 109 | { 110 | return $this->brutto; 111 | } 112 | 113 | /** 114 | * @return VatCodeId 115 | */ 116 | public function vatCodeId() 117 | { 118 | return $this->vatCodeId; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /tests/Invoices/InvoiceStubTrait.php: -------------------------------------------------------------------------------- 1 | newContractor(), 21 | Payment::create( 22 | PaymentMethod::transfer(), 23 | $this->faker()->dateTimeBetween('now', '+30 days') 24 | ), 25 | Type::vat(), 26 | $seriesId, 27 | new \DateTime(), 28 | null, 29 | null, 30 | $currency 31 | ); 32 | 33 | $invoice->addInvoiceContent( 34 | InvoicesContent::fromName( 35 | $this->faker()->colorName, 36 | 'szt.', 37 | mt_rand(1, 5), 38 | $this->faker()->randomFloat(2, 100, 1000), 39 | 23 40 | ) 41 | ); 42 | 43 | $invoice->addInvoiceContent( 44 | InvoicesContent::fromName( 45 | $this->faker()->colorName, 46 | 'szt.', 47 | mt_rand(1, 5), 48 | $this->faker()->randomFloat(2, 100, 1000), 49 | 23 50 | ) 51 | ); 52 | 53 | return $invoice; 54 | } 55 | 56 | private function newInvoiceContent(): InvoicesContent 57 | { 58 | return InvoicesContent::fromName( 59 | $this->faker()->colorName, 60 | 'szt.', 61 | mt_rand(1, 5), 62 | $this->faker()->randomFloat(2, 100, 1000), 63 | 23 64 | ); 65 | } 66 | 67 | /** 68 | * @return Contractor 69 | */ 70 | private function newContractor(): Contractor 71 | { 72 | return new Contractor( 73 | $this->faker()->company, 74 | null, 75 | '1234563218', 76 | null, 77 | new InvoiceAddress( 78 | $this->faker()->streetAddress, 79 | $this->faker()->postcode, 80 | $this->faker()->city, 81 | 'PL' 82 | ), 83 | new ContactAddress( 84 | $this->faker()->company, 85 | $this->faker()->streetAddress, 86 | $this->faker()->postcode, 87 | $this->faker()->city, 88 | 'PL', 89 | $this->faker()->name 90 | ) 91 | ); 92 | } 93 | } -------------------------------------------------------------------------------- /src/Vat/ServiceCode.php: -------------------------------------------------------------------------------- 1 | type = strtolower($type); 16 | } 17 | 18 | /** 19 | * @return Type 20 | */ 21 | public static function vat() 22 | { 23 | return new self('normal'); 24 | } 25 | 26 | /** 27 | * @return Type 28 | */ 29 | public static function proformaVat() 30 | { 31 | return new self('proforma'); 32 | } 33 | 34 | /** 35 | * @return Type 36 | */ 37 | public static function offerVat() 38 | { 39 | return new self('offer'); 40 | } 41 | 42 | /** 43 | * @return Type 44 | */ 45 | public static function nonFiscalReceiptVat() 46 | { 47 | return new self('receipt_normal'); 48 | } 49 | 50 | /** 51 | * @return Type 52 | */ 53 | public static function receiptVat() 54 | { 55 | return new self('receipt_fiscal_normal'); 56 | } 57 | 58 | /** 59 | * @return Type 60 | */ 61 | public static function otherIncomeVat() 62 | { 63 | return new self('income_normal'); 64 | } 65 | 66 | /** 67 | * @return Type 68 | */ 69 | public static function bill() 70 | { 71 | return new self('bill'); 72 | } 73 | 74 | /** 75 | * @return Type 76 | */ 77 | public static function proformaBill() 78 | { 79 | return new self('proforma_bill'); 80 | } 81 | 82 | /** 83 | * @return Type 84 | */ 85 | public static function offerBill() 86 | { 87 | return new self('offer_bill'); 88 | } 89 | 90 | /** 91 | * @return Type 92 | */ 93 | public static function nonFiscalReceiptBill() 94 | { 95 | return new self('receipt_bill'); 96 | } 97 | 98 | /** 99 | * @return Type 100 | */ 101 | public static function receiptBill() 102 | { 103 | return new self('receipt_fiscal_bill'); 104 | } 105 | 106 | /** 107 | * @return Type 108 | */ 109 | public static function otherIncomeBill() 110 | { 111 | return new self('income_bill'); 112 | } 113 | 114 | /** 115 | * @return Type 116 | */ 117 | public static function draftVat() 118 | { 119 | return new self('normal_draft'); 120 | } 121 | 122 | /** 123 | * @param string $type 124 | * @return Type 125 | * @internal 126 | */ 127 | public static function fromString($type) 128 | { 129 | return new self($type); 130 | } 131 | 132 | /** 133 | * @inheritdoc 134 | */ 135 | public function __toString() 136 | { 137 | return $this->type; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Goods/Stock.php: -------------------------------------------------------------------------------- 1 | count = $count; 40 | $this->min = $min; 41 | $this->max = $max; 42 | $this->secure = $secure; 43 | $this->reserved = $reserved; 44 | } 45 | 46 | /** 47 | * @return float|null 48 | */ 49 | public function count(): ?float 50 | { 51 | return $this->count; 52 | } 53 | 54 | /** 55 | * @return float|null 56 | */ 57 | public function min(): ?float 58 | { 59 | return $this->min; 60 | } 61 | 62 | /** 63 | * @return float|null 64 | */ 65 | public function max(): ?float 66 | { 67 | return $this->max; 68 | } 69 | 70 | /** 71 | * @return float|null 72 | */ 73 | public function secure(): ?float 74 | { 75 | return $this->secure; 76 | } 77 | 78 | /** 79 | * @return float|null 80 | */ 81 | public function reserved(): ?float 82 | { 83 | return $this->reserved; 84 | } 85 | 86 | /** 87 | * @param float|null $count 88 | * @return Stock 89 | */ 90 | public function setCount(?float $count): Stock 91 | { 92 | return new self($count, $this->min, $this->max, $this->secure, $this->reserved); 93 | } 94 | 95 | /** 96 | * @param float|null $min 97 | * @return Stock 98 | */ 99 | public function setMin(?float $min): Stock 100 | { 101 | return new self($this->count, $min, $this->max, $this->secure, $this->reserved); 102 | } 103 | 104 | /** 105 | * @param float|null $max 106 | * @return Stock 107 | */ 108 | public function setMax(?float $max): Stock 109 | { 110 | return new self($this->count, $this->min, $max, $this->secure, $this->reserved); 111 | } 112 | 113 | /** 114 | * @param float|null $secure 115 | * @return Stock 116 | */ 117 | public function withSecure(?float $secure): Stock 118 | { 119 | return new self($this->count, $this->min, $this->max, $secure, $this->reserved); 120 | } 121 | } -------------------------------------------------------------------------------- /tests/Entity/AbstractApiTestCase.php: -------------------------------------------------------------------------------- 1 | logger((bool)getenv('debug_api_messages')) 30 | ) 31 | ); 32 | } catch (\Exception $e) { 33 | throw new \RuntimeException('Cannot create EntityApiFactory', 0, $e); 34 | } 35 | 36 | return $factory->create($this->basicAuth()); 37 | } 38 | 39 | private function logger(bool $logMessages): LoggerInterface 40 | { 41 | if (!$logMessages) { 42 | return new NullLogger(); 43 | } 44 | 45 | return new Logger( 46 | 'API', 47 | array( 48 | new StreamHandler('php://stdout') 49 | ) 50 | ); 51 | } 52 | 53 | private function basicAuth(): BasicAuth 54 | { 55 | $username = getenv('wFirma.username'); 56 | $password = getenv('wFirma.password'); 57 | if (!($username && $password)) { 58 | $this->markTestSkipped('Set wFirma.username and wFirma.password in your phpunit.xml file.'); 59 | } 60 | 61 | return new BasicAuth(getenv('wFirma.username'), getenv('wFirma.password'), $this->companyId()); 62 | } 63 | 64 | private function apiKeysAuth(): ApiKeysAuth 65 | { 66 | $accessKey = getenv('wFirma.access_key'); 67 | $secretKey = getenv('wFirma.secret_key'); 68 | $appKey = getenv('wFirma.app_key'); 69 | if (!($accessKey && $secretKey && $appKey)) { 70 | $this->markTestSkipped('Set wFirma.access_key, wFirma.secret_key and wFirma.app_key in your phpunit.xml file.'); 71 | } 72 | 73 | return new ApiKeysAuth(getenv('wFirma.access_key'), getenv('wFirma.secret_key'), getenv('wFirma.app_key'), $this->companyId()); 74 | } 75 | 76 | /** 77 | * @return null|int 78 | */ 79 | private function companyId(): ?int 80 | { 81 | return (int)getenv('wFirma.company_id') ?? null; 82 | } 83 | 84 | protected function invoicesApi(): InvoicesApi 85 | { 86 | return new InvoicesApi($this->entityApi()); 87 | } 88 | 89 | protected function paymentsApi(): PaymentsApi 90 | { 91 | return new PaymentsApi($this->entityApi()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Entity/Infrastructure/ResponseValidator.php: -------------------------------------------------------------------------------- 1 | status()->code()) { 27 | case StatusCode::error(): 28 | throw ValidationException::create($request, $response); 29 | case StatusCode::accessDenied(): 30 | throw AccessDenied::create($request, $response); 31 | case StatusCode::actionNotFound(): 32 | throw ActionNotFound::create($request, $response); 33 | case StatusCode::auth(): 34 | throw AuthException::create($request, $response); 35 | case StatusCode::authFailedLimitWait5Minutes(): 36 | throw AuthFailedLimitWait5MinutesException::create($request, $response); 37 | case StatusCode::companyIdRequired(): 38 | throw CompanyIdRequiredException::create($request, $response); 39 | case StatusCode::deniedScopeRequested(): 40 | throw DeniedScopeRequested::create($request, $response); 41 | case StatusCode::fatal(): 42 | throw FatalException::create($request, $response); 43 | case StatusCode::inputError(): 44 | throw InputErrorException::create($request, $response); 45 | case StatusCode::notFound(): 46 | case StatusCode::notFoundBogus(): 47 | throw NotFoundException::create($request, $response); 48 | case StatusCode::outOfService(): 49 | throw OutOfServiceException::create($request, $response); 50 | case StatusCode::snapshotLock(): 51 | throw SnapshotLockException::create($request, $response); 52 | case StatusCode::totalExecutionTimeLimitExceeded(): 53 | throw TotalRequestsLimitExceededException::create($request, $response); 54 | case StatusCode::totalRequestsLimitExceeded(): 55 | throw TotalRequestsLimitExceededException::create($request, $response); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Goods/GoodsApiTest.php: -------------------------------------------------------------------------------- 1 | api = new GoodsApi($this->entityApi()); 21 | } 22 | 23 | public function tearDown(): void 24 | { 25 | foreach ($this->goods as $good) { 26 | try { 27 | $this->api->delete($good->id()); 28 | } catch (NotFoundException $e) { 29 | continue; 30 | } 31 | } 32 | } 33 | 34 | public function testAdd(): void 35 | { 36 | $good = $this->createGood(); 37 | 38 | $this->goods[] = $createdGood = $this->api->add($good); 39 | $this->assertGood($good, $createdGood); 40 | $this->assertInstanceOf(Good::class, $createdGood); 41 | } 42 | 43 | public function testEdit(): void 44 | { 45 | $this->goods[] = $good = $this->api->add($this->createGood()); 46 | 47 | $good->setName($newName = $this->faker()->streetName); 48 | $editedGood = $this->api->edit($good); 49 | $this->assertEquals($newName, $editedGood->name()); 50 | } 51 | 52 | public function testDelete(): void 53 | { 54 | $this->goods[] = $good = $this->api->add($this->createGood()); 55 | $this->api->delete($good->id()); 56 | 57 | $this->expectException(NotFoundException::class); 58 | $this->api->get($good->id()); 59 | } 60 | 61 | private function assertGood(Good $expected, Good $actual): void 62 | { 63 | $this->assertEquals($expected->name(), $actual->name()); 64 | $this->assertEquals($expected->code(), $actual->code()); 65 | $this->assertEquals($expected->description(), $actual->description()); 66 | $this->assertEquals($expected->type(), $actual->type()); 67 | $this->assertEquals($expected->priceType(), $actual->priceType()); 68 | 69 | if ($expected->price()->priceType() == PriceType::netto()) { 70 | $this->assertEquals($expected->netto(), $actual->netto()); 71 | $this->assertNotNull($actual->brutto()); 72 | } else { 73 | $this->assertEquals($expected->brutto(), $actual->brutto()); 74 | $this->assertNotNull($actual->netto()); 75 | } 76 | } 77 | 78 | private function createGood(): Good 79 | { 80 | $netAmount = $this->faker()->randomNumber(5); 81 | 82 | return new Good( 83 | $this->faker()->colorName, 84 | 'usługa', 85 | Price::createFromNetPrice($netAmount, VatRate::VAT23()), 86 | $this->faker()->word, 87 | Type::service(), 88 | null, 89 | $this->faker()->sentence, 90 | new Dimensions(24.5, 12.3, 11.1, 10.9) 91 | ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Payments/PaymentAmount.php: -------------------------------------------------------------------------------- 1 | value = round($value, 2); 41 | $this->account = $account; 42 | $this->valuePln = $valuePln !== null ? round($valuePln, 2) : null; 43 | $this->exchangeRate = $exchangeRate; 44 | $this->nbpLabel = $nbpLabel; 45 | $this->rateDate = $rateDate; 46 | } 47 | 48 | /** 49 | * @return ?float 50 | */ 51 | public function value(): ?float 52 | { 53 | return $this->value; 54 | } 55 | 56 | /** 57 | * @return ?string 58 | */ 59 | public function account(): ?string 60 | { 61 | return $this->account; 62 | } 63 | 64 | /** 65 | * @return ?float 66 | */ 67 | public function valuePln(): ?float 68 | { 69 | return $this->valuePln; 70 | } 71 | 72 | /** 73 | * @return ?float 74 | */ 75 | public function exchangeRate(): ?float 76 | { 77 | return $this->exchangeRate; 78 | } 79 | 80 | /** 81 | * @return ?string 82 | */ 83 | public function nbpLabel(): ?string 84 | { 85 | return $this->nbpLabel; 86 | } 87 | 88 | /** 89 | * @return ?\DateTime 90 | */ 91 | public function rateDate(): ?\DateTime 92 | { 93 | return $this->rateDate; 94 | } 95 | 96 | /** 97 | * @param float 98 | * @param float|null $valuePln 99 | * @return PaymentAmount 100 | */ 101 | public static function forPlnAccount(float $value, ?float $valuePln = null): PaymentAmount 102 | { 103 | return new self($value, self::ACCOUNT_PLN, $valuePln); 104 | } 105 | 106 | /** 107 | * @param float 108 | * @param float|null $valuePln 109 | * @return PaymentAmount 110 | */ 111 | public static function forCurrencyAccount(float $value, ?float $valuePln = null): PaymentAmount 112 | { 113 | return new self($value, self::ACCOUNT_CURRENCY, $valuePln); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /tests/Tags/TagIdsTest.php: -------------------------------------------------------------------------------- 1 | serialiser = $this->jmsSerializer(); 17 | } 18 | 19 | /** 20 | * @test 21 | */ 22 | public function it_creates_an_instance_with_tag_id() 23 | { 24 | $tagIds = new TagIds(); 25 | 26 | $this->assertEquals( 27 | new TagIds(array(TagId::create(123))), 28 | $tagIds->withTagId(TagId::create(123)) 29 | ); 30 | } 31 | 32 | /** 33 | * @test 34 | */ 35 | public function it_creates_an_instance_without_tag_id() 36 | { 37 | $tagIds = new TagIds( 38 | array( 39 | TagId::create(123), 40 | TagId::create(321) 41 | ) 42 | ); 43 | 44 | $this->assertEquals( 45 | new TagIds(array(TagId::create(321))), 46 | $tagIds->withoutTagId(TagId::create(123)) 47 | ); 48 | } 49 | 50 | /** 51 | * @test 52 | */ 53 | public function it_is_traversable() 54 | { 55 | $ids = array(); 56 | 57 | $tagIds = new TagIds( 58 | array( 59 | $ids[] = TagId::create(123), 60 | $ids[] = TagId::create(321) 61 | ) 62 | ); 63 | 64 | foreach ($tagIds as $i => $tagId) { 65 | $this->assertEquals($ids[$i], $tagId); 66 | } 67 | } 68 | 69 | /** 70 | * @test 71 | */ 72 | public function it_is_countable() 73 | { 74 | $tagIds = new TagIds( 75 | array( 76 | $ids[] = TagId::create(123), 77 | $ids[] = TagId::create(321) 78 | ) 79 | ); 80 | 81 | $this->assertEquals(2, count($tagIds)); 82 | } 83 | 84 | /** 85 | * @test 86 | */ 87 | public function testSerialisation() 88 | { 89 | $ids = new TagIds(array( 90 | TagId::create('123'), 91 | TagId::create('321') 92 | )); 93 | 94 | 95 | $expectedXml = << 97 | (123),(321) 98 | 99 | XML; 100 | 101 | $this->assertEquals($expectedXml, $this->serialiser->serialize($ids, 'xml')); 102 | } 103 | 104 | /** 105 | * @test 106 | */ 107 | public function testDeserialisation() 108 | { 109 | $xml = << 111 | (123),(321) 112 | XML; 113 | $expectedIds = new TagIds(array( 114 | TagId::create('123'), 115 | TagId::create('321') 116 | )); 117 | 118 | $this->assertEquals( 119 | $expectedIds, 120 | $this->serialiser->deserialize($xml, 'Webit\WFirmaSDK\Tags\TagIds', 'xml') 121 | ); 122 | } 123 | } 124 | --------------------------------------------------------------------------------