-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Models\Common; | ||
|
||
use Helloasso\Models\HelloassoObject; | ||
|
||
/** | ||
* @template T of HelloassoObject | ||
*/ | ||
abstract class Collection implements HelloassoObject | ||
{ | ||
/** | ||
* @var T[] | ||
*/ | ||
protected array $data = []; | ||
|
||
protected PaginationModel $pagination; | ||
|
||
public function isEmpty(): bool | ||
{ | ||
return 0 === \count($this->data); | ||
} | ||
|
||
/** | ||
* @return T[] | ||
*/ | ||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* @param T[] $data | ||
*/ | ||
public function setData(array $data): self | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPagination(): PaginationModel | ||
{ | ||
return $this->pagination; | ||
} | ||
|
||
public function setPagination(PaginationModel $pagination): self | ||
{ | ||
$this->pagination = $pagination; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Models\Statistics; | ||
|
||
use Helloasso\Models\Common\Collection; | ||
|
||
/** | ||
* @extends Collection<Payment> | ||
*/ | ||
class PaymentCollection extends Collection | ||
{ | ||
/** | ||
* Overriding the property with an @var annotation is needed for the | ||
* serializer component until generics are not supported. | ||
* | ||
* @var Payment[] | ||
*/ | ||
protected array $data = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Service; | ||
|
||
use Helloasso\Exception\HelloassoApiException; | ||
use Helloasso\Http\ApiCaller; | ||
use Helloasso\Models\Statistics\Payment; | ||
use Helloasso\Models\Statistics\PaymentCollection; | ||
|
||
class PaymentService | ||
{ | ||
public function __construct( | ||
private readonly ApiCaller $apiCaller, | ||
private readonly string $organizationSlug, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws HelloassoApiException | ||
*/ | ||
public function retrieve(int $id): Payment | ||
{ | ||
return $this->apiCaller->get("/v5/payments/$id", Payment::class); | ||
} | ||
|
||
/** | ||
* @throws HelloassoApiException | ||
*/ | ||
public function all(array $params = []): PaymentCollection | ||
{ | ||
return $this->apiCaller->get("/v5/organizations/{$this->organizationSlug}/payments", PaymentCollection::class, $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Tests\Functional\Service; | ||
|
||
use Helloasso\Models\Statistics\Payment; | ||
use Helloasso\Models\Statistics\PaymentCollection; | ||
use Helloasso\Tests\Functional\FunctionalTestCase; | ||
|
||
final class PaymentServiceTest extends FunctionalTestCase | ||
{ | ||
public function testAll(): void | ||
{ | ||
$paymentCollection = $this->getClient()->payment->all(); | ||
$this->assertInstanceOf(PaymentCollection::class, $paymentCollection); | ||
|
||
if ($paymentCollection->isEmpty()) { | ||
$this->markTestSkipped(); | ||
} | ||
|
||
$paymentId = $paymentCollection->getData()[0]->getId(); | ||
|
||
$payment = $this->getClient()->payment->retrieve($paymentId); | ||
$this->assertInstanceOf(Payment::class, $payment); | ||
$this->assertSame($paymentId, $payment->getId()); | ||
} | ||
} |