mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-15 22:56:13 +00:00
Compare commits
5 Commits
1.0.0-alph
...
1.0.0-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
4d6fe7c325
|
|||
|
d447a88430
|
|||
|
d9a330222b
|
|||
|
21946e3a22
|
|||
|
1b96b87e1d
|
113
README.md
113
README.md
@@ -9,13 +9,11 @@ PHP Anikeen ID API Client for Laravel 11+
|
|||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
1. [Installation](#installation)
|
1. [Installation](#installation)
|
||||||
2. [Event Listener](#event-listener)
|
2. [Configuration](#configuration)
|
||||||
3. [Configuration](#configuration)
|
3. [General](#general)
|
||||||
4. [Implementing Auth](#implementing-auth)
|
4. [Examples](#examples)
|
||||||
5. [General](#general)
|
5. [Documentation](#documentation)
|
||||||
6. [Examples](#examples)
|
6. [Development](#Development)
|
||||||
7. [Documentation](#documentation)
|
|
||||||
8. [Development](#Development)
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -23,19 +21,9 @@ PHP Anikeen ID API Client for Laravel 11+
|
|||||||
composer require anikeen/id
|
composer require anikeen/id
|
||||||
```
|
```
|
||||||
|
|
||||||
## Event Listener
|
|
||||||
|
|
||||||
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your `AppServiceProvider`
|
|
||||||
|
|
||||||
```
|
|
||||||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
|
||||||
$event->extendSocialite('anikeen-id', \Anikeen\Id\Socialite\Provider::class);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Add environmental variables to your `.env`
|
Add environmental variables to your `.env` file:
|
||||||
|
|
||||||
```
|
```
|
||||||
ANIKEEN_ID_KEY=
|
ANIKEEN_ID_KEY=
|
||||||
@@ -43,12 +31,19 @@ ANIKEEN_ID_SECRET=
|
|||||||
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
|
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To switch from `production` to `staging` use following variable:
|
||||||
|
|
||||||
|
```
|
||||||
|
ANIKEEN_ID_MODE=staging
|
||||||
|
```
|
||||||
|
|
||||||
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
||||||
|
|
||||||
**Add to `config/services.php`:**
|
Add to `config/services.php` file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'anikeen' => [
|
'anikeen' => [
|
||||||
|
'mode' => env('ANIKEEN_ID_MODE'),
|
||||||
'client_id' => env('ANIKEEN_ID_KEY'),
|
'client_id' => env('ANIKEEN_ID_KEY'),
|
||||||
'client_secret' => env('ANIKEEN_ID_SECRET'),
|
'client_secret' => env('ANIKEEN_ID_SECRET'),
|
||||||
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
|
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
|
||||||
@@ -56,13 +51,63 @@ You will need to add an entry to the services configuration file so that after c
|
|||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Event Listener
|
||||||
|
|
||||||
|
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your `AppServiceProvider` boot method:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$middleware->web(append: [
|
public function boot(): void
|
||||||
\Anikeen\Id\Http\Middleware\CreateFreshApiToken::class,
|
{
|
||||||
]);
|
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||||
|
$event->extendSocialite('anikeen-id', \Anikeen\Id\Socialite\Provider::class);
|
||||||
|
});
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Implementing Auth
|
### Registering Middleware
|
||||||
|
|
||||||
|
Append it to the global middleware stack in your application's `bootstrap/app.php` file:
|
||||||
|
|
||||||
|
```php
|
||||||
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
|
$middleware->web(append: [
|
||||||
|
\Anikeen\Id\Http\Middleware\CreateFreshApiToken::class,
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementing Billable
|
||||||
|
|
||||||
|
To implement the `Billable` trait, you need to add the `Billable` trait to your user model.
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Anikeen\Id\Billable;
|
||||||
|
|
||||||
|
class User extends Authenticatable
|
||||||
|
{
|
||||||
|
use Billable;
|
||||||
|
|
||||||
|
// Your model code...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
then, you can use the `Billable` trait methods in your user model.
|
||||||
|
|
||||||
|
### Change the default access token / refresh token field name
|
||||||
|
|
||||||
|
If you access / refresh token fields differs from the default `anikeen_id_access_token` / `anikeen_id_refresh_token`, you can specify the field name in the `AppServiceProvider` boot method:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Anikeen\Id\AnikeenId;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
AnikeenId::useAccessTokenField('anikeen_id_access_token');
|
||||||
|
AnikeenId::useRefreshTokenField('anikeen_id_refresh_token');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementing Auth
|
||||||
|
|
||||||
This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
|
This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
|
||||||
|
|
||||||
@@ -71,12 +116,7 @@ use Anikeen\Id\AnikeenId;
|
|||||||
use Anikeen\Id\Providers\AnikeenIdSsoUserProvider;
|
use Anikeen\Id\Providers\AnikeenIdSsoUserProvider;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
/**
|
public function boot(): void
|
||||||
* Register any authentication / authorization services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
{
|
||||||
Auth::provider('sso-users', function ($app, array $config) {
|
Auth::provider('sso-users', function ($app, array $config) {
|
||||||
return new AnikeenIdSsoUserProvider(
|
return new AnikeenIdSsoUserProvider(
|
||||||
@@ -84,7 +124,6 @@ public function boot()
|
|||||||
$app->make(Request::class),
|
$app->make(Request::class),
|
||||||
$config['model'],
|
$config['model'],
|
||||||
$config['fields'] ?? [],
|
$config['fields'] ?? [],
|
||||||
$config['access_token_field'] ?? null
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,7 +158,6 @@ reference the provider in the `providers` configuration of your `auth.php` confi
|
|||||||
'driver' => 'sso-users',
|
'driver' => 'sso-users',
|
||||||
'model' => App\Models\User::class,
|
'model' => App\Models\User::class,
|
||||||
'fields' => ['first_name', 'last_name', 'email'],
|
'fields' => ['first_name', 'last_name', 'email'],
|
||||||
'access_token_field' => 'sso_access_token',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
@@ -272,6 +310,16 @@ public function isEmailExisting(string $email): Result
|
|||||||
|
|
||||||
## Billable
|
## Billable
|
||||||
|
|
||||||
|
### ManagesAddresses
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function addresses(): Result
|
||||||
|
public function createAddress(array $attributes = []): Result
|
||||||
|
public function address(string $addressId): Result
|
||||||
|
public function updateAddress(string $addressId, array $attributes = []): Result
|
||||||
|
public function deleteAddress(string $addressId): Result
|
||||||
|
```
|
||||||
|
|
||||||
### ManagesBalance
|
### ManagesBalance
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@@ -285,7 +333,7 @@ public function charge(float $amount, string $paymentMethodId, array $options =
|
|||||||
```php
|
```php
|
||||||
public function invoices(): Result
|
public function invoices(): Result
|
||||||
public function invoice(string $invoiceId): Result
|
public function invoice(string $invoiceId): Result
|
||||||
public function getInvoiceDownloadUrl(string $invoiceId): string
|
public function getInvoiceTemporaryUrl(string $invoiceId): string
|
||||||
```
|
```
|
||||||
|
|
||||||
### ManagesOrders
|
### ManagesOrders
|
||||||
@@ -325,6 +373,7 @@ public function createSubscription(array $attributes): Result
|
|||||||
public function checkoutSubscription(string $subscriptionId): Result
|
public function checkoutSubscription(string $subscriptionId): Result
|
||||||
public function revokeSubscription(string $subscriptionId): Result
|
public function revokeSubscription(string $subscriptionId): Result
|
||||||
public function resumeSubscription(string $subscriptionId): Result
|
public function resumeSubscription(string $subscriptionId): Result
|
||||||
|
public function deleteSubscription(string $subscriptionId): Result
|
||||||
```
|
```
|
||||||
|
|
||||||
### ManagesTaxation
|
### ManagesTaxation
|
||||||
|
|||||||
100
README.stub
100
README.stub
@@ -9,13 +9,11 @@ PHP Anikeen ID API Client for Laravel 11+
|
|||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
1. [Installation](#installation)
|
1. [Installation](#installation)
|
||||||
2. [Event Listener](#event-listener)
|
2. [Configuration](#configuration)
|
||||||
3. [Configuration](#configuration)
|
3. [General](#general)
|
||||||
4. [Implementing Auth](#implementing-auth)
|
4. [Examples](#examples)
|
||||||
5. [General](#general)
|
5. [Documentation](#documentation)
|
||||||
6. [Examples](#examples)
|
6. [Development](#Development)
|
||||||
7. [Documentation](#documentation)
|
|
||||||
8. [Development](#Development)
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -23,19 +21,9 @@ PHP Anikeen ID API Client for Laravel 11+
|
|||||||
composer require anikeen/id
|
composer require anikeen/id
|
||||||
```
|
```
|
||||||
|
|
||||||
## Event Listener
|
|
||||||
|
|
||||||
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your `AppServiceProvider`
|
|
||||||
|
|
||||||
```
|
|
||||||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
|
||||||
$event->extendSocialite('anikeen-id', \Anikeen\Id\Socialite\Provider::class);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Add environmental variables to your `.env`
|
Add environmental variables to your `.env` file:
|
||||||
|
|
||||||
```
|
```
|
||||||
ANIKEEN_ID_KEY=
|
ANIKEEN_ID_KEY=
|
||||||
@@ -43,12 +31,19 @@ ANIKEEN_ID_SECRET=
|
|||||||
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
|
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To switch from `production` to `staging` use following variable:
|
||||||
|
|
||||||
|
```
|
||||||
|
ANIKEEN_ID_MODE=staging
|
||||||
|
```
|
||||||
|
|
||||||
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
||||||
|
|
||||||
**Add to `config/services.php`:**
|
Add to `config/services.php` file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'anikeen' => [
|
'anikeen' => [
|
||||||
|
'mode' => env('ANIKEEN_ID_MODE'),
|
||||||
'client_id' => env('ANIKEEN_ID_KEY'),
|
'client_id' => env('ANIKEEN_ID_KEY'),
|
||||||
'client_secret' => env('ANIKEEN_ID_SECRET'),
|
'client_secret' => env('ANIKEEN_ID_SECRET'),
|
||||||
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
|
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
|
||||||
@@ -56,13 +51,63 @@ You will need to add an entry to the services configuration file so that after c
|
|||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Event Listener
|
||||||
|
|
||||||
|
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your `AppServiceProvider` boot method:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$middleware->web(append: [
|
public function boot(): void
|
||||||
\Anikeen\Id\Http\Middleware\CreateFreshApiToken::class,
|
{
|
||||||
]);
|
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||||
|
$event->extendSocialite('anikeen-id', \Anikeen\Id\Socialite\Provider::class);
|
||||||
|
});
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Implementing Auth
|
### Registering Middleware
|
||||||
|
|
||||||
|
Append it to the global middleware stack in your application's `bootstrap/app.php` file:
|
||||||
|
|
||||||
|
```php
|
||||||
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
|
$middleware->web(append: [
|
||||||
|
\Anikeen\Id\Http\Middleware\CreateFreshApiToken::class,
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementing Billable
|
||||||
|
|
||||||
|
To implement the `Billable` trait, you need to add the `Billable` trait to your user model.
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Anikeen\Id\Billable;
|
||||||
|
|
||||||
|
class User extends Authenticatable
|
||||||
|
{
|
||||||
|
use Billable;
|
||||||
|
|
||||||
|
// Your model code...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
then, you can use the `Billable` trait methods in your user model.
|
||||||
|
|
||||||
|
### Change the default access token / refresh token field name
|
||||||
|
|
||||||
|
If you access / refresh token fields differs from the default `anikeen_id_access_token` / `anikeen_id_refresh_token`, you can specify the field name in the `AppServiceProvider` boot method:
|
||||||
|
|
||||||
|
```php
|
||||||
|
use Anikeen\Id\AnikeenId;
|
||||||
|
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
AnikeenId::useAccessTokenField('anikeen_id_access_token');
|
||||||
|
AnikeenId::useRefreshTokenField('anikeen_id_refresh_token');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementing Auth
|
||||||
|
|
||||||
This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
|
This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
|
||||||
|
|
||||||
@@ -71,12 +116,7 @@ use Anikeen\Id\AnikeenId;
|
|||||||
use Anikeen\Id\Providers\AnikeenIdSsoUserProvider;
|
use Anikeen\Id\Providers\AnikeenIdSsoUserProvider;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
/**
|
public function boot(): void
|
||||||
* Register any authentication / authorization services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
{
|
||||||
Auth::provider('sso-users', function ($app, array $config) {
|
Auth::provider('sso-users', function ($app, array $config) {
|
||||||
return new AnikeenIdSsoUserProvider(
|
return new AnikeenIdSsoUserProvider(
|
||||||
@@ -84,7 +124,6 @@ public function boot()
|
|||||||
$app->make(Request::class),
|
$app->make(Request::class),
|
||||||
$config['model'],
|
$config['model'],
|
||||||
$config['fields'] ?? [],
|
$config['fields'] ?? [],
|
||||||
$config['access_token_field'] ?? null
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,7 +158,6 @@ reference the provider in the `providers` configuration of your `auth.php` confi
|
|||||||
'driver' => 'sso-users',
|
'driver' => 'sso-users',
|
||||||
'model' => App\Models\User::class,
|
'model' => App\Models\User::class,
|
||||||
'fields' => ['first_name', 'last_name', 'email'],
|
'fields' => ['first_name', 'last_name', 'email'],
|
||||||
'access_token_field' => 'sso_access_token',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -52,14 +52,19 @@ class AnikeenId
|
|||||||
private static string $baseUrl = 'https://id.anikeen.com/api/';
|
private static string $baseUrl = 'https://id.anikeen.com/api/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key for the access token.
|
* The staging base URL for Anikeen ID API.
|
||||||
*/
|
*/
|
||||||
private static string $accessTokenKey = 'anikeen_id_token';
|
private static string $stagingBaseUrl = 'https://staging.id.anikeen.com/api/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key for the access token.
|
* The key for the access token.
|
||||||
*/
|
*/
|
||||||
private static string $refreshTokenKey = 'anikeen_id_refresh_token';
|
private static string $accessTokenField = 'anikeen_id_access_token';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key for the access token.
|
||||||
|
*/
|
||||||
|
private static string $refreshTokenField = 'anikeen_id_refresh_token';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guzzle is used to make http requests.
|
* Guzzle is used to make http requests.
|
||||||
@@ -105,6 +110,9 @@ 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') {
|
||||||
|
self::setBaseUrl(self::$stagingBaseUrl);
|
||||||
|
}
|
||||||
if ($baseUrl = config('services.anikeen.base_url')) {
|
if ($baseUrl = config('services.anikeen.base_url')) {
|
||||||
self::setBaseUrl($baseUrl);
|
self::setBaseUrl($baseUrl);
|
||||||
}
|
}
|
||||||
@@ -123,24 +131,24 @@ class AnikeenId
|
|||||||
self::$baseUrl = $baseUrl;
|
self::$baseUrl = $baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function useAccessTokenKey(string $accessTokenKey): void
|
public static function useAccessTokenField(string $accessTokenField): void
|
||||||
{
|
{
|
||||||
self::$accessTokenKey = $accessTokenKey;
|
self::$accessTokenField = $accessTokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAccessTokenKey(): string
|
public static function getAccessTokenField(): string
|
||||||
{
|
{
|
||||||
return self::$accessTokenKey;
|
return self::$accessTokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function useRefreshTokenKey(string $refreshTokenKey): void
|
public static function useRefreshTokenField(string $refreshTokenField): void
|
||||||
{
|
{
|
||||||
self::$refreshTokenKey = $refreshTokenKey;
|
self::$refreshTokenField = $refreshTokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRefreshTokenKey(): string
|
public static function getRefreshTokenField(): string
|
||||||
{
|
{
|
||||||
return self::$refreshTokenKey;
|
return self::$refreshTokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,4 +62,9 @@ class UserProvider implements Base
|
|||||||
{
|
{
|
||||||
return $this->providerName;
|
return $this->providerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
|
||||||
|
{
|
||||||
|
// TODO: Implement rehashPasswordIfRequired() method.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Anikeen\Id;
|
namespace Anikeen\Id;
|
||||||
|
|
||||||
use Anikeen\Id\ApiOperations\Request;
|
use Anikeen\Id\ApiOperations\Request;
|
||||||
|
use Anikeen\Id\Concerns\ManagesAddresses;
|
||||||
use Anikeen\Id\Concerns\ManagesBalance;
|
use Anikeen\Id\Concerns\ManagesBalance;
|
||||||
use Anikeen\Id\Concerns\ManagesInvoices;
|
use Anikeen\Id\Concerns\ManagesInvoices;
|
||||||
use Anikeen\Id\Concerns\ManagesOrders;
|
use Anikeen\Id\Concerns\ManagesOrders;
|
||||||
@@ -17,6 +18,7 @@ use stdClass;
|
|||||||
|
|
||||||
trait Billable
|
trait Billable
|
||||||
{
|
{
|
||||||
|
use ManagesAddresses;
|
||||||
use ManagesBalance;
|
use ManagesBalance;
|
||||||
use ManagesInvoices;
|
use ManagesInvoices;
|
||||||
use ManagesOrders;
|
use ManagesOrders;
|
||||||
@@ -51,7 +53,7 @@ trait Billable
|
|||||||
protected function request(string $method, string $path, null|array $payload = null, array $parameters = [], Paginator $paginator = null): Result
|
protected function request(string $method, string $path, null|array $payload = null, array $parameters = [], Paginator $paginator = null): Result
|
||||||
{
|
{
|
||||||
$anikeenId = new AnikeenId();
|
$anikeenId = new AnikeenId();
|
||||||
$anikeenId->withToken($this->{AnikeenId::getAccessTokenKey()});
|
$anikeenId->withToken($this->{AnikeenId::getAccessTokenField()});
|
||||||
|
|
||||||
return $anikeenId->request($method, $path, $payload, $parameters, $paginator);
|
return $anikeenId->request($method, $path, $payload, $parameters, $paginator);
|
||||||
}
|
}
|
||||||
|
|||||||
132
src/Id/Concerns/ManagesAddresses.php
Normal file
132
src/Id/Concerns/ManagesAddresses.php
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Anikeen\Id\Concerns;
|
||||||
|
|
||||||
|
use Anikeen\Id\ApiOperations\Request;
|
||||||
|
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||||
|
use Anikeen\Id\Result;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
|
||||||
|
trait ManagesAddresses
|
||||||
|
{
|
||||||
|
use Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get addresses from the current user.
|
||||||
|
*
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function addresses(): Result
|
||||||
|
{
|
||||||
|
return $this->request('GET', 'v1/addresses');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new address for the current user.
|
||||||
|
*
|
||||||
|
* @param array{
|
||||||
|
* company_name: null|string,
|
||||||
|
* first_name: string,
|
||||||
|
* last_name: string,
|
||||||
|
* address: string,
|
||||||
|
* address_2: null|string,
|
||||||
|
* house_number: null|string,
|
||||||
|
* postal_code: string,
|
||||||
|
* city: string,
|
||||||
|
* state: null|string,
|
||||||
|
* country_iso: string,
|
||||||
|
* phone_number: null|string,
|
||||||
|
* email: null|string,
|
||||||
|
* primary: bool,
|
||||||
|
* primary_billing_address: bool
|
||||||
|
* } $attributes The address data:
|
||||||
|
* - company_name: Company name (optional)
|
||||||
|
* - first_name: First name
|
||||||
|
* - last_name: Last name
|
||||||
|
* - address: Address line 1 (e.g. street address, P.O. Box, etc.)
|
||||||
|
* - address_2: Address line 2 (optional, e.g. apartment number, c/o, etc.)
|
||||||
|
* - house_number: House number (optional)
|
||||||
|
* - postal_code: Postal code
|
||||||
|
* - city: City
|
||||||
|
* - state: State (optional, e.g. province, region, etc.)
|
||||||
|
* - country_iso: Country ISO code (e.g. US, CA, etc.)
|
||||||
|
* - phone_number: Phone number (optional)
|
||||||
|
* - email: Email address (optional, e.g. for delivery notifications)
|
||||||
|
* - primary: Whether this address should be the primary address (optional)
|
||||||
|
* - primary_billing_address: Whether this address should be the primary billing address (optional)
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function createAddress(array $attributes = []): Result
|
||||||
|
{
|
||||||
|
return $this->request('POST', 'v1/addresses', $attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get given address from the current user.
|
||||||
|
*
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function address(string $addressId): Result
|
||||||
|
{
|
||||||
|
return $this->request('GET', sprintf('v1/addresses/%s', $addressId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update given address from the current user.
|
||||||
|
*
|
||||||
|
* VAT is calculated based on the billing address and shown in the address response.
|
||||||
|
*
|
||||||
|
* @param string $addressId The address ID.
|
||||||
|
* @param array{
|
||||||
|
* company_name: null|string,
|
||||||
|
* first_name: string,
|
||||||
|
* last_name: string,
|
||||||
|
* address_2: null|string,
|
||||||
|
* address: string,
|
||||||
|
* house_number: null|string,
|
||||||
|
* postal_code: string,
|
||||||
|
* city: string,
|
||||||
|
* state: null|string,
|
||||||
|
* country_iso: string,
|
||||||
|
* phone_number: null|string,
|
||||||
|
* email: null|string,
|
||||||
|
* primary: bool,
|
||||||
|
* primary_billing_address: bool
|
||||||
|
* } $attributes The address data:
|
||||||
|
* - company_name: Company name (optional)
|
||||||
|
* - first_name: First name (required when set)
|
||||||
|
* - last_name: Last name (required when set)
|
||||||
|
* - address: Address line 1 (e.g. street address, P.O. Box, etc.)
|
||||||
|
* - address_2: Address line 2 (optional, e.g. apartment number, c/o, etc.)
|
||||||
|
* - house_number: House number (optional)
|
||||||
|
* - postal_code: Postal code (required when set)
|
||||||
|
* - city: City (required when set)
|
||||||
|
* - state: State (optional, e.g. province, region, etc.)
|
||||||
|
* - country_iso: Country ISO code (required when set, e.g. US, CA, etc.)
|
||||||
|
* - phone_number: Phone number (optional)
|
||||||
|
* - email: Email address (optional, e.g. for delivery notifications)
|
||||||
|
* - primary: Whether this address should be the primary address (optional)
|
||||||
|
* - primary_billing_address: Whether this address should be the primary billing address (optional)
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function updateAddress(string $addressId, array $attributes = []): Result
|
||||||
|
{
|
||||||
|
return $this->request('PUT', sprintf('v1/addresses/%s', $addressId), $attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete given address from the current user.
|
||||||
|
*
|
||||||
|
* @param string $addressId The address ID.
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function deleteAddress(string $addressId): Result
|
||||||
|
{
|
||||||
|
return $this->request('DELETE', sprintf('v1/addresses/%s', $addressId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,14 +35,14 @@ trait ManagesInvoices
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get download url from given invoice.
|
* Get temporary download url from given invoice.
|
||||||
*
|
*
|
||||||
* @param string $invoiceId The invoice ID
|
* @param string $invoiceId The invoice ID
|
||||||
* @throws RequestRequiresClientIdException
|
* @throws RequestRequiresClientIdException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function getInvoiceDownloadUrl(string $invoiceId): string
|
public function getInvoiceTemporaryUrl(string $invoiceId): string
|
||||||
{
|
{
|
||||||
return $this->request('PUT', sprintf('v1/invoices/%s', $invoiceId))->data->download_url;
|
return $this->request('PUT', sprintf('v1/invoices/%s', $invoiceId))->data->temporary_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,11 @@ trait ManagesOrders
|
|||||||
*
|
*
|
||||||
* VAT is calculated based on the billing address and shown in the order response.
|
* VAT is calculated based on the billing address and shown in the order response.
|
||||||
*
|
*
|
||||||
|
* The billing and shipping addresses are each persisted as standalone Address entities
|
||||||
|
* in the database, but are also embedded (deep-copied) into the Order object itself
|
||||||
|
* rather than merely referenced. This guarantees that the order retains its own snapshot
|
||||||
|
* of both addresses for future reference.
|
||||||
|
*
|
||||||
* @param array{
|
* @param array{
|
||||||
* billing_address: array{
|
* billing_address: array{
|
||||||
* company_name: null|string,
|
* company_name: null|string,
|
||||||
@@ -92,6 +97,11 @@ trait ManagesOrders
|
|||||||
*
|
*
|
||||||
* VAT is calculated based on the billing address and shown in the order response.
|
* VAT is calculated based on the billing address and shown in the order response.
|
||||||
*
|
*
|
||||||
|
* The billing and shipping addresses are each persisted as standalone Address entities
|
||||||
|
* in the database, but are also embedded (deep-copied) into the Order object itself
|
||||||
|
* rather than merely referenced. This guarantees that the order retains its own snapshot
|
||||||
|
* of both addresses for future reference.
|
||||||
|
*
|
||||||
* @param string $orderId The order ID.
|
* @param string $orderId The order ID.
|
||||||
* @param array{
|
* @param array{
|
||||||
* billing_address: array{
|
* billing_address: array{
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ trait ManagesPaymentMethods
|
|||||||
*/
|
*/
|
||||||
public function hasDefaultPaymentMethod(): bool
|
public function hasDefaultPaymentMethod(): bool
|
||||||
{
|
{
|
||||||
return $this->defaultPaymentMethod()->count() > 0;
|
return (bool)$this->defaultPaymentMethod()->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,7 @@ trait ManagesPaymentMethods
|
|||||||
*/
|
*/
|
||||||
public function billingPortalUrl(string $returnUrl, array $options): string
|
public function billingPortalUrl(string $returnUrl, array $options): string
|
||||||
{
|
{
|
||||||
return $this->request('POST', 'v1/stripe/billing-portal', [
|
return $this->request('POST', 'v1/billing/portal', [
|
||||||
'return_url' => $returnUrl,
|
'return_url' => $returnUrl,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
])->data->url;
|
])->data->url;
|
||||||
|
|||||||
@@ -100,4 +100,16 @@ trait ManagesSubscriptions
|
|||||||
{
|
{
|
||||||
return $this->request('PUT', sprintf('v1/subscriptions/%s/resume', $subscriptionId));
|
return $this->request('PUT', sprintf('v1/subscriptions/%s/resume', $subscriptionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a given subscription from the current user.
|
||||||
|
*
|
||||||
|
* @param string $subscriptionId The subscription ID.
|
||||||
|
* @throws RequestRequiresClientIdException
|
||||||
|
* @throws GuzzleException
|
||||||
|
*/
|
||||||
|
public function deleteSubscription(string $subscriptionId): Result
|
||||||
|
{
|
||||||
|
return $this->request('DELETE', sprintf('v1/subscriptions/%s', $subscriptionId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,28 +13,19 @@ use Illuminate\Support\Arr;
|
|||||||
|
|
||||||
class AnikeenIdSsoUserProvider implements UserProvider
|
class AnikeenIdSsoUserProvider implements UserProvider
|
||||||
{
|
{
|
||||||
private AnikeenId $anikeenId;
|
|
||||||
private ?string $accessTokenField = null;
|
private ?string $accessTokenField = null;
|
||||||
private array $fields;
|
|
||||||
private string $model;
|
|
||||||
private Request $request;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AnikeenId $anikeenId,
|
private AnikeenId $anikeenId,
|
||||||
Request $request,
|
private Request $request,
|
||||||
string $model,
|
private string $model,
|
||||||
array $fields,
|
private array $fields
|
||||||
?string $accessTokenField = null
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->accessTokenField = AnikeenId::getAccessTokenField();
|
||||||
$this->model = $model;
|
|
||||||
$this->fields = $fields;
|
|
||||||
$this->accessTokenField = $accessTokenField;
|
|
||||||
$this->anikeenId = $anikeenId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function retrieveById(mixed $identifier): Builder|Model|null
|
public function retrieveById(mixed $identifier): ?Authenticatable
|
||||||
{
|
{
|
||||||
$model = $this->createModel();
|
$model = $this->createModel();
|
||||||
$token = $this->request->bearerToken();
|
$token = $this->request->bearerToken();
|
||||||
@@ -114,4 +105,9 @@ class AnikeenIdSsoUserProvider implements UserProvider
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false)
|
||||||
|
{
|
||||||
|
// TODO: Implement rehashPasswordIfRequired() method.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ class AnikeenIdExtendSocialite
|
|||||||
{
|
{
|
||||||
public function handle(SocialiteWasCalled $socialiteWasCalled): void
|
public function handle(SocialiteWasCalled $socialiteWasCalled): void
|
||||||
{
|
{
|
||||||
$socialiteWasCalled->extendSocialite('anikeen-id', Provider::class);
|
$socialiteWasCalled->extendSocialite('anikeen', Provider::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace Anikeen\Id\Socialite;
|
|||||||
|
|
||||||
use Anikeen\Id\Enums\Scope;
|
use Anikeen\Id\Enums\Scope;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Laravel\Socialite\Two\ProviderInterface;
|
use Laravel\Socialite\Two\ProviderInterface;
|
||||||
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
|
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
|
||||||
@@ -26,13 +27,25 @@ class Provider extends AbstractProvider implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
protected $scopeSeparator = ' ';
|
protected $scopeSeparator = ' ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the base URL for the API.
|
||||||
|
*/
|
||||||
|
protected function getBaseUrl(): string
|
||||||
|
{
|
||||||
|
$mode = $this->config['mode'] ?? 'production';
|
||||||
|
|
||||||
|
return $mode === 'staging'
|
||||||
|
? 'https://staging.id.anikeen.com'
|
||||||
|
: 'https://id.anikeen.com';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getAuthUrl($state): string
|
protected function getAuthUrl($state): string
|
||||||
{
|
{
|
||||||
return $this->buildAuthUrlFromBase(
|
return $this->buildAuthUrlFromBase(
|
||||||
'https://id.anikeen.com/oauth/authorize', $state
|
$this->getBaseUrl() . '/oauth/authorize', $state
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +54,7 @@ class Provider extends AbstractProvider implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
protected function getTokenUrl(): string
|
protected function getTokenUrl(): string
|
||||||
{
|
{
|
||||||
return 'https://id.anikeen.com/oauth/token';
|
return $this->getBaseUrl() . '/oauth/token';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +65,7 @@ class Provider extends AbstractProvider implements ProviderInterface
|
|||||||
protected function getUserByToken($token)
|
protected function getUserByToken($token)
|
||||||
{
|
{
|
||||||
$response = $this->getHttpClient()->get(
|
$response = $this->getHttpClient()->get(
|
||||||
'https://id.anikeen.com/api/v1/user', [
|
$this->getBaseUrl() . '/api/v1/user', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
'Authorization' => 'Bearer ' . $token,
|
'Authorization' => 'Bearer ' . $token,
|
||||||
|
|||||||
Reference in New Issue
Block a user