mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-13 13:46:13 +00:00
@@ -13,7 +13,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0",
|
"php": "^8.1",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"illuminate/support": "^11.0|^12.0",
|
"illuminate/support": "^11.0|^12.0",
|
||||||
"illuminate/console": "^11.0|^12.0",
|
"illuminate/console": "^11.0|^12.0",
|
||||||
|
|||||||
@@ -6,12 +6,34 @@ use stdClass;
|
|||||||
|
|
||||||
trait MagicProperties
|
trait MagicProperties
|
||||||
{
|
{
|
||||||
protected function setMagicProperties(stdClass $data): void
|
protected function setMagicProperties(stdClass|array $data): void
|
||||||
{
|
{
|
||||||
foreach ($data as $key => $value) {
|
foreach ((object)$data as $key => $value) {
|
||||||
if (!property_exists($this, $key)) {
|
if (!property_exists($this, $key)) {
|
||||||
$this->{$key} = $value;
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,9 @@ trait ManagesInvoices
|
|||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function invoices(): Invoices
|
public function invoices(array $parameters = []): Invoices
|
||||||
{
|
{
|
||||||
return (new Invoices($this->request('GET', 'v1/invoices')))
|
return (new Invoices($this->request('GET', 'v1/invoices', [], $parameters)))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,9 +18,9 @@ trait ManagesOrders
|
|||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function orders(): Orders
|
public function orders(array $parameters = []): Orders
|
||||||
{
|
{
|
||||||
return (new Orders($this->request('GET', 'v1/orders')))
|
return (new Orders($this->request('GET', 'v1/orders', [], $parameters)))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
|
use Anikeen\Id\Concerns\MagicProperties;
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
abstract class BaseCollection implements JsonSerializable
|
abstract class BaseCollection implements JsonSerializable
|
||||||
{
|
{
|
||||||
|
use MagicProperties;
|
||||||
|
|
||||||
public function __construct(protected Result $result)
|
public function __construct(protected Result $result)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -102,13 +102,12 @@ class Order extends BaseResource
|
|||||||
/**
|
/**
|
||||||
* Get order items from given order.
|
* Get order items from given order.
|
||||||
*
|
*
|
||||||
* @param string $orderId The order ID.
|
|
||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function orderItems(string $orderId): OrderItems
|
public function orderItems(array $parameters = []): OrderItems
|
||||||
{
|
{
|
||||||
return (new OrderItems($this->billable->request('GET', sprintf('v1/orders/%s/items', $this->id))))
|
return (new OrderItems($this->billable->request('GET', sprintf('v1/orders/%s/items', $this->id), [], $parameters)))
|
||||||
->setBillable($this->billable)
|
->setBillable($this->billable)
|
||||||
->setParent($this);
|
->setParent($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ namespace Anikeen\Id\Resources;
|
|||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $id
|
||||||
|
*/
|
||||||
class PaymentMethod extends BaseResource
|
class PaymentMethod extends BaseResource
|
||||||
{
|
{
|
||||||
use HasBillable;
|
use HasBillable;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ class PaymentMethods extends BaseCollection
|
|||||||
{
|
{
|
||||||
use HasBillable;
|
use HasBillable;
|
||||||
|
|
||||||
|
private ?PaymentMethod $cachedDefaultPaymentMethod = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if current user has at least one payment method.
|
* Check if current user has at least one payment method.
|
||||||
*
|
*
|
||||||
@@ -30,8 +32,24 @@ class PaymentMethods extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function defaultPaymentMethod(): PaymentMethod
|
public function defaultPaymentMethod(): PaymentMethod
|
||||||
{
|
{
|
||||||
return (new PaymentMethod($this->billable->request('GET', 'v1/payment-methods/default')))
|
if ($this->cachedDefaultPaymentMethod === null) {
|
||||||
->setBillable($this->billable);
|
$this->cachedDefaultPaymentMethod = (new PaymentMethod(
|
||||||
|
$this->billable->request('GET', 'v1/payment-methods/default')
|
||||||
|
))->setBillable($this->billable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cachedDefaultPaymentMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current user has a default payment method.
|
||||||
|
*
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function hasDefaultPaymentMethod(): bool
|
||||||
|
{
|
||||||
|
return $this->defaultPaymentMethod()?->id !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ use GuzzleHttp\Exception\GuzzleException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string $id
|
* @property string $id
|
||||||
|
* @property string $name
|
||||||
|
* @property string $description
|
||||||
|
* @property string $status
|
||||||
|
* @property string $unit
|
||||||
|
* @property float $price
|
||||||
|
* @property string $ends_at
|
||||||
*/
|
*/
|
||||||
class Subscription extends BaseResource
|
class Subscription extends BaseResource
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user