diff --git a/src/Id/Concerns/ManagesAddresses.php b/src/Id/Concerns/ManagesAddresses.php index 7946cb0..ef7596c 100644 --- a/src/Id/Concerns/ManagesAddresses.php +++ b/src/Id/Concerns/ManagesAddresses.php @@ -22,4 +22,16 @@ trait ManagesAddresses return (new Addresses($this->request('GET', 'v1/addresses'))) ->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(); + } } \ No newline at end of file diff --git a/src/Id/Concerns/ManagesPaymentMethods.php b/src/Id/Concerns/ManagesPaymentMethods.php index d71c1be..7710d86 100644 --- a/src/Id/Concerns/ManagesPaymentMethods.php +++ b/src/Id/Concerns/ManagesPaymentMethods.php @@ -4,6 +4,7 @@ namespace Anikeen\Id\Concerns; use Anikeen\Id\ApiOperations\Request; use Anikeen\Id\Exceptions\RequestRequiresClientIdException; +use Anikeen\Id\Resources\PaymentMethod; use Anikeen\Id\Resources\PaymentMethods; use Anikeen\Id\Result; use GuzzleHttp\Exception\GuzzleException; @@ -24,6 +25,42 @@ trait ManagesPaymentMethods ->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. * diff --git a/src/Id/Resources/Subscription.php b/src/Id/Resources/Subscription.php index d14b6b1..fca2b52 100644 --- a/src/Id/Resources/Subscription.php +++ b/src/Id/Resources/Subscription.php @@ -10,15 +10,50 @@ use GuzzleHttp\Exception\GuzzleException; * @property string $id * @property string $name * @property string $description - * @property string $status * @property string $unit * @property float $price + * @property float $vat_rate + * @property array $payload * @property string $ends_at + * @property string $webhook_url + * @property string $webhook_secret */ class Subscription extends BaseResource { 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). * diff --git a/src/Id/Resources/Subscriptions.php b/src/Id/Resources/Subscriptions.php index ca2aa48..fd9f7f0 100644 --- a/src/Id/Resources/Subscriptions.php +++ b/src/Id/Resources/Subscriptions.php @@ -4,7 +4,6 @@ namespace Anikeen\Id\Resources; use Anikeen\Id\Concerns\HasBillable; use Anikeen\Id\Exceptions\RequestRequiresClientIdException; -use Anikeen\Id\Result; use GuzzleHttp\Exception\GuzzleException; class Subscriptions extends BaseCollection @@ -16,24 +15,24 @@ class Subscriptions extends BaseCollection * * @param array{ * name: null, - * description: string, + * description: null|string, * unit: string, * price: float, - * vat: null|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 + * - description: The description (optional) * - unit: The unit (e.g. "hour", "day", "week", "month", "year") * - price: The price per unit - * - vat: The VAT (optional) + * - 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) + * - webhook_url: The webhook URL (optional) + * - webhook_secret: The webhook secret (optional) * @throws RequestRequiresClientIdException * @throws GuzzleException */