PHPackages                             vdhicts/wefact-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. vdhicts/wefact-api-client

ActiveLibrary[API Development](/categories/api)

vdhicts/wefact-api-client
=========================

A client for the API of WeFact

v7.0.0(2mo ago)42.7k↑53.3%MITPHPPHP &gt;=8.2CI passing

Since Nov 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/vdhicts/wefact-api-client)[ Packagist](https://packagist.org/packages/vdhicts/wefact-api-client)[ Docs](https://github.com/vdhicts/wefact-api-client)[ RSS](/packages/vdhicts-wefact-api-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (9)Used By (0)

wefact-api-client
=================

[](#wefact-api-client)

Easy WeFact API client

Requirements
------------

[](#requirements)

This package requires at least PHP 8.2.

Installation
------------

[](#installation)

This package can be used in any PHP project or with any framework.

You can install the package via composer:

`composer require vdhicts/wefact-api-client`

Usage
-----

[](#usage)

This package is just an easy client for using the WeFact API. Please refer to the [API documentation](https://www.wefact.nl/api/) for more information about the requests.

### Getting started

[](#getting-started)

```
use Vdhicts\WeFact\WeFact;
use Vdhicts\WeFact\WeFactRequest;
use Vdhicts\WeFact\Enums\WeFactController;

// Initialize the client
$client = new WeFact($apiKey);

// Perform the request
$request = new WeFactRequest(WeFactController::CREDITOR, 'list');
$response = $client->request($request);

if ($response->ok()) {
    $response->json('creditors');
}
```

Or if you need to provide extra parameters (i.e. for a 'add' request):

```
$request = new WeFactRequest(WeFactController::CREDITOR, 'add', [
    'CompanyName' => 'Vdhicts',
]);
$response = $client->request($request);
```

### Extending the client

[](#extending-the-client)

You can extend the client and implement your own endpoints:

```
use Vdhicts\WeFact\Enums\WeFactController;
use Vdhicts\WeFact\WeFact;
use Vdhicts\WeFact\WeFactRequest;

class Debtor extends WeFact
{
    public function show(string $debtorCode): Response
    {
        $request = new WeFactRequest(WeFactController::DEBTOR, 'show', [
            'DebtorCode' => $debtorCode,
        ]);

        return $this->$request($request);
    }
}
```

### Handling errors

[](#handling-errors)

A `Response` object will always be returned. See [Error handling](https://laravel.com/docs/8.x/http-client#error-handling) of the Http Client.

```
if ($response->failed()) {
    var_dump($response->serverError());
}
```

### Laravel

[](#laravel)

This package can be easily used in any Laravel application. I would suggest adding your credentials to the `.env` file of the project:

```
WEFACT_API_KEY=apikey

```

Next create a config file `wefact.php` in `/config`:

```
