2 Commits
1.2.0 ... main

Author SHA1 Message Date
René Preuß
9c3f9344a0 Add ManagesSocialiteUsers concern and resources for listing third-party connections
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-26 17:47:12 +02:00
Maurice Preuß
a7ec7aa908 add set default payment method
Signed-off-by: Maurice Preuß <envoyr@froxlor.org>
2026-05-17 16:46:06 +02:00
6 changed files with 106 additions and 21 deletions

View File

@@ -3,6 +3,7 @@
namespace Anikeen\Id; namespace Anikeen\Id;
use Anikeen\Id\Concerns\ManagesPricing; use Anikeen\Id\Concerns\ManagesPricing;
use Anikeen\Id\Concerns\ManagesSocialiteUsers;
use Anikeen\Id\Concerns\ManagesSshKeys; use Anikeen\Id\Concerns\ManagesSshKeys;
use Anikeen\Id\Concerns\ManagesUsers; use Anikeen\Id\Concerns\ManagesUsers;
use Anikeen\Id\Exceptions\RequestRequiresAuthenticationException; use Anikeen\Id\Exceptions\RequestRequiresAuthenticationException;
@@ -20,6 +21,7 @@ class AnikeenId
{ {
use OauthTrait; use OauthTrait;
use ManagesPricing; use ManagesPricing;
use ManagesSocialiteUsers;
use ManagesSshKeys; use ManagesSshKeys;
use ManagesUsers; use ManagesUsers;

View File

@@ -55,14 +55,27 @@ trait ManagesPaymentMethods
* @throws Throwable * @throws Throwable
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod() * @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
*/ */
public function hasDefaultPaymentMethod(): bool public function hasDefaultPaymentMethod(): bool
{ {
return $this->paymentMethods()->hasDefaultPaymentMethod(); return $this->paymentMethods()->hasDefaultPaymentMethod();
} }
/** /**
* Get billing portal URL for the current user. * Set the default payment method for the current user.
* *
* @throws Throwable
* @see \Anikeen\Id\Resources\PaymentMethods::setDefault()
*/
public function setDefaultPaymentMethod(string $id): PaymentMethod
{
unset($this->paymentMethodsCache);
return $this->paymentMethods()->setDefault($id);
}
/**
* Get billing portal URL for the current user.
*
* @param string|null $returnUrl The URL to redirect to after the user has finished in the billing portal. * @param string|null $returnUrl The URL to redirect to after the user has finished in the billing portal.
* @param array $options Additional options for the billing portal. * @param array $options Additional options for the billing portal.
* @throws Throwable * @throws Throwable

View File

@@ -0,0 +1,23 @@
<?php
namespace Anikeen\Id\Concerns;
use Anikeen\Id\ApiOperations\Get;
use Anikeen\Id\Resources\SocialiteUsers;
use Throwable;
trait ManagesSocialiteUsers
{
use Get;
/**
* Get all socialite connections for the authenticated user.
*
* @throws Throwable
*/
public function socialiteUsers(): SocialiteUsers
{
return SocialiteUsers::builder(fn() => $this->get('v1/user/socialite-users'))
->setParent($this);
}
}

View File

@@ -34,20 +34,34 @@ class PaymentMethods extends BaseCollection
* *
* @throws Throwable * @throws Throwable
*/ */
public function defaultPaymentMethod(): PaymentMethod public function defaultPaymentMethod(): PaymentMethod
{ {
if (!isset($this->defaultPaymentMethodCache)) { if (!isset($this->defaultPaymentMethodCache)) {
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId() $this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
->request('GET', 'v1/payment-methods/default'))) ->request('GET', 'v1/payment-methods/default')))
->setBillable($this->billable); ->setBillable($this->billable);
} }
return $this->defaultPaymentMethodCache; return $this->defaultPaymentMethodCache;
} }
/** /**
* {@inheritDoc} * Set the default payment method for the current user.
* *
* @throws Throwable
*/
public function setDefault(string $id): PaymentMethod
{
unset($this->defaultPaymentMethodCache);
return (new PaymentMethod(fn() => $this->billable->anikeenId()
->request('PUT', sprintf('v1/payment-methods/%s/default', $id))))
->setBillable($this->billable);
}
/**
* {@inheritDoc}
*
* @throws Throwable * @throws Throwable
*/ */
public function find(string $id): ?PaymentMethod public function find(string $id): ?PaymentMethod
@@ -56,4 +70,4 @@ class PaymentMethods extends BaseCollection
->request('GET', sprintf('v1/payment-methods/%s', $id)))) ->request('GET', sprintf('v1/payment-methods/%s', $id))))
->setBillable($this->billable); ->setBillable($this->billable);
} }
} }

View File

@@ -0,0 +1,18 @@
<?php
namespace Anikeen\Id\Resources;
/**
* @property string $id
* @property string $user_id
* @property string $driver
* @property string $uid
* @property string|null $display_name
* @property string|null $avatar
* @property string|null $expires_at
* @property string $created_at
* @property string $updated_at
*/
class SocialiteUser extends BaseResource
{
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Anikeen\Id\Resources;
use Anikeen\Id\Concerns\HasParent;
class SocialiteUsers extends BaseCollection
{
use HasParent;
public function find(string $id): ?SocialiteUser
{
return null;
}
}