update subscription, add alias

Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
2025-04-30 09:02:24 +02:00
parent 71663bffd8
commit 3bcebd9d45
4 changed files with 91 additions and 8 deletions

View File

@@ -22,4 +22,16 @@ trait ManagesAddresses
return (new Addresses($this->request('GET', 'v1/addresses'))) return (new Addresses($this->request('GET', 'v1/addresses')))
->setBillable($this); ->setBillable($this);
} }
/**
* Check if the current user has a default billing address.
*
* @see \Anikeen\Id\Resources\Addresses::hasDefaultBillingAddress()
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function hasDefaultBillingAddress(): bool
{
return $this->addresses()->hasDefaultBillingAddress();
}
} }

View File

@@ -4,6 +4,7 @@ namespace Anikeen\Id\Concerns;
use Anikeen\Id\ApiOperations\Request; use Anikeen\Id\ApiOperations\Request;
use Anikeen\Id\Exceptions\RequestRequiresClientIdException; use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
use Anikeen\Id\Resources\PaymentMethod;
use Anikeen\Id\Resources\PaymentMethods; use Anikeen\Id\Resources\PaymentMethods;
use Anikeen\Id\Result; use Anikeen\Id\Result;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
@@ -24,6 +25,42 @@ trait ManagesPaymentMethods
->setBillable($this); ->setBillable($this);
} }
/**
* Check if current user has at least one payment method.
*
* @see \Anikeen\Id\Resources\PaymentMethods::hasPaymentMethod()
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function hasPaymentMethod(): ?PaymentMethod
{
return $this->paymentMethods()->hasPaymentMethod();
}
/**
* Get default payment method from the current user.
*
* @see \Anikeen\Id\Resources\PaymentMethods::defaultPaymentMethod()
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function defaultPaymentMethod(): ?PaymentMethod
{
return $this->paymentMethods()->defaultPaymentMethod();
}
/**
* Check if the current user has a default payment method.
*
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function hasDefaultPaymentMethod(): bool
{
return $this->paymentMethods()->hasDefaultPaymentMethod();
}
/** /**
* Get billing portal URL for the current user. * Get billing portal URL for the current user.
* *

View File

@@ -10,15 +10,50 @@ use GuzzleHttp\Exception\GuzzleException;
* @property string $id * @property string $id
* @property string $name * @property string $name
* @property string $description * @property string $description
* @property string $status
* @property string $unit * @property string $unit
* @property float $price * @property float $price
* @property float $vat_rate
* @property array $payload
* @property string $ends_at * @property string $ends_at
* @property string $webhook_url
* @property string $webhook_secret
*/ */
class Subscription extends BaseResource class Subscription extends BaseResource
{ {
use HasBillable; use HasBillable;
/**
* Update a given subscription from the current user.
*
* @param array{
* name: null,
* description: null|string,
* unit: string,
* price: float,
* vat_rate: null|float,
* payload: null|array,
* ends_at: null|string,
* webhook_url: null|string,
* webhook_secret: null|string
* } $attributes The subscription data:
* - name: The name
* - description: The description (optional)
* - unit: The unit (e.g. "hour", "day", "week", "month", "year")
* - price: The price per unit
* - vat_rate: The VAT rate (optional)
* - payload: The payload (optional)
* - ends_at: The end date (optional)
* - webhook_url: The webhook URL (optional)
* - webhook_secret: The webhook secret (optional)
* @throws RequestRequiresClientIdException
* @throws GuzzleException
*/
public function update(array $attributes): self
{
return (new self($this->billable->request('PUT', sprintf('v1/subscriptions/%s', $this->id), $attributes)))
->setBillable($this->billable);
}
/** /**
* Force given subscription to check out (trusted apps only). * Force given subscription to check out (trusted apps only).
* *

View File

@@ -4,7 +4,6 @@ namespace Anikeen\Id\Resources;
use Anikeen\Id\Concerns\HasBillable; use Anikeen\Id\Concerns\HasBillable;
use Anikeen\Id\Exceptions\RequestRequiresClientIdException; use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
use Anikeen\Id\Result;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
class Subscriptions extends BaseCollection class Subscriptions extends BaseCollection
@@ -16,24 +15,24 @@ class Subscriptions extends BaseCollection
* *
* @param array{ * @param array{
* name: null, * name: null,
* description: string, * description: null|string,
* unit: string, * unit: string,
* price: float, * price: float,
* vat: null|float, * vat_rate: null|float,
* payload: null|array, * payload: null|array,
* ends_at: null|string, * ends_at: null|string,
* webhook_url: null|string, * webhook_url: null|string,
* webhook_secret: null|string * webhook_secret: null|string
* } $attributes The subscription data: * } $attributes The subscription data:
* - name: The name * - name: The name
* - description: The description * - description: The description (optional)
* - unit: The unit (e.g. "hour", "day", "week", "month", "year") * - unit: The unit (e.g. "hour", "day", "week", "month", "year")
* - price: The price per unit * - price: The price per unit
* - vat: The VAT (optional) * - vat_rate: The VAT rate (optional)
* - payload: The payload (optional) * - payload: The payload (optional)
* - ends_at: The end date (optional) * - ends_at: The end date (optional)
* - webhook_url: The webhook URL (optional) * - webhook_url: The webhook URL (optional)
* - webhook_secret: The webhook secret (optional) * - webhook_secret: The webhook secret (optional)
* @throws RequestRequiresClientIdException * @throws RequestRequiresClientIdException
* @throws GuzzleException * @throws GuzzleException
*/ */