mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-16 15:16:26 +00:00
update resources
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Concerns;
|
||||
|
||||
use stdClass;
|
||||
|
||||
trait MagicProperties
|
||||
{
|
||||
protected function setMagicProperties(stdClass|array $data): void
|
||||
{
|
||||
foreach ((object)$data as $key => $value) {
|
||||
if (!property_exists($this, $key)) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter: return null for undefined properties
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic isset: return false for undefined properties
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Addresses;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesAddresses
|
||||
{
|
||||
@@ -14,21 +14,23 @@ trait ManagesAddresses
|
||||
/**
|
||||
* Get addresses from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function addresses(): Addresses
|
||||
{
|
||||
return (new Addresses($this->request('GET', 'v1/addresses')))
|
||||
->setBillable($this);
|
||||
if (!isset($this->addressesCache)) {
|
||||
$this->addressesCache = Addresses::builder(fn() => $this->request('GET', 'v1/addresses'))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->addressesCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user has a default billing address.
|
||||
*
|
||||
* @see \Anikeen\Id\Resources\Addresses::hasDefaultBillingAddress()
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function hasDefaultBillingAddress(): bool
|
||||
{
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
namespace Anikeen\Id\Concerns;
|
||||
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Transaction;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesBalance
|
||||
{
|
||||
@@ -15,8 +13,7 @@ trait ManagesBalance
|
||||
/**
|
||||
* Get balance from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function balance(): float
|
||||
{
|
||||
@@ -26,8 +23,7 @@ trait ManagesBalance
|
||||
/**
|
||||
* Get charges from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function charges(): float
|
||||
{
|
||||
@@ -40,12 +36,11 @@ trait ManagesBalance
|
||||
* @param float $amount Amount to charge in euros.
|
||||
* @param string $paymentMethodId Payment method ID.
|
||||
* @param array $options Additional options for the charge.
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function charge(float $amount, string $paymentMethodId, array $options = []): Transaction
|
||||
{
|
||||
return new Transaction($this->request('POST', 'billing/charge', [
|
||||
return new Transaction(fn() => $this->request('POST', 'billing/charge', [
|
||||
'amount' => $amount,
|
||||
'payment_method_id' => $paymentMethodId,
|
||||
'options' => $options,
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Countries;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesCountries
|
||||
{
|
||||
@@ -14,12 +14,15 @@ trait ManagesCountries
|
||||
/**
|
||||
* Get available countries for the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function countries(): Countries
|
||||
{
|
||||
return (new Countries($this->request('GET', 'v1/countries')))
|
||||
->setBillable($this);
|
||||
if (!isset($this->countriesCache)) {
|
||||
$this->countriesCache = Countries::builder(fn() => $this->request('GET', 'v1/countries'))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->countriesCache;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Invoices;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesInvoices
|
||||
{
|
||||
@@ -14,12 +14,15 @@ trait ManagesInvoices
|
||||
/**
|
||||
* Get invoices from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function invoices(array $parameters = []): Invoices
|
||||
{
|
||||
return (new Invoices($this->request('GET', 'v1/invoices', [], $parameters)))
|
||||
->setBillable($this);
|
||||
if (!isset($this->invoicesCache)) {
|
||||
$this->invoicesCache = Invoices::builder(fn() => $this->request('GET', 'v1/invoices', [], $parameters))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->invoicesCache;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Orders;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesOrders
|
||||
{
|
||||
@@ -15,12 +15,15 @@ trait ManagesOrders
|
||||
/**
|
||||
* Get orders from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function orders(array $parameters = []): Orders
|
||||
{
|
||||
return (new Orders($this->request('GET', 'v1/orders', [], $parameters)))
|
||||
->setBillable($this);
|
||||
if (!isset($this->ordersCache)) {
|
||||
$this->ordersCache = Orders::builder(fn() => $this->request('GET', 'v1/orders', [], $parameters))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->ordersCache;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\PaymentMethod;
|
||||
use Anikeen\Id\Resources\PaymentMethods;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesPaymentMethods
|
||||
{
|
||||
@@ -16,21 +16,24 @@ trait ManagesPaymentMethods
|
||||
/**
|
||||
* Get payment methods from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function paymentMethods(): PaymentMethods
|
||||
{
|
||||
return (new PaymentMethods($this->request('GET', 'v1/payment-methods')))
|
||||
->setBillable($this);
|
||||
if (!isset($this->paymentMethodsCache)) {;
|
||||
$this->paymentMethodsCache = PaymentMethods::builder(
|
||||
fn() => $this->request('GET', 'v1/payment-methods')
|
||||
)->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->paymentMethodsCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current user has at least one payment method.
|
||||
*
|
||||
* @see \Anikeen\Id\Resources\PaymentMethods::hasPaymentMethod()
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function hasPaymentMethod(): ?PaymentMethod
|
||||
{
|
||||
@@ -41,8 +44,7 @@ trait ManagesPaymentMethods
|
||||
* Get default payment method from the current user.
|
||||
*
|
||||
* @see \Anikeen\Id\Resources\PaymentMethods::defaultPaymentMethod()
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function defaultPaymentMethod(): ?PaymentMethod
|
||||
{
|
||||
@@ -53,8 +55,7 @@ trait ManagesPaymentMethods
|
||||
* Check if the current user has a default payment method.
|
||||
*
|
||||
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function hasDefaultPaymentMethod(): bool
|
||||
{
|
||||
@@ -66,8 +67,7 @@ trait ManagesPaymentMethods
|
||||
*
|
||||
* @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.
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function billingPortalUrl(?string $returnUrl = null, array $options = []): string
|
||||
{
|
||||
@@ -81,8 +81,7 @@ trait ManagesPaymentMethods
|
||||
* Create a new setup intent.
|
||||
*
|
||||
* @param array $options Additional options for the setup intent.
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function createSetupIntent(array $options = []): Result
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Post;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesPricing
|
||||
{
|
||||
@@ -29,8 +29,7 @@ trait ManagesPricing
|
||||
* } $attributes The order data:
|
||||
* - country_iso: ISO 3166-1 alpha-2 country code
|
||||
* - items: Array of order items (each with type, name, price, unit, units, and quantity)
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function createOrderPreview(array $attributes = []): Result
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesProfile
|
||||
{
|
||||
@@ -17,8 +17,7 @@ trait ManagesProfile
|
||||
* @param string|null $returnUrl The URL to redirect to after the user has completed their profile.
|
||||
* @param array $options Additional options for the profile URL.
|
||||
* @return string
|
||||
* @throws GuzzleException
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function profilePortalUrl(?string $returnUrl = null, array $options = []): string
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Get;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\SshKeys;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesSshKeys
|
||||
{
|
||||
@@ -15,12 +15,15 @@ trait ManagesSshKeys
|
||||
/**
|
||||
* Get currently authed user with Bearer Token.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function sshKeysByUserId(string $sskKeyId): SshKeys
|
||||
{
|
||||
return (new SshKeys($this->get(sprintf('v1/users/%s/ssh-keys/json', $sskKeyId))))
|
||||
->setParent($this);
|
||||
if (!isset($this->sshKeysCache)) {
|
||||
$this->sshKeysCache = SshKeys::builder(fn() => $this->get(sprintf('v1/users/%s/ssh-keys/json', $sskKeyId)))
|
||||
->setParent($this);
|
||||
}
|
||||
|
||||
return $this->sshKeysCache;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Anikeen\Id\Concerns;
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Subscriptions;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesSubscriptions
|
||||
{
|
||||
@@ -14,12 +14,15 @@ trait ManagesSubscriptions
|
||||
/**
|
||||
* Get subscriptions from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function subscriptions(): Subscriptions
|
||||
{
|
||||
return (new Subscriptions($this->request('GET', 'v1/subscriptions')))
|
||||
->setBillable($this);
|
||||
if (!isset($this->subscriptionsCache)) {
|
||||
$this->subscriptionsCache = Subscriptions::builder(fn() => $this->request('GET', 'v1/subscriptions'))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->subscriptionsCache;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Anikeen\Id\Concerns;
|
||||
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesTaxation
|
||||
{
|
||||
@@ -13,11 +13,10 @@ trait ManagesTaxation
|
||||
/**
|
||||
* Get VAT for the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function vat(): float
|
||||
public function vatRate(): float
|
||||
{
|
||||
return $this->getUserData()->vat;
|
||||
return $this->getUserData()->vat_rate;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Resources\Transactions;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesTransactions
|
||||
{
|
||||
@@ -15,12 +15,15 @@ trait ManagesTransactions
|
||||
/**
|
||||
* Get transactions from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function transactions(): Transactions
|
||||
{
|
||||
return (new Transactions($this->request('GET', 'v1/transactions')))
|
||||
->setBillable($this);;
|
||||
if (!isset($this->transactionsCache)) {
|
||||
$this->transactionsCache = Transactions::builder(fn() => $this->request('GET', 'v1/transactions'))
|
||||
->setBillable($this);
|
||||
}
|
||||
|
||||
return $this->transactionsCache;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use Anikeen\Id\ApiOperations\Get;
|
||||
use Anikeen\Id\ApiOperations\Post;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Throwable;
|
||||
|
||||
trait ManagesUsers
|
||||
{
|
||||
@@ -17,8 +17,7 @@ trait ManagesUsers
|
||||
/**
|
||||
* Get currently authed user with Bearer Token
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function getAuthedUser(): Result
|
||||
{
|
||||
@@ -40,8 +39,7 @@ trait ManagesUsers
|
||||
* - username: The username (optional)
|
||||
* - email: The email (required)
|
||||
* - password: The password (optional, can be reset by the user if not provided)
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function createUser(array $attributes): Result
|
||||
{
|
||||
@@ -52,8 +50,7 @@ trait ManagesUsers
|
||||
* Checks if the given email exists.
|
||||
*
|
||||
* @param string $email The email to check.
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function isEmailExisting(string $email): Result
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user