Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dunnings endpoint #139

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ $response = $api->downPaymentInvoice()->document($entityId, true); // get file c
$response = $api->downPaymentInvoice()->document($entityId, true, 'image/*'); // accept only images
```

### Dunnings Endpoint
```php
$response = $api->dunning()->get($entityId);
$response = $api->dunning()->pursue($precedingSalesVoucherId, $data);
$response = $api->dunning()->document($entityId); // get document ID
$response = $api->dunning()->document($entityId, true); // get file content
$response = $api->dunning()->document($entityId, true, 'image/*'); // accept only images
```

### Event Subscriptions Endpooint
```php
$response = $api->event()->get($entityId);
Expand Down
6 changes: 6 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sysix\LexOffice\Clients\CreditNote;
use Sysix\LexOffice\Clients\DeliveryNote;
use Sysix\LexOffice\Clients\DownPaymentInvoice;
use Sysix\LexOffice\Clients\Dunning;
use Sysix\LexOffice\Clients\Event;
use Sysix\LexOffice\Clients\File;
use Sysix\LexOffice\Clients\Invoice;
Expand Down Expand Up @@ -109,6 +110,11 @@ public function downPaymentInvoice(): DownPaymentInvoice
return new DownPaymentInvoice($this);
}

public function dunning(): Dunning
{
return new Dunning($this);
}

public function event(): Event
{
return new Event($this);
Expand Down
19 changes: 19 additions & 0 deletions src/Clients/Dunning.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Sysix\LexOffice\Clients;

use Sysix\LexOffice\BaseClient;
use Sysix\LexOffice\Clients\Traits\DocumentClientTrait;
use Sysix\LexOffice\Clients\Traits\GetTrait;
use Sysix\LexOffice\Clients\Traits\PursueTrait;

class Dunning extends BaseClient
{
use DocumentClientTrait;
use GetTrait;
use PursueTrait;

protected string $resource = 'dunnings';
}
2 changes: 2 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Sysix\LexOffice\Clients\CreditNote;
use Sysix\LexOffice\Clients\DeliveryNote;
use Sysix\LexOffice\Clients\DownPaymentInvoice;
use Sysix\LexOffice\Clients\Dunning;
use Sysix\LexOffice\Clients\Event;
use Sysix\LexOffice\Clients\File;
use Sysix\LexOffice\Clients\Invoice;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function testClients(): void
$this->assertInstanceOf(CreditNote::class, $stub->creditNote());
$this->assertInstanceOf(DeliveryNote::class, $stub->deliveryNote());
$this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice());
$this->assertInstanceOf(Dunning::class, $stub->dunning());
$this->assertInstanceOf(Event::class, $stub->event());
$this->assertInstanceOf(File::class, $stub->file());
$this->assertInstanceOf(Invoice::class, $stub->invoice());
Expand Down
97 changes: 97 additions & 0 deletions tests/Clients/DunningTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace Sysix\LexOffice\Tests\Clients;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Sysix\LexOffice\Clients\Dunning;
use Sysix\LexOffice\Tests\TestClient;

class DunningTest extends TestClient
{
public function testGet(): void
{
[$api, $stub] = $this->createClientMockObject(Dunning::class);

$response = $stub->get('resource-id');

$this->assertInstanceOf(ResponseInterface::class, $response);

$this->assertEquals('GET', $api->getRequest()->getMethod());
$this->assertEquals(
$api->apiUrl . '/v1/dunnings/resource-id',
$api->getRequest()->getUri()->__toString()
);
}

public function testPursue(): void
{
[$api, $stub] = $this->createClientMockObject(Dunning::class);

$response = $stub->pursue('resource-id', [
'version' => 0
]);

$this->assertInstanceOf(ResponseInterface::class, $response);

$this->assertEquals('POST', $api->getRequest()->getMethod());
$this->assertEquals(
$api->apiUrl . '/v1/dunnings?precedingSalesVoucherId=resource-id',
$api->getRequest()->getUri()->__toString()
);
}

public function testDocument(): void
{
[$api, $stub] = $this->createClientMockObject(Dunning::class);

$response = $stub->document('resource-id');

$this->assertInstanceOf(ResponseInterface::class, $response);

$this->assertEquals('GET', $api->getRequest()->getMethod());
$this->assertEquals(
$api->apiUrl . '/v1/dunnings/resource-id/document',
$api->getRequest()->getUri()->__toString()
);
}

public function testDocumentContent(): void
{
[$api, $stub] = $this->createClientMultiMockObject(
Dunning::class,
[
new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'),
new Response()
]
);

$response = $stub->document('resource-id', true);

$this->assertInstanceOf(ResponseInterface::class, $response);

$this->assertEquals('GET', $api->getRequest()->getMethod());
$this->assertEquals(
$api->apiUrl . '/v1/files/fake-id',
$api->getRequest()->getUri()->__toString()
);
}

public function testFailedDocumentContent(): void
{
[$api, $stub] = $this->createClientMultiMockObject(
Dunning::class,
[
new Response(500),
new Response()
]
);

$response = $stub->document('resource-id', true);

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals(500, $response->getStatusCode());
}
}