Skip to content

Commit fe93fdf

Browse files
committed
Allow extra body data to be passed to the Create Endpoints
1 parent d596bae commit fe93fdf

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/API/Endpoints/Concerns/CreatesWithType.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ 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
{
26-
$data = [$entityType->value => $data->toCreateData()->toArray()];
27-
return $this->callApi($entityType, $data);
28-
}
29-
30-
public function callApi(EntityTypeEnum $entityType, array $data): EntityData{
3126
$response = $this->call(
3227
action: static::CREATE,
3328
urlParams: ['type' => $entityType->toUrlVariable()],
34-
bodyData: $data
29+
bodyData: [
30+
$entityType->value => $data->toCreateData()->toArray(),
31+
...$extraData,
32+
]
3533
);
34+
3635
return $this->responseToDataObject($response[$entityType->value]);
3736
}
3837
}

src/API/Endpoints/InvoicesEndpoint.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InvoicesEndpoint extends Endpoint
3030
use ChangesState;
3131

3232
/** @use CreatesWithType<InvoiceData> */
33-
use CreatesWithType {create as createWithType; }
33+
use CreatesWithType { create as createWithType; }
3434

3535
use GeneratesAndCancelsPayment;
3636
use GeneratesPDF;
@@ -62,11 +62,13 @@ protected function getEndpointName(): string
6262
return static::ENDPOINT_CONFIG;
6363
}
6464

65-
public function create(EntityTypeEnum $entityType, InvoiceData $data, ?string $proprietaryUid): InvoiceData {
66-
$data = [$entityType->value => $data->toCreateData()->toArray()];
67-
if($proprietaryUid){
68-
$data['proprietary_uid'] = $proprietaryUid;
65+
public function create(EntityTypeEnum $entityType, InvoiceData $data, ?string $proprietaryUid = null): InvoiceData
66+
{
67+
$extra = [];
68+
if ($proprietaryUid) {
69+
$extra['proprietary_uid'] = $proprietaryUid;
6970
}
70-
return $this->callApi($entityType, $data);
71+
72+
return $this->createWithType($entityType, $data, $extra);
7173
}
7274
}

0 commit comments

Comments
 (0)