Skip to main content

WeFact

This plugin allows for API integration with WeFact.

Installation

To install this module:

composer require qore/wefact

Usage

Getting started

After you enable this plugin in the interface, you will be required to fill in the API key.

You can find this key here. Do note that you might also need to white list your IP address inside WeFact.

After saving, you should be ready to make API calls.

info

WeFact's API Documentation can be found here

API requests

You can start doing requests to WeFact by getting the WefactClient:

use Qore\Wefact\Clients\WefactClient;

$client = new WefactClient();

$results = $client->request(WefactController::DEBTOR, WefactAction::LIST);

The first parameter is the so-called "controller", in this case we want the debtors. The second parameter is the "action", in this case we list all.

Listing resources

You can list resources:

$client = new WefactClient();

// Optional parameters
$params = [
'searchat' => 'EmailAddress',
'searchfor' => 'info@example.com'
];

$debtors = $client->list(WefactController::DEBTOR, $params);

Alternatively, you can do:

$results = $client->request(WefactController::DEBTOR, WefactAction::LIST, $params);

Finding resources

You can find a specific resource by ID:

$client = new WefactClient();

$params = [
'Identifier' => '1',
];

// OR:
$params = [
'DebtorCode' => 'DB10000',
];

$debtor = $client->show(WefactController::DEBTOR, $params);

Alternatively, you can do:

$results = $client->request(WefactController::DEBTOR, WefactAction::SHOW, $params);

Creating a resource

You can create a new resource like this:

$client = new WefactClient();

$params = [
'Debtor' => '1',
'InvoiceLines' => [
[
'Number' => 2,
'Description' => 'Test regel 1'
],
[
'Description' => 'Reiskosten à € 0,19 per km',
'PriceExcl' => 0.19
]
]
];

$invoice = $client->add(WefactController::INVOICE, $params);

Alternatively, you can do:

$results = $client->request(WefactController::INVOICE, WefactAction::ADD, $params);

Updating a resource

You can update an existing resource:

$client = new WefactClient();

$params = [
'Identifier' => '1',
'Discount' => 10, // percentage
'Term' => 20
];

$invoice = $client->edit(WefactController::INVOICE, $params);

Alternatively, you can do:

$results = $client->request(WefactController::INVOICE, WefactAction::EDIT, $params);

Deleting a resource

To delete a resource:

$client = new WefactClient();

$params = [
'Identifier' => '1',
'InvoiceLines' => [
[
'Identifier' => '2'
]
]
];

// Delete an invoice line
$results = $client->delete(WefactController::INVOICE_LINE, $params);

Alternatively, you can do:

$results = $client->request(WefactController::INVOICE_LINE, WefactAction::DELETE, $params);  

Other actions

There exists a list of other actions that can be called. For example, you can credit an invoice:

$client = new WefactClient();

$params = [
'Identifier' => '1'
];

// Only non-credit invoices can be credited
$response = $client->request(WefactController::INVOICE, WefactAction::CREDIT, $params);

Comparing statuses

WeFact resources like Invoices, Credit Invoices etc. have their own status identifiers.

You can find all variables here

For example, checking if an invoice is paid could be done like this:

$client = new WefactClient();

$params = [
'Identifier' => '3'
];

$invoice = $client->show(WefactController::INVOICE, $params);

if ($invoice['Status'] === WefactInvoiceStatus::PAID->value) {
// Invoice is paid
}
warning

Invoice statuses are different from credit invoices (purchaseinvoices). For example, for a credit invoice you should compare WefactPurchaseInvoiceStatus.

Upgrade Guide

To upgrade this module:

composer update qore/wefact