Skip to content

Commit 366f001

Browse files
authored
Merge pull request #28 from mbarreiro85/feature/add-proprietary_uid
invoices with idempotency keys
2 parents 9e28d9c + fe93fdf commit 366f001

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/API/Endpoints/Concerns/CreatesWithType.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ trait CreatesWithType
2121
* @throws RequestException
2222
* @throws UnknownAPIMethodException
2323
*/
24-
public function create(EntityTypeEnum $entityType, EntityData $data): EntityData
24+
public function create(EntityTypeEnum $entityType, EntityData $data, array $extraData = []): EntityData
2525
{
2626
$response = $this->call(
2727
action: static::CREATE,
2828
urlParams: ['type' => $entityType->toUrlVariable()],
29-
bodyData: [$entityType->value => $data->toCreateData()->toArray()]
29+
bodyData: [
30+
$entityType->value => $data->toCreateData()->toArray(),
31+
...$extraData,
32+
]
3033
);
3134

3235
return $this->responseToDataObject($response[$entityType->value]);

src/API/Endpoints/InvoicesEndpoint.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Squarebit\InvoiceXpress\API\Endpoints\Concerns\RelatedDocuments;
2020
use Squarebit\InvoiceXpress\API\Endpoints\Concerns\SendsByEmail;
2121
use Squarebit\InvoiceXpress\API\Endpoints\Concerns\UpdatesWithType;
22+
use Squarebit\InvoiceXpress\Enums\EntityTypeEnum;
2223

2324
/**
2425
* @template-extends Endpoint<InvoiceData>
@@ -29,7 +30,7 @@ class InvoicesEndpoint extends Endpoint
2930
use ChangesState;
3031

3132
/** @use CreatesWithType<InvoiceData> */
32-
use CreatesWithType;
33+
use CreatesWithType { create as createWithType; }
3334

3435
use GeneratesAndCancelsPayment;
3536
use GeneratesPDF;
@@ -60,4 +61,14 @@ protected function getEndpointName(): string
6061
{
6162
return static::ENDPOINT_CONFIG;
6263
}
64+
65+
public function create(EntityTypeEnum $entityType, InvoiceData $data, ?string $proprietaryUid = null): InvoiceData
66+
{
67+
$extra = [];
68+
if ($proprietaryUid) {
69+
$extra['proprietary_uid'] = $proprietaryUid;
70+
}
71+
72+
return $this->createWithType($entityType, $data, $extra);
73+
}
6374
}

0 commit comments

Comments
 (0)