Skip to content

Commit

Permalink
CreditInvoice, Creditor and Subscription resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Jun 7, 2023
1 parent fb8946d commit 96a994a
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 4 deletions.
179 changes: 176 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ This package provides a fluent interface to communicate with the WeFact API. For
- [Installation](#installation)
- [Usage](#usage)
- [Available methods](#available-methods)
- [Creditor](#creditor)
- [List creditors](#list-creditors)
- [Create creditor](#create-creditor)
- [Update creditor](#update-creditor)
- [Show creditor](#show-creditor)
- [Delete creditor](#delete-creditor)
- [Credit Invoice](#credit-invoice)
- [List credit invoices](#list-credit-invoices)
- [Create credit invoice](#create-credit-invoice)
- [Update credit invoice](#update-credit-invoice)
- [Show credit invoice](#show-credit-invoice)
- [Delete credit invoice](#delete-credit-invoice)
- [Debtor](#debtor)
- [List debtors](#list-debtors)
- [Create debtor](#create-debtor)
Expand All @@ -35,6 +47,11 @@ This package provides a fluent interface to communicate with the WeFact API. For
- [Update product](#update-product)
- [Show product](#show-product)
- [Delete product](#delete-product)
- [Subscription](#subscription)
- [List subscriptions](#list-subscriptions)
- [Create subscription](#create-subscription)
- [Update subscription](#update-subscription)
- [Show subscription](#show-subscription)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
Expand Down Expand Up @@ -67,9 +84,112 @@ $invoices = $weFact->invoice()->list();

## Available methods

### Debtor
### Creditor

#### List creditors

```php
$weFact->creditor()->list();
```

#### Create creditor

Required parameters: `CompanyName` or `SurName`.

```php
$weFact->creditor()->create([
'CompanyName' => 'Your company name',
])
```

#### Update creditor

Required parameter: `Identifier` or `CreditorCode`.

```php
$weFact->creditor()->edit([
'Identifier' => $creditorId,
'CompanyName' => 'Your company name',
])
```

#### Show creditor

Required parameter: `Identifier` or `CreditorCode`.

```php
$weFact->creditor()->show(['Identifier' => $creditorId]);
// or
$weFact->creditor()->show(['CreditorCode' => $creditorCode]);
```

#### Delete creditor

Required parameter: `Identifier` or `CreditorCode`.

```php
$weFact->creditor()->delete(['Identifier' => $creditorId]);
// or
$weFact->creditor()->delete(['CreditorCode' => $creditorCode]);
```

### Credit Invoice

#### List credit invoices

```php
$weFact->creditInvoice()->list();
```

#### Create credit invoice

Required parameters: `InvoiceCode`, `Creditor` or `CreditorCode` and `InvoiceLines`.

```php
$weFact->creditInvoice()->create([
'InvoiceCode' => 'your-invoice-code',
'CreditorCode' => 'CD10001'
'InvoiceLines' => [
[
'Description' => 'Your description',
'PriceExcl' => 10,
],
],
])
```

#### Update credit invoice

<!-- Show list, add and edit -->
Required parameter: `Identifier` or `CreditInvoiceCode`.

```php
$weFact->creditInvoice()->edit([
'Identifier' => $creditInvoiceId,
'Comment' => 'Your comment',
])
```

#### Show credit invoice

Required parameter: `Identifier` or `CreditInvoiceCode`.

```php
$weFact->creditInvoice()->show(['Identifier' => $creditInvoiceId]);
// or
$weFact->creditInvoice()->show(['CreditInvoiceCode' => $creditInvoiceCode]);
```

#### Delete credit invoice

Required parameter: `Identifier` or `CreditInvoiceCode`.

```php
$weFact->creditInvoice()->delete(['Identifier' => $creditInvoiceId]);
// or
$weFact->creditInvoice()->delete(['CreditInvoiceCode' => $creditInvoiceCode]);
```

### Debtor

#### List debtors

Expand Down Expand Up @@ -112,8 +232,12 @@ $weFact->debtor()->show(['DebtorCode' => $debtorCode]);

#### List groups

Required parameter: `Type`.

```php
$weFact->group()->list();
$weFact->group()->list([
'type' => 'debtor',
]);
```

#### Create group
Expand Down Expand Up @@ -273,6 +397,55 @@ $weFact->product()->delete(['Identifier' => $productId]);
$weFact->product()->delete(['ProductCode' => $productCode]);
```

### Subscription

#### List subscriptions

```php
$weFact->subscription()->list();
```

#### Create subscription

Required parameters: `Debtor` or `DebtorCode` and `ProductCode`. When `ProductCode` is empty, `Description`, `PriceExcl` and `Periodic` are required.

> Please note: You can pass either the `TerminateAfter` or the `TerminationDate`, not both. The `TerminateAfter` includes the number of times the subscription has been billed in the past.
```php
$weFact->subscription()->create([
'DebtorCode' => 'DB10000',
'ProductCode' => 'P0001',
'Description' => 'Your product description',
'PriceExcl' => 100,
'Periodic' => 'month',
'TerminateAfter' => 12
])
```

#### Update subscription

Required parameter: `Identifier`.

> Please note: You can pass either the `TerminateAfter` or the `TerminationDate`, not both. The `TerminateAfter` includes the number of times the subscription has been billed in the past.
```php
$weFact->subscription()->edit([
'Identifier' => $subscriptionId,
'Description' => 'Your product description',
'PriceExcl' => 100,
'Periodic' => 'month',
'TerminateAfter' => 12
])
```

#### Show subscription

Required parameter: `Identifier`.

```php
$weFact->subscription()->show(['Identifier' => $subscriptionId]);
```

## Testing

```bash
Expand Down
23 changes: 23 additions & 0 deletions src/Resources/CreditInvoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Vormkracht10\WeFact\Resources;

use GuzzleHttp\Client;

class CreditInvoice extends Resource
{
final public const CONTROLLER_NAME = 'creditinvoice';

public function __construct(
protected Client $http,
protected string $apiKey,
protected string $apiUrl
) {
$this->http = $http;
}

public function getResourceName(): string
{
return self::CONTROLLER_NAME;
}
}
23 changes: 23 additions & 0 deletions src/Resources/Creditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Vormkracht10\WeFact\Resources;

use GuzzleHttp\Client;

class Creditor extends Resource
{
final public const CONTROLLER_NAME = 'creditor';

public function __construct(
protected Client $http,
protected string $apiKey,
protected string $apiUrl
) {
$this->http = $http;
}

public function getResourceName(): string
{
return self::CONTROLLER_NAME;
}
}
28 changes: 28 additions & 0 deletions src/Resources/Subscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Vormkracht10\WeFact\Resources;

use Vormkracht10\WeFact\Exceptions\MethodNotAvailableException;

class Subscription extends Resource
{
final public const CONTROLLER_NAME = 'debtor';

public function getResourceName(): string
{
return self::CONTROLLER_NAME;
}

/**
* @param array<string, mixed> $params
* @return MethodNotAvailableException|array<string, mixed>
*
* @throws MethodNotAvailableException
*/
public function delete(array $params = []): MethodNotAvailableException|array
{
throw new MethodNotAvailableException(
sprintf('%s is not available for this resource.', __METHOD__)
);
}
}
32 changes: 31 additions & 1 deletion src/WeFact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace Vormkracht10\WeFact;

use GuzzleHttp\Client;
use Vormkracht10\WeFact\Resources\Debtor;
use Vormkracht10\WeFact\Resources\Group;
use Vormkracht10\WeFact\Resources\Debtor;
use Vormkracht10\WeFact\Resources\Invoice;
use Vormkracht10\WeFact\Resources\Product;
use Vormkracht10\WeFact\Resources\Creditor;
use Vormkracht10\WeFact\Resources\Subscription;
use Vormkracht10\WeFact\Resources\CreditInvoice;

class WeFact
{
Expand Down Expand Up @@ -74,4 +77,31 @@ public function product(): Product
$this->apiUrl
);
}

public function creditor(): Creditor
{
return new Creditor(
$this->http,
$this->apiKey,
$this->apiUrl
);
}

public function creditInvoice(): CreditInvoice
{
return new CreditInvoice(
$this->http,
$this->apiKey,
$this->apiUrl,
);
}

public function subscription(): Subscription
{
return new Subscription(
$this->http,
$this->apiKey,
$this->apiUrl,
);
}
}

0 comments on commit 96a994a

Please sign in to comment.