mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-14 22:26:14 +00:00
Compare commits
15 Commits
1.0.0-rc.2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bc9c202c3b | |||
| cecf8560ff | |||
| 25248e7822 | |||
| c641ec725d | |||
| 8eb0c25582 | |||
| 30ac4ae4f9 | |||
| e1a6af11a3 | |||
| bb5df7f115 | |||
| 297404b05d | |||
| 5ab57dcdfe | |||
| 0f14fa1b4c | |||
| 437e78770c | |||
| 0dbb27fc94 | |||
|
|
8232de4003 | ||
|
|
ac3e28f67f |
@@ -15,14 +15,15 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"illuminate/support": "^11.0|^12.0",
|
"illuminate/support": "^10.0|^11.0|^12.0",
|
||||||
"illuminate/console": "^11.0|^12.0",
|
"illuminate/console": "^10.0|^11.0|^12.0",
|
||||||
"guzzlehttp/guzzle": "^6.3|^7.0",
|
"guzzlehttp/guzzle": "^6.3|^7.0",
|
||||||
"socialiteproviders/manager": "^3.4|^4.0.1",
|
"socialiteproviders/manager": "^3.4|^4.0.1",
|
||||||
"firebase/php-jwt": "^6.0"
|
"firebase/php-jwt": "^6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^8.0|^9.0"
|
"phpunit/phpunit": "^8.0|^9.0",
|
||||||
|
"laravel/framework": "^10.0|^11.0|^12.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -49,4 +50,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
oauth-public.staging.key
Normal file
14
oauth-public.staging.key
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAi4Ta8r01zKaGSnGi1EiD
|
||||||
|
uMFWRXBlK4y/ZIfWBpElmS2ygv4mGeP3hT4Flm696Z2UMy56KC+c7CC/PQCiutLk
|
||||||
|
5NUphyX/t+0QS5Dqpw6FB33fLTNNY7GqSmGIUE4os8XYZRSyDQRgtOgq3R3vJkoV
|
||||||
|
7zoavTJmSCQlG5Qf0T//iMmzQ+b+6VZm1CJSz5nGx94u1DuXNyP5Epkk0wuHrtwy
|
||||||
|
kADR2lmydNodJzqpSD+8yQqnAhOZNtNF4qwQ3g13fRvHycBp3G2nlCfOn2g5PmYD
|
||||||
|
KYBKqvTq4PQH4E+K3pbbMz6zf/T6Dw7zTfksqHR4hqMgN6byRRxmwuBczIumcu9b
|
||||||
|
y7xbgoIGIVZXgJliALPFi+zTPTN7c8MedFs/xCBHCmzWYTCZfHgr8RPRewD19tCG
|
||||||
|
NSny5R0vlArpuZCTTgedPESDeGU4eNEddg4yXFzKlpE2nNuvzZ1Ohruc5ETOSU19
|
||||||
|
RTCBUBkjeL6ESZRd/yKGjbVx4dEYxZdIz4yBl+hZ2ZOIyG7L3zPrccAWrPpG56xr
|
||||||
|
E5IDBXxLFhaJ5LlyEAGQehB0ShEuCdkr88Xz7ba9PHpGqY83l4//ULrqPIZPAa4Z
|
||||||
|
E3AWHT1ZtXNPeA4SzZ9Y9Oij4M3chyHxqM0lL3kYP+dstZehTujStfElDIx2Ni10
|
||||||
|
73tILu4edYS0FxsL19m8gbsCAwEAAQ==
|
||||||
|
-----END PUBLIC KEY-----
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<php>
|
<php>
|
||||||
<env name="ANIKEEN_ID_KEY" value="38"/>
|
<env name="ANIKEEN_ID_KEY" value="38"/>
|
||||||
<env name="ANIKEEN_ID_SECRET" value="2goNRF8x37HPVZVaa28ySZGVXJuksvxnxM7TcGzM"/>
|
<env name="ANIKEEN_ID_SECRET" value="2goNRF8x37HPVZVaa28ySZGVXJuksvxnxM7TcGzM"/>
|
||||||
<env name="ANIKEEN_ID_BASE_URL" value="https://id.anikeen.com/api/"/>
|
<env name="ANIKEEN_ID_BASE_URL" value="https://id.anikeen.com"/>
|
||||||
<env name="CLIENT_ACCESS_TOKEN" value="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxNSIsImp0aSI6IjAxN2QxZDg0Y2MxNjAyZTYxOGZkNjYwZGViZWVjMDY4MTk2YmYzMDk1OGMzY2RiYzBjZmJkZWFjZjFhOTUxODQzZDU1YTk3OGY2YWIxY2YzIiwiaWF0IjoxNjY0NjIzMzA4LjQyODI4MSwibmJmIjoxNjY0NjIzMzA4LjQyODI4NCwiZXhwIjoxNjgwMzQ4MTA4LjQxNjc4MSwic3ViIjoiMzkiLCJzY29wZXMiOlsiYXBpIiwicmVhZF91c2VyIl0sImNsaWVudCI6eyJ0cnVzdGVkIjpmYWxzZX19.vxnzCaU4PpOrNVHa5AnGSS6gX_RCvxIERAnHFhjTrUzRafV9mr2Cvwd-BDVYoUr10wHvxa_TJSYfnAdDuhE-MEyDv13O3dL2XGTtJNa_Rg6L6CQ0JvC3wL-lWPvGPFax9pu-_lqbA3jm5B08hc3-7tq3f2nXcxjhtkqT6TTJv1-RCAppb2HCXiUDAqANzbhyInDjOH2WvFj1OGC_AI03J3W2KRWyeFLtUne8XKPFyr9XGcPuTrqogcuuXLeUt2kcf2bXbuIV1OlgIECrDiP1Ee0F2AzPs27ZVJ2z0R0JbT6AubKhGl5_Qi27cwjOH7hT2dmjcF1mLjzpN1uChLIdSnGSoStH8VzYHnHE2I8G-owW_aadG2UmGdnRY143q6g_28f3WIZNSucBSXkwFeS_t4fylsvpxhpjYJusf5qiEU_X3YbeawYMUCFUkSD2XTIypAqMJLNZQAeJ52eyL-9fln-Bv7n9v7K9G6ieR6Tm0tsJ1PRnaQi7rA1NTFwHoQmIOW9tfMycLzT7bgSoz3ra6Ez2J7ZNuWBZNKS0O-0YfSrAWyWK5U8YRfQuSVzP2VrIU63K6RGU2c284PfQGy11kgKUNQPykirb8p7MDQ8PwrxKaylBnD6hhDgjqEh2bfsr_43DfJA0R58L1HK3BmQnxgap0C77wK1e0yNlABpN28Q"/>
|
<env name="CLIENT_ACCESS_TOKEN" value="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxNSIsImp0aSI6IjAxN2QxZDg0Y2MxNjAyZTYxOGZkNjYwZGViZWVjMDY4MTk2YmYzMDk1OGMzY2RiYzBjZmJkZWFjZjFhOTUxODQzZDU1YTk3OGY2YWIxY2YzIiwiaWF0IjoxNjY0NjIzMzA4LjQyODI4MSwibmJmIjoxNjY0NjIzMzA4LjQyODI4NCwiZXhwIjoxNjgwMzQ4MTA4LjQxNjc4MSwic3ViIjoiMzkiLCJzY29wZXMiOlsiYXBpIiwicmVhZF91c2VyIl0sImNsaWVudCI6eyJ0cnVzdGVkIjpmYWxzZX19.vxnzCaU4PpOrNVHa5AnGSS6gX_RCvxIERAnHFhjTrUzRafV9mr2Cvwd-BDVYoUr10wHvxa_TJSYfnAdDuhE-MEyDv13O3dL2XGTtJNa_Rg6L6CQ0JvC3wL-lWPvGPFax9pu-_lqbA3jm5B08hc3-7tq3f2nXcxjhtkqT6TTJv1-RCAppb2HCXiUDAqANzbhyInDjOH2WvFj1OGC_AI03J3W2KRWyeFLtUne8XKPFyr9XGcPuTrqogcuuXLeUt2kcf2bXbuIV1OlgIECrDiP1Ee0F2AzPs27ZVJ2z0R0JbT6AubKhGl5_Qi27cwjOH7hT2dmjcF1mLjzpN1uChLIdSnGSoStH8VzYHnHE2I8G-owW_aadG2UmGdnRY143q6g_28f3WIZNSucBSXkwFeS_t4fylsvpxhpjYJusf5qiEU_X3YbeawYMUCFUkSD2XTIypAqMJLNZQAeJ52eyL-9fln-Bv7n9v7K9G6ieR6Tm0tsJ1PRnaQi7rA1NTFwHoQmIOW9tfMycLzT7bgSoz3ra6Ez2J7ZNuWBZNKS0O-0YfSrAWyWK5U8YRfQuSVzP2VrIU63K6RGU2c284PfQGy11kgKUNQPykirb8p7MDQ8PwrxKaylBnD6hhDgjqEh2bfsr_43DfJA0R58L1HK3BmQnxgap0C77wK1e0yNlABpN28Q"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
@@ -46,16 +46,6 @@ class AnikeenId
|
|||||||
*/
|
*/
|
||||||
public static bool $unserializesCookies = false;
|
public static bool $unserializesCookies = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* The base URL for Anikeen ID API.
|
|
||||||
*/
|
|
||||||
private static string $baseUrl = 'https://id.anikeen.com/api/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The staging base URL for Anikeen ID API.
|
|
||||||
*/
|
|
||||||
private static string $stagingBaseUrl = 'https://staging.id.anikeen.com/api/';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key for the access token.
|
* The key for the access token.
|
||||||
*/
|
*/
|
||||||
@@ -96,6 +86,16 @@ class AnikeenId
|
|||||||
*/
|
*/
|
||||||
protected ?string $redirectUri = null;
|
protected ?string $redirectUri = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base URL for Anikeen ID.
|
||||||
|
*/
|
||||||
|
protected string $baseUrl = 'https://id.anikeen.com';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The staging base URL for Anikeen ID.
|
||||||
|
*/
|
||||||
|
protected string $stagingBaseUrl = 'https://staging.id.anikeen.com';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@@ -110,25 +110,25 @@ class AnikeenId
|
|||||||
if ($redirectUri = config('services.anikeen.redirect')) {
|
if ($redirectUri = config('services.anikeen.redirect')) {
|
||||||
$this->setRedirectUri($redirectUri);
|
$this->setRedirectUri($redirectUri);
|
||||||
}
|
}
|
||||||
if (config('services.anikeen.mode') === 'staging') {
|
if (self::getMode() === 'staging' && !config('services.anikeen.base_url')) {
|
||||||
self::setBaseUrl(self::$stagingBaseUrl);
|
self::setBaseUrl($this->stagingBaseUrl);
|
||||||
}
|
}
|
||||||
if ($baseUrl = config('services.anikeen.base_url')) {
|
if ($baseUrl = config('services.anikeen.base_url')) {
|
||||||
self::setBaseUrl($baseUrl);
|
self::setBaseUrl($baseUrl);
|
||||||
}
|
}
|
||||||
$this->client = new Client([
|
$this->client = new Client([
|
||||||
'base_uri' => self::$baseUrl,
|
'base_uri' => $this->baseUrl . '/api/',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function setBaseUrl(string $baseUrl): void
|
||||||
* @param string $baseUrl
|
|
||||||
*
|
|
||||||
* @internal only for internal and debug purposes.
|
|
||||||
*/
|
|
||||||
public static function setBaseUrl(string $baseUrl): void
|
|
||||||
{
|
{
|
||||||
self::$baseUrl = $baseUrl;
|
$this->baseUrl = $baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaseUrl(): string
|
||||||
|
{
|
||||||
|
return rtrim($this->baseUrl, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function useAccessTokenField(string $accessTokenField): void
|
public static function useAccessTokenField(string $accessTokenField): void
|
||||||
@@ -141,6 +141,11 @@ class AnikeenId
|
|||||||
return self::$accessTokenField;
|
return self::$accessTokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMode(): string
|
||||||
|
{
|
||||||
|
return config('services.anikeen.mode') ?: 'production';
|
||||||
|
}
|
||||||
|
|
||||||
public static function useRefreshTokenField(string $refreshTokenField): void
|
public static function useRefreshTokenField(string $refreshTokenField): void
|
||||||
{
|
{
|
||||||
self::$refreshTokenField = $refreshTokenField;
|
self::$refreshTokenField = $refreshTokenField;
|
||||||
@@ -322,7 +327,7 @@ class AnikeenId
|
|||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
*/
|
*/
|
||||||
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null): Result
|
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null, bool $useClientSecret = false): Result
|
||||||
{
|
{
|
||||||
if ($paginator !== null) {
|
if ($paginator !== null) {
|
||||||
$parameters[$paginator->action] = $paginator->cursor();
|
$parameters[$paginator->action] = $paginator->cursor();
|
||||||
@@ -330,7 +335,7 @@ class AnikeenId
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client->request($method, $path, [
|
$response = $this->client->request($method, $path, [
|
||||||
'headers' => $this->buildHeaders((bool)$payload),
|
'headers' => $this->buildHeaders((bool)$payload, $useClientSecret),
|
||||||
'query' => Query::build($parameters),
|
'query' => Query::build($parameters),
|
||||||
'json' => $payload ?: null,
|
'json' => $payload ?: null,
|
||||||
]);
|
]);
|
||||||
@@ -348,14 +353,14 @@ class AnikeenId
|
|||||||
*
|
*
|
||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
*/
|
*/
|
||||||
private function buildHeaders(bool $json = false): array
|
private function buildHeaders(bool $json = false, bool $useClientSecret = false): array
|
||||||
{
|
{
|
||||||
$headers = [
|
$headers = [
|
||||||
'Client-ID' => $this->getClientId(),
|
'Client-ID' => $this->getClientId(),
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
];
|
];
|
||||||
if ($this->token) {
|
if ($bearerToken = $useClientSecret ? $this->getClientSecret() : $this->getToken()) {
|
||||||
$headers['Authorization'] = 'Bearer ' . $this->token;
|
$headers['Authorization'] = 'Bearer ' . $bearerToken;
|
||||||
}
|
}
|
||||||
if ($json) {
|
if ($json) {
|
||||||
$headers['Content-Type'] = 'application/json';
|
$headers['Content-Type'] = 'application/json';
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id;
|
namespace Anikeen\Id;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Concerns\ManagesAddresses;
|
use Anikeen\Id\Concerns\ManagesAddresses;
|
||||||
use Anikeen\Id\Concerns\ManagesBalance;
|
use Anikeen\Id\Concerns\ManagesBalance;
|
||||||
use Anikeen\Id\Concerns\ManagesCountries;
|
use Anikeen\Id\Concerns\ManagesCountries;
|
||||||
@@ -13,8 +12,6 @@ use Anikeen\Id\Concerns\ManagesProfile;
|
|||||||
use Anikeen\Id\Concerns\ManagesSubscriptions;
|
use Anikeen\Id\Concerns\ManagesSubscriptions;
|
||||||
use Anikeen\Id\Concerns\ManagesTaxation;
|
use Anikeen\Id\Concerns\ManagesTaxation;
|
||||||
use Anikeen\Id\Concerns\ManagesTransactions;
|
use Anikeen\Id\Concerns\ManagesTransactions;
|
||||||
use Anikeen\Id\Helpers\Paginator;
|
|
||||||
use stdClass;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait Billable
|
trait Billable
|
||||||
@@ -29,31 +26,27 @@ trait Billable
|
|||||||
use ManagesSubscriptions;
|
use ManagesSubscriptions;
|
||||||
use ManagesTaxation;
|
use ManagesTaxation;
|
||||||
use ManagesTransactions;
|
use ManagesTransactions;
|
||||||
use Request;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently authenticated user.
|
* Get the currently authenticated user.
|
||||||
*
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function getUserData(): stdClass
|
public function getUserData(): object
|
||||||
{
|
{
|
||||||
if (!isset($this->userDataCache)) {
|
if (!isset($this->userDataCache)) {
|
||||||
$this->userDataCache = $this->request('GET', 'v1/user')->data;
|
$this->userDataCache = $this->anikeenId()->request('GET', 'v1/user')->data;
|
||||||
}
|
}
|
||||||
return $this->userDataCache;
|
return $this->userDataCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a request to the Anikeen API.
|
* Get the AnikeenId class.
|
||||||
*
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function request(string $method, string $path, null|array $payload = null, array $parameters = [], ?Paginator $paginator = null): Result
|
public function anikeenId(): AnikeenId
|
||||||
{
|
{
|
||||||
$anikeenId = new AnikeenId();
|
return app(AnikeenId::class)->withToken($this->{AnikeenId::getAccessTokenField()});
|
||||||
$anikeenId->withToken($this->{AnikeenId::getAccessTokenField()});
|
|
||||||
|
|
||||||
return $anikeenId->request($method, $path, $payload, $parameters, $paginator);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,21 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
|
use Anikeen\Id\Contracts\Billable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
trait HasBillable
|
trait HasBillable
|
||||||
{
|
{
|
||||||
public mixed $billable;
|
public Billable|Model $billable;
|
||||||
|
|
||||||
public function setBillable(mixed $billable): self
|
public function setBillable(Billable|Model $billable): self
|
||||||
{
|
{
|
||||||
$this->billable = $billable;
|
$this->billable = $billable;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBillable(): mixed
|
public function getBillable(): Billable
|
||||||
{
|
{
|
||||||
return $this->billable;
|
return $this->billable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Addresses;
|
use Anikeen\Id\Resources\Addresses;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesAddresses
|
trait ManagesAddresses
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get addresses from the current user.
|
* Get addresses from the current user.
|
||||||
@@ -19,7 +17,8 @@ trait ManagesAddresses
|
|||||||
public function addresses(): Addresses
|
public function addresses(): Addresses
|
||||||
{
|
{
|
||||||
if (!isset($this->addressesCache)) {
|
if (!isset($this->addressesCache)) {
|
||||||
$this->addressesCache = Addresses::builder(fn() => $this->request('GET', 'v1/addresses'))
|
$this->addressesCache = Addresses::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/addresses'))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,8 +28,8 @@ trait ManagesAddresses
|
|||||||
/**
|
/**
|
||||||
* Check if the current user has a default billing address.
|
* Check if the current user has a default billing address.
|
||||||
*
|
*
|
||||||
* @see \Anikeen\Id\Resources\Addresses::hasDefaultBillingAddress()
|
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
* @see \Anikeen\Id\Resources\Addresses::hasDefaultBillingAddress()
|
||||||
*/
|
*/
|
||||||
public function hasDefaultBillingAddress(): bool
|
public function hasDefaultBillingAddress(): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Resources\Transaction;
|
use Anikeen\Id\Resources\Transaction;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesBalance
|
trait ManagesBalance
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get balance from the current user.
|
* Get balance from the current user.
|
||||||
@@ -40,10 +39,12 @@ trait ManagesBalance
|
|||||||
*/
|
*/
|
||||||
public function charge(float $amount, string $paymentMethodId, array $options = []): Transaction
|
public function charge(float $amount, string $paymentMethodId, array $options = []): Transaction
|
||||||
{
|
{
|
||||||
return new Transaction(fn() => $this->request('POST', 'billing/charge', [
|
return (new Transaction(fn() => $this->anikeenId()
|
||||||
'amount' => $amount,
|
->request('POST', 'billing/charge', [
|
||||||
'payment_method_id' => $paymentMethodId,
|
'amount' => $amount,
|
||||||
'options' => $options,
|
'payment_method_id' => $paymentMethodId,
|
||||||
]));
|
'options' => $options,
|
||||||
|
])))
|
||||||
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Countries;
|
use Anikeen\Id\Resources\Countries;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesCountries
|
trait ManagesCountries
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get available countries for the current user.
|
* Get available countries for the current user.
|
||||||
@@ -19,7 +17,8 @@ trait ManagesCountries
|
|||||||
public function countries(): Countries
|
public function countries(): Countries
|
||||||
{
|
{
|
||||||
if (!isset($this->countriesCache)) {
|
if (!isset($this->countriesCache)) {
|
||||||
$this->countriesCache = Countries::builder(fn() => $this->request('GET', 'v1/countries'))
|
$this->countriesCache = Countries::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/countries'))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Invoices;
|
use Anikeen\Id\Resources\Invoices;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesInvoices
|
trait ManagesInvoices
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get invoices from the current user.
|
* Get invoices from the current user.
|
||||||
@@ -19,7 +17,8 @@ trait ManagesInvoices
|
|||||||
public function invoices(array $parameters = []): Invoices
|
public function invoices(array $parameters = []): Invoices
|
||||||
{
|
{
|
||||||
if (!isset($this->invoicesCache)) {
|
if (!isset($this->invoicesCache)) {
|
||||||
$this->invoicesCache = Invoices::builder(fn() => $this->request('GET', 'v1/invoices', [], $parameters))
|
$this->invoicesCache = Invoices::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/invoices', [], $parameters))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Orders;
|
use Anikeen\Id\Resources\Orders;
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesOrders
|
trait ManagesOrders
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get orders from the current user.
|
* Get orders from the current user.
|
||||||
@@ -20,7 +17,8 @@ trait ManagesOrders
|
|||||||
public function orders(array $parameters = []): Orders
|
public function orders(array $parameters = []): Orders
|
||||||
{
|
{
|
||||||
if (!isset($this->ordersCache)) {
|
if (!isset($this->ordersCache)) {
|
||||||
$this->ordersCache = Orders::builder(fn() => $this->request('GET', 'v1/orders', [], $parameters))
|
$this->ordersCache = Orders::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/orders', [], $parameters))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\PaymentMethod;
|
use Anikeen\Id\Resources\PaymentMethod;
|
||||||
use Anikeen\Id\Resources\PaymentMethods;
|
use Anikeen\Id\Resources\PaymentMethods;
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
@@ -11,7 +9,7 @@ use Throwable;
|
|||||||
|
|
||||||
trait ManagesPaymentMethods
|
trait ManagesPaymentMethods
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get payment methods from the current user.
|
* Get payment methods from the current user.
|
||||||
@@ -20,10 +18,10 @@ trait ManagesPaymentMethods
|
|||||||
*/
|
*/
|
||||||
public function paymentMethods(): PaymentMethods
|
public function paymentMethods(): PaymentMethods
|
||||||
{
|
{
|
||||||
if (!isset($this->paymentMethodsCache)) {;
|
if (!isset($this->paymentMethodsCache)) {
|
||||||
$this->paymentMethodsCache = PaymentMethods::builder(
|
$this->paymentMethodsCache = PaymentMethods::builder(fn() => $this->anikeenId()
|
||||||
fn() => $this->request('GET', 'v1/payment-methods')
|
->request('GET', 'v1/payment-methods'))
|
||||||
)->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->paymentMethodsCache;
|
return $this->paymentMethodsCache;
|
||||||
@@ -32,8 +30,8 @@ trait ManagesPaymentMethods
|
|||||||
/**
|
/**
|
||||||
* Check if current user has at least one payment method.
|
* Check if current user has at least one payment method.
|
||||||
*
|
*
|
||||||
* @see \Anikeen\Id\Resources\PaymentMethods::hasPaymentMethod()
|
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
* @see \Anikeen\Id\Resources\PaymentMethods::hasPaymentMethod()
|
||||||
*/
|
*/
|
||||||
public function hasPaymentMethod(): ?PaymentMethod
|
public function hasPaymentMethod(): ?PaymentMethod
|
||||||
{
|
{
|
||||||
@@ -43,8 +41,8 @@ trait ManagesPaymentMethods
|
|||||||
/**
|
/**
|
||||||
* Get default payment method from the current user.
|
* Get default payment method from the current user.
|
||||||
*
|
*
|
||||||
* @see \Anikeen\Id\Resources\PaymentMethods::defaultPaymentMethod()
|
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
* @see \Anikeen\Id\Resources\PaymentMethods::defaultPaymentMethod()
|
||||||
*/
|
*/
|
||||||
public function defaultPaymentMethod(): ?PaymentMethod
|
public function defaultPaymentMethod(): ?PaymentMethod
|
||||||
{
|
{
|
||||||
@@ -54,8 +52,8 @@ trait ManagesPaymentMethods
|
|||||||
/**
|
/**
|
||||||
* Check if the current user has a default payment method.
|
* Check if the current user has a default payment method.
|
||||||
*
|
*
|
||||||
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
|
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
|
||||||
*/
|
*/
|
||||||
public function hasDefaultPaymentMethod(): bool
|
public function hasDefaultPaymentMethod(): bool
|
||||||
{
|
{
|
||||||
@@ -71,10 +69,13 @@ trait ManagesPaymentMethods
|
|||||||
*/
|
*/
|
||||||
public function billingPortalUrl(?string $returnUrl = null, array $options = []): string
|
public function billingPortalUrl(?string $returnUrl = null, array $options = []): string
|
||||||
{
|
{
|
||||||
return $this->request('POST', 'v1/billing/portal', [
|
return $this->anikeenId()
|
||||||
'return_url' => $returnUrl,
|
->request('POST', 'v1/billing/portal', [
|
||||||
'options' => $options,
|
'return_url' => $returnUrl,
|
||||||
])->data->url;
|
'options' => $options,
|
||||||
|
])
|
||||||
|
->data
|
||||||
|
->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,8 +86,9 @@ trait ManagesPaymentMethods
|
|||||||
*/
|
*/
|
||||||
public function createSetupIntent(array $options = []): Result
|
public function createSetupIntent(array $options = []): Result
|
||||||
{
|
{
|
||||||
return $this->request('POST', 'v1/payment-methods', [
|
return $this->anikeenId()
|
||||||
'options' => $options,
|
->request('POST', 'v1/payment-methods', [
|
||||||
]);
|
'options' => $options,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Post;
|
use Anikeen\Id\ApiOperations\Post;
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesProfile
|
trait ManagesProfile
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the profile url for the current user.
|
* Get the profile url for the current user.
|
||||||
@@ -21,7 +18,7 @@ trait ManagesProfile
|
|||||||
*/
|
*/
|
||||||
public function profilePortalUrl(?string $returnUrl = null, array $options = []): string
|
public function profilePortalUrl(?string $returnUrl = null, array $options = []): string
|
||||||
{
|
{
|
||||||
return $this->request('POST', 'v1/user/profile', [
|
return $this->anikeenId()->request('POST', 'v1/user/profile', [
|
||||||
'return_url' => $returnUrl,
|
'return_url' => $returnUrl,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
])->data->url;
|
])->data->url;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Get;
|
use Anikeen\Id\ApiOperations\Get;
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\SshKeys;
|
use Anikeen\Id\Resources\SshKeys;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Subscriptions;
|
use Anikeen\Id\Resources\Subscriptions;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesSubscriptions
|
trait ManagesSubscriptions
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get subscriptions from the current user.
|
* Get subscriptions from the current user.
|
||||||
@@ -19,7 +17,8 @@ trait ManagesSubscriptions
|
|||||||
public function subscriptions(): Subscriptions
|
public function subscriptions(): Subscriptions
|
||||||
{
|
{
|
||||||
if (!isset($this->subscriptionsCache)) {
|
if (!isset($this->subscriptionsCache)) {
|
||||||
$this->subscriptionsCache = Subscriptions::builder(fn() => $this->request('GET', 'v1/subscriptions'))
|
$this->subscriptionsCache = Subscriptions::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/subscriptions'))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesTaxation
|
trait ManagesTaxation
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get VAT for the current user.
|
* Get VAT for the current user.
|
||||||
|
|||||||
@@ -2,15 +2,12 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Concerns;
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Resources\Transactions;
|
use Anikeen\Id\Resources\Transactions;
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
trait ManagesTransactions
|
trait ManagesTransactions
|
||||||
{
|
{
|
||||||
use Request;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get transactions from the current user.
|
* Get transactions from the current user.
|
||||||
@@ -20,7 +17,8 @@ trait ManagesTransactions
|
|||||||
public function transactions(): Transactions
|
public function transactions(): Transactions
|
||||||
{
|
{
|
||||||
if (!isset($this->transactionsCache)) {
|
if (!isset($this->transactionsCache)) {
|
||||||
$this->transactionsCache = Transactions::builder(fn() => $this->request('GET', 'v1/transactions'))
|
$this->transactionsCache = Transactions::builder(fn() => $this->anikeenId()
|
||||||
|
->request('GET', 'v1/transactions'))
|
||||||
->setBillable($this);
|
->setBillable($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ namespace Anikeen\Id\Concerns;
|
|||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Get;
|
use Anikeen\Id\ApiOperations\Get;
|
||||||
use Anikeen\Id\ApiOperations\Post;
|
use Anikeen\Id\ApiOperations\Post;
|
||||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -52,11 +51,11 @@ trait ManagesUsers
|
|||||||
public function refreshToken(string $storedRefreshToken, string $scope = ''): Result
|
public function refreshToken(string $storedRefreshToken, string $scope = ''): Result
|
||||||
{
|
{
|
||||||
return $this->post('../oauth/token', [
|
return $this->post('../oauth/token', [
|
||||||
'grant_type' => 'refresh_token',
|
'grant_type' => 'refresh_token',
|
||||||
'refresh_token' => $storedRefreshToken,
|
'refresh_token' => $storedRefreshToken,
|
||||||
'client_id' => $this->clientId,
|
'client_id' => $this->clientId,
|
||||||
'client_secret' => $this->clientSecret,
|
'client_secret' => $this->clientSecret,
|
||||||
'scope' => $scope,
|
'scope' => $scope,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/Id/Contracts/Billable.php
Normal file
12
src/Id/Contracts/Billable.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Anikeen\Id\Contracts;
|
||||||
|
|
||||||
|
use Anikeen\Id\AnikeenId;
|
||||||
|
|
||||||
|
interface Billable
|
||||||
|
{
|
||||||
|
public function getUserData(): object;
|
||||||
|
|
||||||
|
public function anikeenId(): AnikeenId;
|
||||||
|
}
|
||||||
@@ -6,11 +6,35 @@ class Scope
|
|||||||
{
|
{
|
||||||
const USER = 'user';
|
const USER = 'user';
|
||||||
const USER_READ = 'user:read';
|
const USER_READ = 'user:read';
|
||||||
const ORDERS = 'orders';
|
|
||||||
const ORDERS_READ = 'orders:read';
|
const ADDRESSES = 'addresses';
|
||||||
const PRODUCTS = 'products';
|
const ADDRESSES_READ = 'addresses:read';
|
||||||
const PRODUCTS_READ = 'products:read';
|
|
||||||
const BILLING = 'billing';
|
const BILLING = 'billing';
|
||||||
const BILLING_READ = 'billing:read';
|
const BILLING_READ = 'billing:read';
|
||||||
|
const BILLING_CLIENT = 'billing:client';
|
||||||
|
|
||||||
|
const INVOICES = 'invoices';
|
||||||
|
const INVOICES_READ = 'invoices:read';
|
||||||
|
const INVOICES_CLIENT = 'invoices:client';
|
||||||
|
|
||||||
|
const ORDERS = 'orders';
|
||||||
|
const ORDERS_READ = 'orders:read';
|
||||||
|
const ORDERS_CLIENT = 'orders:client';
|
||||||
|
|
||||||
|
const PAYMENT_METHODS = 'payment-methods';
|
||||||
|
const PAYMENT_METHODS_READ = 'payment-methods:read';
|
||||||
|
|
||||||
|
const SUBSCRIPTIONS = 'subscriptions';
|
||||||
|
const SUBSCRIPTIONS_READ = 'subscriptions:read';
|
||||||
|
const SUBSCRIPTIONS_CLIENT = 'subscriptions:client';
|
||||||
|
|
||||||
|
const TRANSACTIONS = 'transactions';
|
||||||
|
const TRANSACTIONS_READ = 'transactions:read';
|
||||||
|
const TRANSACTIONS_CLIENT = 'transactions:client';
|
||||||
|
|
||||||
|
const SSH_KEYS = 'ssh-keys';
|
||||||
|
const SSH_KEYS_READ = 'ssh-keys:read';
|
||||||
|
|
||||||
const ADMIN = 'admin';
|
const ADMIN = 'admin';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Helpers;
|
namespace Anikeen\Id\Helpers;
|
||||||
|
|
||||||
|
use Anikeen\Id\AnikeenId;
|
||||||
use Firebase\JWT\JWT;
|
use Firebase\JWT\JWT;
|
||||||
use Firebase\JWT\Key;
|
use Firebase\JWT\Key;
|
||||||
use Illuminate\Auth\AuthenticationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
@@ -30,6 +31,8 @@ class JwtParser
|
|||||||
|
|
||||||
private function getOauthPublicKey(): bool|string
|
private function getOauthPublicKey(): bool|string
|
||||||
{
|
{
|
||||||
return file_get_contents(dirname(__DIR__, 3) . '/oauth-public.key');
|
return AnikeenId::getMode() === 'staging'
|
||||||
|
? file_get_contents(dirname(__DIR__, 3) . '/oauth-public.staging.key')
|
||||||
|
: file_get_contents(dirname(__DIR__, 3) . '/oauth-public.key');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use Illuminate\Auth\AuthenticationException;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
abstract class CheckCredentials
|
abstract class CheckCredentials extends UseParameters
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Illuminate\Auth\AuthenticationException;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class CheckForAnyScope
|
class CheckForAnyScope extends UseParameters
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle the incoming request.
|
* Handle the incoming request.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Illuminate\Auth\AuthenticationException;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class CheckScopes
|
class CheckScopes extends UseParameters
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle the incoming request.
|
* Handle the incoming request.
|
||||||
|
|||||||
20
src/Id/Http/Middleware/UseParameters.php
Normal file
20
src/Id/Http/Middleware/UseParameters.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Anikeen\Id\Http\Middleware;
|
||||||
|
|
||||||
|
abstract class UseParameters
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Specify the parameters for the middleware.
|
||||||
|
*
|
||||||
|
* @param string[]|string $param
|
||||||
|
*/
|
||||||
|
public static function using(array|string $param, string ...$params): string
|
||||||
|
{
|
||||||
|
if (is_array($param)) {
|
||||||
|
return static::class . ':' . implode(',', $param);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static::class . ':' . implode(',', [$param, ...$params]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,13 +23,11 @@ trait OauthTrait
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$result = new Result($response, null);
|
$result = new Result($response, null, $this);
|
||||||
} catch (RequestException $exception) {
|
} catch (RequestException $exception) {
|
||||||
$result = new Result($exception->getResponse(), $exception);
|
$result = new Result($exception->getResponse(), $exception, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->anikeenId = $this;
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ class Address extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function update(array $attributes = []): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ class Address extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function delete(): bool
|
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
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,8 +56,9 @@ class Addresses extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function find(string $id): ?Address
|
public function find(string $id): ?Address
|
||||||
{
|
{
|
||||||
return (new Address(fn() => $this->billable->request('GET', sprintf('v1/addresses/%s', $id))))
|
return (new Address(fn() => $this->billable->anikeenId()
|
||||||
->setBillable($this->billable);
|
->request('GET', sprintf('v1/addresses/%s', $id))))
|
||||||
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,7 +68,8 @@ class Addresses extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function defaultBillingAddress(): Address
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace Anikeen\Id\Resources;
|
|||||||
|
|
||||||
use Anikeen\Id\AnikeenId;
|
use Anikeen\Id\AnikeenId;
|
||||||
use Anikeen\Id\Exceptions\CollectionException;
|
use Anikeen\Id\Exceptions\CollectionException;
|
||||||
use Anikeen\Id\Exceptions\ResourceException;
|
|
||||||
use Anikeen\Id\Helpers\Paginator;
|
use Anikeen\Id\Helpers\Paginator;
|
||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use Closure;
|
use Closure;
|
||||||
@@ -24,6 +23,7 @@ use Throwable;
|
|||||||
* @property Response $response
|
* @property Response $response
|
||||||
* @property null|Throwable $exception
|
* @property null|Throwable $exception
|
||||||
*/
|
*/
|
||||||
|
#[\AllowDynamicProperties]
|
||||||
abstract class BaseCollection implements JsonSerializable
|
abstract class BaseCollection implements JsonSerializable
|
||||||
{
|
{
|
||||||
private Closure $callable;
|
private Closure $callable;
|
||||||
@@ -87,4 +87,4 @@ abstract class BaseCollection implements JsonSerializable
|
|||||||
{
|
{
|
||||||
return isset($this->result->{$name});
|
return isset($this->result->{$name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use Anikeen\Id\Exceptions\ResourceException;
|
|||||||
use Anikeen\Id\Result;
|
use Anikeen\Id\Result;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
abstract class BaseResource implements JsonSerializable
|
#[\AllowDynamicProperties]
|
||||||
|
abstract class BaseResource implements JsonSerializable
|
||||||
{
|
{
|
||||||
public Result $result;
|
public Result $result;
|
||||||
|
|
||||||
@@ -53,4 +54,4 @@ abstract class BaseResource implements JsonSerializable
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ class Invoice extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function getInvoiceTemporaryUrl(): string
|
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
|
public function find(string $id): ?Invoice
|
||||||
{
|
{
|
||||||
return (new Invoice(fn() => $this->billable->request('GET', sprintf('v1/invoices/%s', $id))))
|
return (new Invoice(fn() => $this->billable->anikeenId()
|
||||||
->setBillable($this->billable);
|
->request('GET', sprintf('v1/invoices/%s', $id))))
|
||||||
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,8 @@ class Order extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function update(array $attributes = []): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,8 @@ class Order extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function checkout(): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +82,8 @@ class Order extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function revoke(): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +94,8 @@ class Order extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function delete(): bool
|
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
|
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)
|
->setBillable($this->billable)
|
||||||
->setParent($this);
|
->setParent($this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ class OrderItem extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function update(array $attributes = []): self
|
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)
|
->setBillable($this->billable)
|
||||||
->setParent($this->parent);
|
->setParent($this->parent);
|
||||||
}
|
}
|
||||||
@@ -46,6 +47,7 @@ class OrderItem extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function delete(): bool
|
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\HasBillable;
|
||||||
use Anikeen\Id\Concerns\HasParent;
|
use Anikeen\Id\Concerns\HasParent;
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class OrderItems extends BaseCollection
|
class OrderItems extends BaseCollection
|
||||||
@@ -33,7 +32,8 @@ class OrderItems extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function create(string $orderId, array $attributes = []): OrderItem
|
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)
|
->setBillable($this->billable)
|
||||||
->setParent($this->parent);
|
->setParent($this->parent);
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,8 @@ class OrderItems extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function find(string $id): ?OrderItem
|
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)
|
->setBillable($this->billable)
|
||||||
->setParent($this->parent);
|
->setParent($this->parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Orders extends BaseCollection
|
class Orders extends BaseCollection
|
||||||
@@ -65,7 +64,8 @@ class Orders extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function create(array $attributes = []): Order
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,8 @@ class Orders extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function find(string $id): ?Order
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,8 @@ class PaymentMethods extends BaseCollection
|
|||||||
public function defaultPaymentMethod(): PaymentMethod
|
public function defaultPaymentMethod(): PaymentMethod
|
||||||
{
|
{
|
||||||
if (!isset($this->defaultPaymentMethodCache)) {
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,10 +47,13 @@ class PaymentMethods extends BaseCollection
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function find(string $id): ?PaymentMethod
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Concerns\HasParent;
|
use Anikeen\Id\Concerns\HasParent;
|
||||||
use Anikeen\Id\Result;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class SshKeys extends BaseCollection
|
class SshKeys extends BaseCollection
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
|
use Anikeen\Id\Contracts\AppTokenRepository;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +51,8 @@ class Subscription extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function update(array $attributes): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +63,8 @@ class Subscription extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function checkout(): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +73,14 @@ class Subscription extends BaseResource
|
|||||||
*
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function revoke(): self
|
public function revoke(bool $refund = false): self
|
||||||
{
|
{
|
||||||
return (new self(fn() => $this->billable->request('PUT', sprintf('v1/subscriptions/%s/revoke', $this->id))))
|
$attributes = [
|
||||||
|
'refund' => $refund,
|
||||||
|
];
|
||||||
|
|
||||||
|
return (new self(fn() => $this->billable->anikeenId()
|
||||||
|
->request('PUT', sprintf('v1/subscriptions/%s/revoke', $this->id), $attributes)))
|
||||||
->setBillable($this->billable);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +91,8 @@ class Subscription extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function pause(): self
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,17 +103,8 @@ class Subscription extends BaseResource
|
|||||||
*/
|
*/
|
||||||
public function resume(): self
|
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);
|
->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;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
|
use Anikeen\Id\Contracts\AppTokenRepository;
|
||||||
|
use Anikeen\Id\Exceptions\ResourceException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Subscriptions extends BaseCollection
|
class Subscriptions extends BaseCollection
|
||||||
@@ -38,16 +40,20 @@ class Subscriptions extends BaseCollection
|
|||||||
*/
|
*/
|
||||||
public function create(array $attributes): Subscription
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @throws ResourceException
|
||||||
*/
|
*/
|
||||||
public function find(string $id): ?Subscription
|
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);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,32 +3,18 @@
|
|||||||
namespace Anikeen\Id\Resources;
|
namespace Anikeen\Id\Resources;
|
||||||
|
|
||||||
use Anikeen\Id\Concerns\HasBillable;
|
use Anikeen\Id\Concerns\HasBillable;
|
||||||
use Anikeen\Id\Exceptions\ResourceException;
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class Transactions extends BaseCollection
|
class Transactions extends BaseCollection
|
||||||
{
|
{
|
||||||
use HasBillable;
|
use HasBillable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new transaction for the current user.
|
|
||||||
*
|
|
||||||
* @param array $attributes The attributes for the transaction.
|
|
||||||
* @throws Throwable
|
|
||||||
* @todo Add type hinting for the attributes array.
|
|
||||||
*/
|
|
||||||
public function create(array $attributes = []): Transaction
|
|
||||||
{
|
|
||||||
return (new Transaction($this->billable->request('POST', 'v1/transactions', $attributes)))
|
|
||||||
->setBillable($this->billable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function find(string $id): ?Transaction
|
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()
|
||||||
->setBillable($this->billable);
|
->request('GET', sprintf('v1/transactions/%s', $id))))
|
||||||
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Anikeen\Id\Socialite;
|
namespace Anikeen\Id\Socialite;
|
||||||
|
|
||||||
|
use Anikeen\Id\AnikeenId;
|
||||||
use Anikeen\Id\Enums\Scope;
|
use Anikeen\Id\Enums\Scope;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -32,11 +33,7 @@ class Provider extends AbstractProvider implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
protected function getBaseUrl(): string
|
protected function getBaseUrl(): string
|
||||||
{
|
{
|
||||||
$mode = config('services.anikeen.mode') ?? 'production';
|
return app(AnikeenId::class)->getBaseUrl();
|
||||||
|
|
||||||
return $mode === 'staging'
|
|
||||||
? 'https://staging.id.anikeen.com'
|
|
||||||
: 'https://id.anikeen.com';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,4 +95,12 @@ class Provider extends AbstractProvider implements ProviderInterface
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user logout url for the provider.
|
||||||
|
*/
|
||||||
|
public function getLogoutUrl(string $redirect = null): string
|
||||||
|
{
|
||||||
|
return app(AnikeenId::class)->getBaseUrl() . '/logout?redirect=' . urlencode($redirect ?: '/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user