diff --git a/src/HelloassoClient.php b/src/HelloassoClient.php index 484d004..86a9d22 100644 --- a/src/HelloassoClient.php +++ b/src/HelloassoClient.php @@ -31,7 +31,7 @@ public function __construct( $this->checkout = new CheckoutIntentService($apiCaller, $organizationSlug); $this->directory = new DirectoryService(); $this->payment = new PaymentService($apiCaller, $organizationSlug); - $this->order = new OrderService($apiCaller); + $this->order = new OrderService($apiCaller, $organizationSlug); } /** diff --git a/src/Models/Statistics/OrderCollection.php b/src/Models/Statistics/OrderCollection.php new file mode 100644 index 0000000..f53feac --- /dev/null +++ b/src/Models/Statistics/OrderCollection.php @@ -0,0 +1,21 @@ + + */ +class OrderCollection extends Collection +{ + /** + * Overriding the property with an @var annotation is needed for the + * serializer component until generics are not supported. + * + * @var Order[] + */ + protected array $data = []; +} diff --git a/src/Service/OrderService.php b/src/Service/OrderService.php index f3de50a..9d68590 100644 --- a/src/Service/OrderService.php +++ b/src/Service/OrderService.php @@ -6,14 +6,37 @@ use Helloasso\Exception\HelloassoApiException; use Helloasso\Http\ApiCaller; +use Helloasso\Models\Statistics\Order; +use Helloasso\Models\Statistics\OrderCollection; class OrderService { public function __construct( private readonly ApiCaller $apiCaller, + private readonly string $organizationSlug, ) { } + /** + * @throws HelloassoApiException + */ + public function retrieve(int $id): Order + { + return $this->apiCaller->get("/v5/orders/$id", Order::class); + } + + /** + * @param array $params + * + * @throws HelloassoApiException + */ + public function all(array $params = []): OrderCollection + { + return $this->apiCaller->get("/v5/organizations/{$this->organizationSlug}/orders", OrderCollection::class, [ + 'query' => $params, + ]); + } + /** * @throws HelloassoApiException */