mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-20 09:06:12 +00:00
refactor code
This commit is contained in:
@@ -65,7 +65,8 @@ class Address extends BaseResource
|
||||
*/
|
||||
public function update(array $attributes = []): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/addresses/%s', $this->id), $attributes)))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/addresses/%s', $this->id), $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ class Address extends BaseResource
|
||||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->billable->request('DELETE', sprintf('v1/addresses/%s', $this->id))->success();
|
||||
return $this->billable->anikeenId()
|
||||
->request('DELETE', sprintf('v1/addresses/%s', $this->id))->success();
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,8 @@ class Addresses extends BaseCollection
|
||||
*/
|
||||
public function create(array $attributes = []): Address
|
||||
{
|
||||
return (new Address(fn() => $this->billable->request('POST', 'v1/addresses', $attributes)))
|
||||
return (new Address(fn() => $this->billable->anikeenId()
|
||||
->request('POST', 'v1/addresses', $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -55,8 +56,9 @@ class Addresses extends BaseCollection
|
||||
*/
|
||||
public function find(string $id): ?Address
|
||||
{
|
||||
return (new Address(fn() => $this->billable->request('GET', sprintf('v1/addresses/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
return (new Address(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/addresses/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +68,8 @@ class Addresses extends BaseCollection
|
||||
*/
|
||||
public function defaultBillingAddress(): Address
|
||||
{
|
||||
return (new Address(fn() => $this->billable->request('GET', sprintf('v1/addresses/%s', $this->billable->getUserData()->billing_address_id))))
|
||||
return (new Address(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/addresses/%s', $this->billable->getUserData()->billing_address_id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\AnikeenId;
|
||||
use Anikeen\Id\Exceptions\CollectionException;
|
||||
use Anikeen\Id\Exceptions\ResourceException;
|
||||
use Anikeen\Id\Helpers\Paginator;
|
||||
use Anikeen\Id\Result;
|
||||
use Closure;
|
||||
@@ -24,8 +23,8 @@ use Throwable;
|
||||
* @property Response $response
|
||||
* @property null|Throwable $exception
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
abstract class BaseCollection implements JsonSerializable
|
||||
#[\AllowDynamicProperties]
|
||||
abstract class BaseCollection implements JsonSerializable
|
||||
{
|
||||
private Closure $callable;
|
||||
public ?Result $result = null;
|
||||
@@ -88,4 +87,4 @@ abstract class BaseCollection implements JsonSerializable
|
||||
{
|
||||
return isset($this->result->{$name});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ class Invoice extends BaseResource
|
||||
*/
|
||||
public function getInvoiceTemporaryUrl(): string
|
||||
{
|
||||
return $this->billable->request('PUT', sprintf('v1/invoices/%s', $this->id))->data->temporary_url;
|
||||
return $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/invoices/%s', $this->id))
|
||||
->data
|
||||
->temporary_url;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ class Invoices extends BaseCollection
|
||||
*/
|
||||
public function find(string $id): ?Invoice
|
||||
{
|
||||
return (new Invoice(fn() => $this->billable->request('GET', sprintf('v1/invoices/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
return (new Invoice(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/invoices/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,8 @@ class Order extends BaseResource
|
||||
*/
|
||||
public function update(array $attributes = []): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/orders/%s', $this->id), $attributes)))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/orders/%s', $this->id), $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,8 @@ class Order extends BaseResource
|
||||
*/
|
||||
public function checkout(): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/orders/%s/checkout', $this->id))))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/orders/%s/checkout', $this->id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -80,7 +82,8 @@ class Order extends BaseResource
|
||||
*/
|
||||
public function revoke(): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/orders/%s/revoke', $this->id))))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/orders/%s/revoke', $this->id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -91,7 +94,8 @@ class Order extends BaseResource
|
||||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->billable->request('DELETE', sprintf('v1/orders/%s', $this->id))->success();
|
||||
return $this->billable->anikeenId()
|
||||
->request('DELETE', sprintf('v1/orders/%s', $this->id))->success();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +105,8 @@ class Order extends BaseResource
|
||||
*/
|
||||
public function orderItems(array $parameters = []): OrderItems
|
||||
{
|
||||
return OrderItems::builder(fn() => $this->billable->request('GET', sprintf('v1/orders/%s/items', $this->id), [], $parameters))
|
||||
return OrderItems::builder(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/orders/%s/items', $this->id), [], $parameters))
|
||||
->setBillable($this->billable)
|
||||
->setParent($this);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ class OrderItem extends BaseResource
|
||||
*/
|
||||
public function update(array $attributes = []): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/orders/%s/items/%s', $this->parent->id, $this->id), $attributes)))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/orders/%s/items/%s', $this->parent->id, $this->id), $attributes)))
|
||||
->setBillable($this->billable)
|
||||
->setParent($this->parent);
|
||||
}
|
||||
@@ -46,6 +47,7 @@ class OrderItem extends BaseResource
|
||||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->billable->request('DELETE', sprintf('v1/orders/%s/items/%s', $this->parent->id, $this->id))->success();
|
||||
return $this->billable->anikeenId()
|
||||
->request('DELETE', sprintf('v1/orders/%s/items/%s', $this->parent->id, $this->id))->success();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Concerns\HasParent;
|
||||
use Anikeen\Id\Result;
|
||||
use Throwable;
|
||||
|
||||
class OrderItems extends BaseCollection
|
||||
@@ -33,7 +32,8 @@ class OrderItems extends BaseCollection
|
||||
*/
|
||||
public function create(string $orderId, array $attributes = []): OrderItem
|
||||
{
|
||||
return (new OrderItem(fn() => $this->billable->request('POST', sprintf('v1/orders/%s', $orderId), $attributes)))
|
||||
return (new OrderItem(fn() => $this->billable->anikeenId()
|
||||
->request('POST', sprintf('v1/orders/%s', $orderId), $attributes)))
|
||||
->setBillable($this->billable)
|
||||
->setParent($this->parent);
|
||||
}
|
||||
@@ -43,7 +43,8 @@ class OrderItems extends BaseCollection
|
||||
*/
|
||||
public function find(string $id): ?OrderItem
|
||||
{
|
||||
return (new OrderItem(fn() => $this->parent->request('GET', sprintf('v1/orders/%s/items/%s', $this->parent->id, $id))))
|
||||
return (new OrderItem(fn() => $this->parent->anikeenId()
|
||||
->request('GET', sprintf('v1/orders/%s/items/%s', $this->parent->id, $id))))
|
||||
->setBillable($this->billable)
|
||||
->setParent($this->parent);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Result;
|
||||
use Throwable;
|
||||
|
||||
class Orders extends BaseCollection
|
||||
@@ -65,7 +64,8 @@ class Orders extends BaseCollection
|
||||
*/
|
||||
public function create(array $attributes = []): Order
|
||||
{
|
||||
return (new Order(fn() => $this->billable->request('POST', 'v1/orders', $attributes)))
|
||||
return (new Order(fn() => $this->billable->anikeenId()
|
||||
->request('POST', 'v1/orders', $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ class Orders extends BaseCollection
|
||||
*/
|
||||
public function find(string $id): ?Order
|
||||
{
|
||||
return (new Order(fn() => $this->billable->request('GET', sprintf('v1/orders/%s', $id))))
|
||||
return (new Order(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/orders/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ class PaymentMethods extends BaseCollection
|
||||
public function defaultPaymentMethod(): PaymentMethod
|
||||
{
|
||||
if (!isset($this->defaultPaymentMethodCache)) {
|
||||
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->request('GET', 'v1/payment-methods/default')))
|
||||
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
|
||||
->request('GET', 'v1/payment-methods/default')))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -46,10 +47,13 @@ class PaymentMethods extends BaseCollection
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function find(string $id): ?PaymentMethod
|
||||
{
|
||||
return (new PaymentMethod(fn() => $this->billable->request('GET', sprintf('v1/payment-methods/%s', $id))))
|
||||
return (new PaymentMethod(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/payment-methods/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasParent;
|
||||
use Anikeen\Id\Result;
|
||||
use Throwable;
|
||||
|
||||
class SshKeys extends BaseCollection
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Contracts\AppTokenRepository;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,8 @@ class Subscription extends BaseResource
|
||||
*/
|
||||
public function update(array $attributes): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s', $this->id), $attributes)))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/subscriptions/%s', $this->id), $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -61,7 +63,8 @@ class Subscription extends BaseResource
|
||||
*/
|
||||
public function checkout(): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s/checkout', $this->id))))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/subscriptions/%s/checkout', $this->id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -76,7 +79,8 @@ class Subscription extends BaseResource
|
||||
'refund' => $refund,
|
||||
];
|
||||
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s/revoke', $this->id), $attributes)))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/subscriptions/%s/revoke', $this->id), $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -87,7 +91,8 @@ class Subscription extends BaseResource
|
||||
*/
|
||||
public function pause(): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s/pause', $this->id))))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/subscriptions/%s/pause', $this->id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
@@ -98,17 +103,8 @@ class Subscription extends BaseResource
|
||||
*/
|
||||
public function resume(): self
|
||||
{
|
||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s/resume', $this->id))))
|
||||
return (new self(fn() => $this->billable->anikeenId()
|
||||
->request('PUT', sprintf('v1/subscriptions/%s/resume', $this->id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a given subscription from the current user.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function delete(): bool
|
||||
{
|
||||
return $this->billable->request('DELETE', sprintf('v1/subscriptions/%s', $this->id))->success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Contracts\AppTokenRepository;
|
||||
use Anikeen\Id\Exceptions\ResourceException;
|
||||
use Throwable;
|
||||
|
||||
class Subscriptions extends BaseCollection
|
||||
@@ -38,16 +40,20 @@ class Subscriptions extends BaseCollection
|
||||
*/
|
||||
public function create(array $attributes): Subscription
|
||||
{
|
||||
return (new Subscription(fn() => $this->billable->request('POST', 'v1/subscriptions', $attributes)))
|
||||
return (new Subscription(fn() => $this->billable->anikeenId()
|
||||
->request('POST', 'v1/subscriptions', $attributes)))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws ResourceException
|
||||
*/
|
||||
public function find(string $id): ?Subscription
|
||||
{
|
||||
return (new Subscription(fn() => $this->billable->request('GET', sprintf('v1/subscriptions/%s', $id))))
|
||||
return (new Subscription(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/subscriptions/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace Anikeen\Id\Resources;
|
||||
|
||||
use Anikeen\Id\Concerns\HasBillable;
|
||||
use Anikeen\Id\Exceptions\ResourceException;
|
||||
use Throwable;
|
||||
|
||||
class Transactions extends BaseCollection
|
||||
{
|
||||
@@ -15,7 +13,8 @@ class Transactions extends BaseCollection
|
||||
*/
|
||||
public function find(string $id): ?Transaction
|
||||
{
|
||||
return (new Transaction(fn() => $this->billable->request('GET', sprintf('v1/transactions/%s', $id))))
|
||||
return (new Transaction(fn() => $this->billable->anikeenId()
|
||||
->request('GET', sprintf('v1/transactions/%s', $id))))
|
||||
->setBillable($this->billable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user