From b3ff0b2266de84d12eeec41f33d6e283a4036bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 21 Apr 2025 21:18:53 +0200 Subject: [PATCH] Add methods to fetch orders --- src/HelloassoClient.php | 2 +- src/Models/Statistics/OrderCollection.php | 21 +++++++++++++++++++++ src/Service/OrderService.php | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/Models/Statistics/OrderCollection.php 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 */