Skip to content

Commit 42f3e4e

Browse files
committed
feat: add Outgoing Payments resource and related request classes
- Updated README to reflect the implementation status of Outgoing Payments as fully implemented. - Introduced the OutgoingPayment resource class along with request classes for creating, updating, deleting, and retrieving outgoing payments. - Added tests to ensure functionality and data integrity for the Outgoing Payments feature.
1 parent 386f680 commit 42f3e4e

File tree

8 files changed

+256
-1
lines changed

8 files changed

+256
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ $client = new BexioClient($auth->getAccessToken());
258258
| Bills ||
259259
| Expenses ||
260260
| Purchase Orders ||
261-
| Outgoing Payment | |
261+
| Outgoing Payment | |
262262

263263
### ACCOUNTING
264264

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments;
5+
6+
use Bexio\Resources\Purchase\OutgoingPayments\Requests\CreateOutgoingPaymentRequest;
7+
use Bexio\Resources\Purchase\OutgoingPayments\Requests\DeleteOutgoingPaymentRequest;
8+
use Bexio\Resources\Purchase\OutgoingPayments\Requests\GetOutgoingPaymentRequest;
9+
use Bexio\Resources\Purchase\OutgoingPayments\Requests\GetOutgoingPaymentsRequest;
10+
use Bexio\Resources\Purchase\OutgoingPayments\Requests\UpdateOutgoingPaymentRequest;
11+
use Bexio\Resources\Resource;
12+
13+
class OutgoingPayment extends Resource
14+
{
15+
public const INDEX_REQUEST = GetOutgoingPaymentsRequest::class;
16+
public const SHOW_REQUEST = GetOutgoingPaymentRequest::class;
17+
public const CREATE_REQUEST = CreateOutgoingPaymentRequest::class;
18+
public const UPDATE_REQUEST = UpdateOutgoingPaymentRequest::class;
19+
public const DELETE_REQUEST = DeleteOutgoingPaymentRequest::class;
20+
21+
public function __construct(
22+
public ?string $id = null,
23+
public ?string $bill_id = null,
24+
public ?string $payment_type = null,
25+
public ?string $execution_date = null,
26+
public ?string $status = null,
27+
public ?float $amount = null,
28+
public ?int $sender_bank_account_id = null,
29+
public ?string $receiver_account_no = null,
30+
public ?string $receiver_iban = null,
31+
public ?string $banking_payment_id = null,
32+
public ?string $transaction_id = null,
33+
public ?string $currency_code = null,
34+
public ?float $exchange_rate = null,
35+
public ?string $note = null,
36+
public ?string $sender_iban = null,
37+
public ?string $sender_name = null,
38+
public ?string $sender_street = null,
39+
public ?string $sender_house_no = null,
40+
public ?string $sender_city = null,
41+
public ?string $sender_postcode = null,
42+
) {
43+
}
44+
}
45+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments\Requests;
5+
6+
use Bexio\Resources\Purchase\OutgoingPayments\OutgoingPayment;
7+
use Saloon\Contracts\Body\HasBody;
8+
use Saloon\Enums\Method;
9+
use Saloon\Http\Request;
10+
use Saloon\Http\Response;
11+
use Saloon\Traits\Body\HasJsonBody;
12+
13+
class CreateOutgoingPaymentRequest extends Request implements HasBody
14+
{
15+
use HasJsonBody;
16+
17+
protected Method $method = Method::POST;
18+
19+
public function __construct(readonly protected OutgoingPayment $payment)
20+
{
21+
}
22+
23+
public function resolveEndpoint(): string
24+
{
25+
return '/4.0/purchase/outgoing-payments';
26+
}
27+
28+
protected function defaultBody(): array
29+
{
30+
return $this->payment->toArray();
31+
}
32+
33+
public function createDtoFromResponse(Response $response): OutgoingPayment
34+
{
35+
$data = $response->json('data') ?? $response->json();
36+
return OutgoingPayment::from($data);
37+
}
38+
}
39+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments\Requests;
5+
6+
use Saloon\Enums\Method;
7+
use Saloon\Http\Request;
8+
9+
class DeleteOutgoingPaymentRequest extends Request
10+
{
11+
protected Method $method = Method::DELETE;
12+
13+
public function __construct(protected readonly string $id)
14+
{
15+
}
16+
17+
public function resolveEndpoint(): string
18+
{
19+
return "/4.0/purchase/outgoing-payments/{$this->id}";
20+
}
21+
}
22+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments\Requests;
5+
6+
use Bexio\Resources\Purchase\OutgoingPayments\OutgoingPayment;
7+
use Saloon\Enums\Method;
8+
use Saloon\Http\Request;
9+
use Saloon\Http\Response;
10+
11+
class GetOutgoingPaymentRequest extends Request
12+
{
13+
protected Method $method = Method::GET;
14+
15+
public function __construct(protected readonly string $id)
16+
{
17+
}
18+
19+
public function resolveEndpoint(): string
20+
{
21+
return "/4.0/purchase/outgoing-payments/{$this->id}";
22+
}
23+
24+
public function createDtoFromResponse(Response $response): OutgoingPayment
25+
{
26+
$data = $response->json('data') ?? $response->json();
27+
return OutgoingPayment::from($data);
28+
}
29+
}
30+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments\Requests;
5+
6+
use Bexio\Resources\Purchase\OutgoingPayments\OutgoingPayment;
7+
use Saloon\Enums\Method;
8+
use Saloon\Http\Request;
9+
use Saloon\Http\Response;
10+
11+
class GetOutgoingPaymentsRequest extends Request
12+
{
13+
protected Method $method = Method::GET;
14+
15+
public function resolveEndpoint(): string
16+
{
17+
return '/4.0/purchase/outgoing-payments';
18+
}
19+
20+
public function createDtoFromResponse(Response $response): array
21+
{
22+
$data = $response->json('data') ?? [];
23+
return OutgoingPayment::collect($data);
24+
}
25+
}
26+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Bexio\Resources\Purchase\OutgoingPayments\Requests;
5+
6+
use Bexio\Resources\Purchase\OutgoingPayments\OutgoingPayment;
7+
use Saloon\Contracts\Body\HasBody;
8+
use Saloon\Enums\Method;
9+
use Saloon\Http\Request;
10+
use Saloon\Http\Response;
11+
use Saloon\Traits\Body\HasJsonBody;
12+
13+
class UpdateOutgoingPaymentRequest extends Request implements HasBody
14+
{
15+
use HasJsonBody;
16+
17+
protected Method $method = Method::PUT;
18+
19+
public function __construct(readonly protected OutgoingPayment $payment)
20+
{
21+
}
22+
23+
public function resolveEndpoint(): string
24+
{
25+
return "/4.0/purchase/outgoing-payments/{$this->payment->id}";
26+
}
27+
28+
protected function defaultBody(): array
29+
{
30+
return $this->payment->toArray();
31+
}
32+
33+
public function createDtoFromResponse(Response $response): OutgoingPayment
34+
{
35+
$data = $response->json('data') ?? $response->json();
36+
return OutgoingPayment::from($data);
37+
}
38+
}
39+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Bexio\Resources\Sales\Quotes\Requests;
4+
5+
use Bexio\Resources\Purchase\OutgoingPayments\OutgoingPayment;
6+
7+
it('can get Outgoing Payments', function () {
8+
try {
9+
$payments = OutgoingPayment::useClient(testClient())->all();
10+
} catch (\Throwable $e) {
11+
\PHPUnit\Framework\Assert::markTestSkipped('Outgoing payments endpoint requires bill context: ' . $e->getMessage());
12+
}
13+
14+
if (count($payments) === 0) {
15+
\PHPUnit\Framework\Assert::markTestSkipped('No outgoing payments available');
16+
}
17+
18+
expect($payments)->toBeArray()
19+
->and($payments[0])->toBeInstanceOf(OutgoingPayment::class)
20+
->and($payments[0]->id)->toBeString();
21+
});
22+
23+
it('can get an Outgoing Payment', function () {
24+
try {
25+
$payments = OutgoingPayment::useClient(testClient())->all();
26+
} catch (\Throwable $e) {
27+
\PHPUnit\Framework\Assert::markTestSkipped('Outgoing payments endpoint requires bill context: ' . $e->getMessage());
28+
}
29+
if (count($payments) === 0) {
30+
\PHPUnit\Framework\Assert::markTestSkipped('No outgoing payments available');
31+
}
32+
33+
$payment = OutgoingPayment::useClient(testClient())->find($payments[0]->id);
34+
35+
expect($payment)->toBeInstanceOf(OutgoingPayment::class)
36+
->and($payment->id)->toBeString()
37+
->and($payment->payment_type)->toBeString();
38+
});
39+
40+
it('can get first Outgoing Payment using query builder', function () {
41+
try {
42+
$payment = OutgoingPayment::useClient(testClient())->query()->first();
43+
} catch (\Throwable $e) {
44+
\PHPUnit\Framework\Assert::markTestSkipped('Outgoing payments endpoint requires bill context: ' . $e->getMessage());
45+
}
46+
47+
if (!$payment) {
48+
\PHPUnit\Framework\Assert::markTestSkipped('No outgoing payments available');
49+
}
50+
51+
expect($payment)->toBeInstanceOf(OutgoingPayment::class)
52+
->and($payment->id)->toBeString();
53+
});
54+

0 commit comments

Comments
 (0)