small fixes

Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
2025-04-30 06:43:07 +02:00
parent 5b2b3c72cc
commit 71663bffd8
9 changed files with 63 additions and 12 deletions

View File

@@ -2,11 +2,14 @@
namespace Anikeen\Id\Resources;
use Anikeen\Id\Concerns\MagicProperties;
use Anikeen\Id\Result;
use JsonSerializable;
abstract class BaseCollection implements JsonSerializable
{
use MagicProperties;
public function __construct(protected Result $result)
{
//

View File

@@ -102,13 +102,12 @@ class Order extends BaseResource
/**
* Get order items from given order.
*
* @param string $orderId The order ID.
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function orderItems(string $orderId): OrderItems
public function orderItems(array $parameters = []): OrderItems
{
return (new OrderItems($this->billable->request('GET', sprintf('v1/orders/%s/items', $this->id))))
return (new OrderItems($this->billable->request('GET', sprintf('v1/orders/%s/items', $this->id), [], $parameters)))
->setBillable($this->billable)
->setParent($this);
}

View File

@@ -4,6 +4,9 @@ namespace Anikeen\Id\Resources;
use Anikeen\Id\Concerns\HasBillable;
/**
* @property string $id
*/
class PaymentMethod extends BaseResource
{
use HasBillable;

View File

@@ -11,6 +11,8 @@ class PaymentMethods extends BaseCollection
{
use HasBillable;
private ?PaymentMethod $cachedDefaultPaymentMethod = null;
/**
* Check if current user has at least one payment method.
*
@@ -30,8 +32,24 @@ class PaymentMethods extends BaseCollection
*/
public function defaultPaymentMethod(): PaymentMethod
{
return (new PaymentMethod($this->billable->request('GET', 'v1/payment-methods/default')))
->setBillable($this->billable);
if ($this->cachedDefaultPaymentMethod === null) {
$this->cachedDefaultPaymentMethod = (new PaymentMethod(
$this->billable->request('GET', 'v1/payment-methods/default')
))->setBillable($this->billable);
}
return $this->cachedDefaultPaymentMethod;
}
/**
* Check if the current user has a default payment method.
*
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function hasDefaultPaymentMethod(): bool
{
return $this->defaultPaymentMethod()?->id !== null;
}
/**

View File

@@ -8,6 +8,12 @@ use GuzzleHttp\Exception\GuzzleException;
/**
* @property string $id
* @property string $name
* @property string $description
* @property string $status
* @property string $unit
* @property float $price
* @property string $ends_at
*/
class Subscription extends BaseResource
{