diff --git a/AUTH.md b/AUTH.md index 8678997..0a1ed10 100644 --- a/AUTH.md +++ b/AUTH.md @@ -3,8 +3,8 @@ This method should typically be called in the `boot` method of your `AuthServiceProvider` class: ```php -use GhostZero\BitinflowAccounts\BitinflowAccounts; -use GhostZero\BitinflowAccounts\Providers\BitinflowAccountsSsoUserProvider; +use Bitinflow\Accounts\BitinflowAccounts; +use Bitinflow\Accounts\Providers\BitinflowAccountsSsoUserProvider; use Illuminate\Http\Request; /** diff --git a/README.md b/README.md index 0a3196c..9fdfc44 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ composer require ghostzero/bitinflow-accounts Add Service Provider to your `app.php` configuration file: ```php -GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, +Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider::class, ``` ## Event Listener @@ -85,7 +85,7 @@ You will need to add an entry to the services configuration file so that after c #### Basic ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); @@ -106,7 +106,7 @@ echo $sshKey->name; #### Setters ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientSecret('abc456'); @@ -120,7 +120,7 @@ $bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456'); #### OAuth Tokens ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setToken('abcdef123456'); @@ -143,7 +143,7 @@ $result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser(); #### Facade ```php -use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; +use Bitinflow\Accounts\Facades\BitinflowAccounts; BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); ``` diff --git a/README.stub b/README.stub index 656bb38..d767634 100644 --- a/README.stub +++ b/README.stub @@ -26,7 +26,7 @@ composer require ghostzero/bitinflow-accounts Add Service Provider to your `app.php` configuration file: ```php -GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, +Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider::class, ``` ## Event Listener @@ -56,7 +56,7 @@ protected $listen = [ Copy configuration to config folder: ``` -$ php artisan vendor:publish --provider="GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider" +$ php artisan vendor:publish --provider="Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider" ``` Add environmental variables to your `.env` @@ -84,7 +84,7 @@ You will need to add an entry to the services configuration file so that after c #### Basic ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); @@ -105,7 +105,7 @@ echo $sshKey->name; #### Setters ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientSecret('abc456'); @@ -119,7 +119,7 @@ $bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456'); #### OAuth Tokens ```php -$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); +$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setToken('abcdef123456'); @@ -142,7 +142,7 @@ $result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser(); #### Facade ```php -use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; +use Bitinflow\Accounts\Facades\BitinflowAccounts; BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); ``` diff --git a/composer.json b/composer.json index 2be81f4..ee41380 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,11 @@ "authors": [ { "name": "René Preuß", - "email": "rene@preuss.io" + "email": "rene@bitinflow.com" + }, + { + "name": "Maurice Preuß", + "email": "maurice@bitinflow.com" } ], "require": { @@ -24,12 +28,12 @@ }, "autoload": { "psr-4": { - "GhostZero\\BitinflowAccounts\\": "src/GhostZero/BitinflowAccounts" + "Bitinflow\\Accounts\\": "src/Accounts" } }, "autoload-dev": { "psr-4": { - "GhostZero\\BitinflowAccounts\\Tests\\": "tests/GhostZero/BitinflowAccounts" + "Bitinflow\\Accounts\\Tests\\": "tests/Accounts" } }, "scripts": { @@ -39,10 +43,10 @@ "extra": { "laravel": { "providers": [ - "GhostZero\\BitinflowAccounts\\Providers\\BitinflowAccountsServiceProvider" + "Bitinflow\\Accounts\\Providers\\BitinflowAccountsServiceProvider" ], "aliases": { - "BitinflowAccounts": "GhostZero\\BitinflowAccounts\\Facades\\BitinflowAccounts" + "BitinflowAccounts": "Bitinflow\\Accounts\\Facades\\BitinflowAccounts" } } } diff --git a/config/bitinflow-accounts.php b/config/bitinflow-accounts.php index 6fa552b..ab17c8e 100644 --- a/config/bitinflow-accounts.php +++ b/config/bitinflow-accounts.php @@ -1,10 +1,13 @@ env('BITINFLOW_ACCOUNTS_KEY'), 'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'), 'redirect_url' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI'), 'base_url' => env('BITINFLOW_ACCOUNTS_BASE_URL'), + + // Payments 'payments' => [ 'base_url' => env('BITINFLOW_PAYMENTS_BASE_URL', 'https://api.pay.bitinflow.com/v1/'), 'dashboard_url' => env('BITINFLOW_PAYMENTS_DASHBOARD_URL', 'https://pay.bitinflow.com/v1/'), diff --git a/generator/generate-docs.php b/generator/generate-docs.php index cc40a13..a048a43 100644 --- a/generator/generate-docs.php +++ b/generator/generate-docs.php @@ -2,7 +2,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use GhostZero\BitinflowAccounts\BitinflowAccounts; +use Bitinflow\Accounts\BitinflowAccounts; use Illuminate\Support\Arr; $markdown = collect(class_uses(BitinflowAccounts::class)) diff --git a/src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php b/src/Accounts/ApiOperations/Delete.php similarity index 60% rename from src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php rename to src/Accounts/ApiOperations/Delete.php index d9926a4..edf642b 100644 --- a/src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php +++ b/src/Accounts/ApiOperations/Delete.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\ApiOperations; +namespace Bitinflow\Accounts\ApiOperations; -use GhostZero\BitinflowAccounts\Helpers\Paginator; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\Helpers\Paginator; +use Bitinflow\Accounts\Result; /** * @author René Preuß diff --git a/src/GhostZero/BitinflowAccounts/ApiOperations/Get.php b/src/Accounts/ApiOperations/Get.php similarity index 59% rename from src/GhostZero/BitinflowAccounts/ApiOperations/Get.php rename to src/Accounts/ApiOperations/Get.php index ef2f1a3..1bb3b93 100644 --- a/src/GhostZero/BitinflowAccounts/ApiOperations/Get.php +++ b/src/Accounts/ApiOperations/Get.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\ApiOperations; +namespace Bitinflow\Accounts\ApiOperations; -use GhostZero\BitinflowAccounts\Helpers\Paginator; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\Helpers\Paginator; +use Bitinflow\Accounts\Result; /** * @author René Preuß diff --git a/src/GhostZero/BitinflowAccounts/ApiOperations/Post.php b/src/Accounts/ApiOperations/Post.php similarity index 59% rename from src/GhostZero/BitinflowAccounts/ApiOperations/Post.php rename to src/Accounts/ApiOperations/Post.php index de10830..c4b6db9 100644 --- a/src/GhostZero/BitinflowAccounts/ApiOperations/Post.php +++ b/src/Accounts/ApiOperations/Post.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\ApiOperations; +namespace Bitinflow\Accounts\ApiOperations; -use GhostZero\BitinflowAccounts\Helpers\Paginator; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\Helpers\Paginator; +use Bitinflow\Accounts\Result; /** * @author René Preuß diff --git a/src/GhostZero/BitinflowAccounts/ApiOperations/Put.php b/src/Accounts/ApiOperations/Put.php similarity index 59% rename from src/GhostZero/BitinflowAccounts/ApiOperations/Put.php rename to src/Accounts/ApiOperations/Put.php index cb0f525..a8be930 100644 --- a/src/GhostZero/BitinflowAccounts/ApiOperations/Put.php +++ b/src/Accounts/ApiOperations/Put.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\ApiOperations; +namespace Bitinflow\Accounts\ApiOperations; -use GhostZero\BitinflowAccounts\Helpers\Paginator; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\Helpers\Paginator; +use Bitinflow\Accounts\Result; /** * @author René Preuß diff --git a/src/GhostZero/BitinflowAccounts/ApiTokenCookieFactory.php b/src/Accounts/ApiTokenCookieFactory.php similarity index 98% rename from src/GhostZero/BitinflowAccounts/ApiTokenCookieFactory.php rename to src/Accounts/ApiTokenCookieFactory.php index daeaf77..b8ad45e 100644 --- a/src/GhostZero/BitinflowAccounts/ApiTokenCookieFactory.php +++ b/src/Accounts/ApiTokenCookieFactory.php @@ -1,6 +1,6 @@ @@ -29,61 +30,63 @@ class BitinflowAccounts use ApiOperations\Post; use ApiOperations\Put; - private static $baseUrl = 'https://accounts.bitinflow.com/api/'; - /** * The name for API token cookies. * * @var string */ public static $cookie = 'bitinflow_token'; - /** * Indicates if Bitinflow Accounts should ignore incoming CSRF tokens. * * @var bool */ public static $ignoreCsrfToken = false; - /** * Indicates if Bitinflow Accounts should unserializes cookies. * * @var bool */ public static $unserializesCookies = false; - + private static $baseUrl = 'https://accounts.bitinflow.com/api/'; /** * Guzzle is used to make http requests. - * @var \GuzzleHttp\Client + * + * @var Client */ protected $client; /** * Paginator object. + * * @var Paginator */ protected $paginator; /** * bitinflow Accounts OAuth token. + * * @var string|null */ protected $token = null; /** * bitinflow Accounts client id. + * * @var string|null */ protected $clientId = null; /** * bitinflow Accounts client secret. + * * @var string|null */ protected $clientSecret = null; /** * bitinflow Accounts OAuth redirect url. + * * @var string|null */ protected $redirectUri = null; @@ -110,10 +113,20 @@ class BitinflowAccounts ]); } + /** + * @param string $baseUrl + * + * @internal only for internal and debug purposes. + */ + public static function setBaseUrl(string $baseUrl): void + { + self::$baseUrl = $baseUrl; + } + /** * Get or set the name for API token cookies. * - * @param string|null $cookie + * @param string|null $cookie * @return string|static */ public static function cookie($cookie = null) @@ -130,15 +143,14 @@ class BitinflowAccounts /** * Set the current user for the application with the given scopes. * - * @param \Illuminate\Contracts\Auth\Authenticatable|Traits\HasBitinflowTokens $user - * @param array $scopes - * @param string $guard - * @return \Illuminate\Contracts\Auth\Authenticatable + * @param Authenticatable|Traits\HasBitinflowTokens $user + * @param array $scopes + * @param string $guard + * @return Authenticatable */ public static function actingAs($user, $scopes = [], $guard = 'api') { - - $user->withBitinflowAccessToken((object) [ + $user->withBitinflowAccessToken((object)[ 'scopes' => $scopes ]); @@ -153,42 +165,6 @@ class BitinflowAccounts return $user; } - /** - * @param string $baseUrl - * - * @internal only for internal and debug purposes. - */ - public static function setBaseUrl(string $baseUrl): void - { - self::$baseUrl = $baseUrl; - } - - /** - * Get client id. - * @return string - * @throws RequestRequiresClientIdException - */ - public function getClientId(): string - { - if (!$this->clientId) { - throw new RequestRequiresClientIdException; - } - - return $this->clientId; - } - - /** - * Set client id. - * - * @param string $clientId bitinflow Accounts client id - * - * @return void - */ - public function setClientId(string $clientId): void - { - $this->clientId = $clientId; - } - /** * Fluid client id setter. * @@ -205,6 +181,7 @@ class BitinflowAccounts /** * Get client secret. + * * @return string * @throws RequestRequiresClientIdException */ @@ -245,6 +222,7 @@ class BitinflowAccounts /** * Get redirect url. + * * @return string * @throws RequestRequiresRedirectUriException */ @@ -285,6 +263,7 @@ class BitinflowAccounts /** * Get OAuth token. + * * @return string bitinflow Accounts token * @return string|null * @throws RequestRequiresAuthenticationException @@ -325,8 +304,8 @@ class BitinflowAccounts } /** - * @param string $path - * @param array $parameters + * @param string $path + * @param array $parameters * @param Paginator|null $paginator * * @return Result @@ -338,73 +317,13 @@ class BitinflowAccounts return $this->query('GET', $path, $parameters, $paginator); } - /** - * @param string $path - * @param array $parameters - * @param Paginator|null $paginator - * - * @return Result - * @throws GuzzleException - * @throws RequestRequiresClientIdException - */ - public function post(string $path = '', array $parameters = [], Paginator $paginator = null): Result - { - return $this->query('POST', $path, $parameters, $paginator); - } - - /** - * @param string $path - * @param array $parameters - * @param Paginator|null $paginator - * - * @return Result - * @throws GuzzleException - * @throws RequestRequiresClientIdException - */ - public function delete(string $path = '', array $parameters = [], Paginator $paginator = null): Result - { - return $this->query('DELETE', $path, $parameters, $paginator); - } - - /** - * @param string $path - * @param array $parameters - * @param Paginator|null $paginator - * - * @return Result - * @throws GuzzleException - * @throws RequestRequiresClientIdException - */ - public function put(string $path = '', array $parameters = [], Paginator $paginator = null): Result - { - return $this->query('PUT', $path, $parameters, $paginator); - } - - /** - * @param string $method - * @param string $path - * @param array|null $body - * - * @return Result - * @throws GuzzleException - * @throws RequestRequiresClientIdException - */ - public function json(string $method, string $path = '', array $body = null): Result - { - if ($body) { - $body = json_encode(['data' => $body]); - } - - return $this->query($method, $path, [], null, $body); - } - /** * Build query & execute. * - * @param string $method HTTP method - * @param string $path Query path - * @param array $parameters Query parameters - * @param Paginator $paginator Paginator object + * @param string $method HTTP method + * @param string $path Query path + * @param array $parameters Query parameters + * @param Paginator $paginator Paginator object * @param mixed|null $jsonBody JSON data * * @return Result Result object @@ -431,26 +350,6 @@ class BitinflowAccounts return $result; } - /** - * Build query with support for multiple smae first-dimension keys. - * - * @param array $query - * - * @return string - */ - public function buildQuery(array $query): string - { - $parts = []; - foreach ($query as $name => $value) { - $value = (array) $value; - array_walk_recursive($value, function ($value) use (&$parts, $name) { - $parts[] = urlencode($name) . '=' . urlencode($value); - }); - } - - return implode('&', $parts); - } - /** * Build headers for request. * @@ -474,4 +373,111 @@ class BitinflowAccounts return $headers; } + + /** + * Get client id. + * + * @return string + * @throws RequestRequiresClientIdException + */ + public function getClientId(): string + { + if (!$this->clientId) { + throw new RequestRequiresClientIdException; + } + + return $this->clientId; + } + + /** + * Set client id. + * + * @param string $clientId bitinflow Accounts client id + * + * @return void + */ + public function setClientId(string $clientId): void + { + $this->clientId = $clientId; + } + + /** + * Build query with support for multiple smae first-dimension keys. + * + * @param array $query + * + * @return string + */ + public function buildQuery(array $query): string + { + $parts = []; + foreach ($query as $name => $value) { + $value = (array)$value; + array_walk_recursive($value, function ($value) use (&$parts, $name) { + $parts[] = urlencode($name) . '=' . urlencode($value); + }); + } + + return implode('&', $parts); + } + + /** + * @param string $path + * @param array $parameters + * @param Paginator|null $paginator + * + * @return Result + * @throws GuzzleException + * @throws RequestRequiresClientIdException + */ + public function post(string $path = '', array $parameters = [], Paginator $paginator = null): Result + { + return $this->query('POST', $path, $parameters, $paginator); + } + + /** + * @param string $path + * @param array $parameters + * @param Paginator|null $paginator + * + * @return Result + * @throws GuzzleException + * @throws RequestRequiresClientIdException + */ + public function delete(string $path = '', array $parameters = [], Paginator $paginator = null): Result + { + return $this->query('DELETE', $path, $parameters, $paginator); + } + + /** + * @param string $path + * @param array $parameters + * @param Paginator|null $paginator + * + * @return Result + * @throws GuzzleException + * @throws RequestRequiresClientIdException + */ + public function put(string $path = '', array $parameters = [], Paginator $paginator = null): Result + { + return $this->query('PUT', $path, $parameters, $paginator); + } + + /** + * @param string $method + * @param string $path + * @param array|null $body + * + * @return Result + * @throws GuzzleException + * @throws RequestRequiresClientIdException + */ + public function json(string $method, string $path = '', array $body = null): Result + { + if ($body) { + $body = json_encode(['data' => $body]); + } + + return $this->query($method, $path, [], null, $body); + } } \ No newline at end of file diff --git a/src/GhostZero/BitinflowAccounts/Enums/Scope.php b/src/Accounts/Enums/Scope.php similarity index 94% rename from src/GhostZero/BitinflowAccounts/Enums/Scope.php rename to src/Accounts/Enums/Scope.php index 1605ff0..ac47ae1 100644 --- a/src/GhostZero/BitinflowAccounts/Enums/Scope.php +++ b/src/Accounts/Enums/Scope.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Enums; +namespace Bitinflow\Accounts\Enums; /** * @author René Preuß diff --git a/src/GhostZero/BitinflowAccounts/Exceptions/MissingScopeException.php b/src/Accounts/Exceptions/MissingScopeException.php similarity index 93% rename from src/GhostZero/BitinflowAccounts/Exceptions/MissingScopeException.php rename to src/Accounts/Exceptions/MissingScopeException.php index fe0c33e..df9234e 100644 --- a/src/GhostZero/BitinflowAccounts/Exceptions/MissingScopeException.php +++ b/src/Accounts/Exceptions/MissingScopeException.php @@ -1,6 +1,6 @@ user() || ! $request->user()->bitinflowToken()) { + if (!$request->user() || !$request->user()->bitinflowToken()) { throw new AuthenticationException; } diff --git a/src/GhostZero/BitinflowAccounts/Http/Middleware/CheckScopes.php b/src/Accounts/Http/Middleware/CheckScopes.php similarity index 61% rename from src/GhostZero/BitinflowAccounts/Http/Middleware/CheckScopes.php rename to src/Accounts/Http/Middleware/CheckScopes.php index 96e446d..6ad159d 100644 --- a/src/GhostZero/BitinflowAccounts/Http/Middleware/CheckScopes.php +++ b/src/Accounts/Http/Middleware/CheckScopes.php @@ -1,9 +1,9 @@ user() || ! $request->user()->bitinflowToken()) { + if (!$request->user() || !$request->user()->bitinflowToken()) { throw new AuthenticationException; } foreach ($scopes as $scope) { - if (! $request->user()->bitinflowTokenCan($scope)) { + if (!$request->user()->bitinflowTokenCan($scope)) { throw new MissingScopeException($scope); } } diff --git a/src/GhostZero/BitinflowAccounts/Http/Middleware/CreateFreshApiToken.php b/src/Accounts/Http/Middleware/CreateFreshApiToken.php similarity index 86% rename from src/GhostZero/BitinflowAccounts/Http/Middleware/CreateFreshApiToken.php rename to src/Accounts/Http/Middleware/CreateFreshApiToken.php index bf4c6ab..1c08842 100644 --- a/src/GhostZero/BitinflowAccounts/Http/Middleware/CreateFreshApiToken.php +++ b/src/Accounts/Http/Middleware/CreateFreshApiToken.php @@ -1,10 +1,10 @@ alreadyContainsToken($response); + !$this->alreadyContainsToken($response); } /** diff --git a/src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsServiceProvider.php b/src/Accounts/Providers/BitinflowAccountsServiceProvider.php similarity index 87% rename from src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsServiceProvider.php rename to src/Accounts/Providers/BitinflowAccountsServiceProvider.php index 0560530..f14f12e 100644 --- a/src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsServiceProvider.php +++ b/src/Accounts/Providers/BitinflowAccountsServiceProvider.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Providers; +namespace Bitinflow\Accounts\Providers; -use GhostZero\BitinflowAccounts\Auth\TokenGuard; -use GhostZero\BitinflowAccounts\Auth\UserProvider; -use GhostZero\BitinflowAccounts\BitinflowAccounts; -use GhostZero\BitinflowAccounts\Helpers\JwtParser; +use Bitinflow\Accounts\Auth\TokenGuard; +use Bitinflow\Accounts\Auth\UserProvider; +use Bitinflow\Accounts\BitinflowAccounts; +use Bitinflow\Accounts\Helpers\JwtParser; use Illuminate\Auth\RequestGuard; use Illuminate\Support\Facades\Auth; use Illuminate\Support\ServiceProvider; @@ -17,6 +17,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider /** * Bootstrap the application services. + * * @return void */ public function boot() @@ -28,6 +29,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider /** * Register the application services. + * * @return void */ public function register() @@ -40,15 +42,6 @@ class BitinflowAccountsServiceProvider extends ServiceProvider $this->registerGuard(); } - /** - * Get the services provided by the provider. - * @return array - */ - public function provides() - { - return [BitinflowAccounts::class]; - } - /** * Register the token guard. * @@ -68,7 +61,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider /** * Make an instance of the token guard. * - * @param array $config + * @param array $config * @return RequestGuard */ protected function makeGuard(array $config): RequestGuard @@ -81,4 +74,14 @@ class BitinflowAccountsServiceProvider extends ServiceProvider ))->user($request); }, $this->app['request']); } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [BitinflowAccounts::class]; + } } diff --git a/src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsSsoUserProvider.php b/src/Accounts/Providers/BitinflowAccountsSsoUserProvider.php similarity index 92% rename from src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsSsoUserProvider.php rename to src/Accounts/Providers/BitinflowAccountsSsoUserProvider.php index 569db66..2566785 100644 --- a/src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsSsoUserProvider.php +++ b/src/Accounts/Providers/BitinflowAccountsSsoUserProvider.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Providers; +namespace Bitinflow\Accounts\Providers; -use GhostZero\BitinflowAccounts\BitinflowAccounts; +use Bitinflow\Accounts\BitinflowAccounts; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Database\Eloquent\Builder; @@ -35,7 +35,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider } /** - * @param mixed $identifier + * @param mixed $identifier * @return Builder|Model|object|null */ public function retrieveById($identifier) @@ -85,7 +85,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider */ public function createModel(): Model { - $class = '\\'.ltrim($this->model, '\\'); + $class = '\\' . ltrim($this->model, '\\'); return new $class; } @@ -93,7 +93,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider /** * Get a new query builder for the model instance. * - * @param Model|null $model + * @param Model|null $model * @return Builder */ protected function newModelQuery(Model $model = null): Builder diff --git a/src/GhostZero/BitinflowAccounts/Result.php b/src/Accounts/Result.php similarity index 84% rename from src/GhostZero/BitinflowAccounts/Result.php rename to src/Accounts/Result.php index 42c4679..d1951e2 100644 --- a/src/GhostZero/BitinflowAccounts/Result.php +++ b/src/Accounts/Result.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts; +namespace Bitinflow\Accounts; +use Bitinflow\Accounts\Helpers\Paginator; use Exception; -use GhostZero\BitinflowAccounts\Helpers\Paginator; use Psr\Http\Message\ResponseInterface; use stdClass; @@ -18,54 +18,63 @@ class Result /** * Query successfull. + * * @var boolean */ public $success = false; /** * Guzzle exception, if present. + * * @var null|mixed */ public $exception = null; /** * Query result data. + * * @var array */ public $data = []; /** * Total amount of result data. + * * @var integer */ public $total = 0; /** * Status Code. + * * @var integer */ public $status = 0; /** * bitinflow Accounts response pagination cursor. - * @var null|\stdClass + * + * @var null|stdClass */ public $pagination; /** * Internal paginator. + * * @var null|Paginator */ public $paginator; /** * Original Guzzle HTTP Response. + * * @var ResponseInterface|null */ public $response; /** * Original bitinflow Accounts instance. + * * @var BitinflowAccounts */ public $bitinflow; @@ -73,9 +82,9 @@ class Result /** * Constructor, * - * @param ResponseInterface|null $response HTTP response - * @param Exception|mixed $exception Exception, if present - * @param null|Paginator $paginator Paginator, if present + * @param ResponseInterface|null $response HTTP response + * @param Exception|mixed $exception Exception, if present + * @param null|Paginator $paginator Paginator, if present */ public function __construct(?ResponseInterface $response, Exception $exception = null, Paginator $paginator = null) { @@ -95,9 +104,9 @@ class Result /** * Sets a class attribute by given JSON Response Body. * - * @param stdClass $jsonResponse Response Body - * @param string $responseProperty Response property name - * @param string|null $attribute Class property name + * @param stdClass $jsonResponse Response Body + * @param string $responseProperty Response property name + * @param string|null $attribute Class property name */ private function setProperty(stdClass $jsonResponse, string $responseProperty, string $attribute = null): void { @@ -111,6 +120,7 @@ class Result /** * Returns wether the query was successfull. + * * @return bool Success state */ public function success(): bool @@ -120,6 +130,7 @@ class Result /** * Get the response data, also available as public attribute. + * * @return mixed */ public function data() @@ -129,6 +140,7 @@ class Result /** * Returns the last HTTP or API error. + * * @return string Error message */ public function error(): string @@ -137,7 +149,7 @@ class Result if ($this->exception === null || !$this->exception->hasResponse()) { return 'bitinflow Accounts API Unavailable'; } - $exception = (string) $this->exception->getResponse()->getBody(); + $exception = (string)$this->exception->getResponse()->getBody(); $exception = @json_decode($exception); if (property_exists($exception, 'message') && !empty($exception->message)) { return $exception->message; @@ -148,6 +160,7 @@ class Result /** * Shifts the current result (Use for single user/video etc. query). + * * @return mixed Shifted data */ public function shift() @@ -163,24 +176,17 @@ class Result /** * Return the current count of items in dataset. + * * @return int Count */ public function count(): int { - return count((array) $this->data); - } - - /** - * Set the Paginator to fetch the first set of results. - * @return null|Paginator - */ - public function first(): ?Paginator - { - return $this->paginator !== null ? $this->paginator->first() : null; + return count((array)$this->data); } /** * Set the Paginator to fetch the next set of results. + * * @return null|Paginator */ public function next(): ?Paginator @@ -190,6 +196,7 @@ class Result /** * Set the Paginator to fetch the last set of results. + * * @return null|Paginator */ public function back(): ?Paginator @@ -210,9 +217,9 @@ class Result return null; } $rateLimit = [ - 'limit' => (int) $this->response->getHeaderLine('X-RateLimit-Limit'), - 'remaining' => (int) $this->response->getHeaderLine('X-RateLimit-Remaining'), - 'reset' => (int) $this->response->getHeaderLine('Retry-After'), + 'limit' => (int)$this->response->getHeaderLine('X-RateLimit-Limit'), + 'remaining' => (int)$this->response->getHeaderLine('X-RateLimit-Remaining'), + 'reset' => (int)$this->response->getHeaderLine('Retry-After'), ]; if ($key === null) { return $rateLimit; @@ -225,7 +232,7 @@ class Result * Insert users in data response. * * @param string $identifierAttribute Attribute to identify the users - * @param string $insertTo Data index to insert user data + * @param string $insertTo Data index to insert user data * * @return self */ @@ -248,4 +255,14 @@ class Result return $this; } + + /** + * Set the Paginator to fetch the first set of results. + * + * @return null|Paginator + */ + public function first(): ?Paginator + { + return $this->paginator !== null ? $this->paginator->first() : null; + } } \ No newline at end of file diff --git a/src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php b/src/Accounts/Socialite/BitinflowExtendSocialite.php similarity index 90% rename from src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php rename to src/Accounts/Socialite/BitinflowExtendSocialite.php index f050e89..a8d0a78 100644 --- a/src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php +++ b/src/Accounts/Socialite/BitinflowExtendSocialite.php @@ -1,6 +1,6 @@ getPaymentsUser()->data->has_wallet; + } + + /** + * Get user from payments gateway. + * + * @return object|null + * @throws GuzzleException + */ + public function getPaymentsUser(): ?object + { + if (is_null($this->paymentsUser)) { + $this->paymentsUser = $this->paymentsGatewayRequest('GET', 'user'); + } + + return $this->paymentsUser; + } /** * Create a new payment gateway request. @@ -44,32 +68,6 @@ trait HasBitinflowPaymentsWallet return json_decode($response->getBody()); } - /** - * Get user from payments gateway. - * - * @return object|null - * @throws GuzzleException - */ - public function getPaymentsUser(): ?object - { - if (is_null($this->paymentsUser)) { - $this->paymentsUser = $this->paymentsGatewayRequest('GET', 'user'); - } - - return $this->paymentsUser; - } - - /** - * Check if user has an active wallet. - * - * @return bool - * @throws GuzzleException - */ - public function hasWallet(): bool - { - return $this->getPaymentsUser()->data->has_wallet; - } - public function getWalletSetupIntent(string $success_path = ''): string { return sprintf('%swallet?continue_url=%s', config('bitinflow-accounts.payments.dashboard_url'), url($success_path)); @@ -97,6 +95,24 @@ trait HasBitinflowPaymentsWallet return $this->getPaymentsUser()->data->taxation->vat; } + public function hasSubscribed($name = 'default'): bool + { + $subscription = $this->getSubscription($name); + + return $subscription && $subscription->status === 'settled' || $subscription && $subscription->resumeable; + } + + public function getSubscription($name = 'default'): ?object + { + foreach ($this->getSubscriptions() as $subscription) { + if (isset($subscription->payload->name) && $subscription->payload->name === $name) { + return $subscription; + } + } + + return null; + } + /** * Get vat from user. * @@ -116,33 +132,15 @@ trait HasBitinflowPaymentsWallet return $subscriptions; } - public function getSubscription($name = 'default'): ?object - { - foreach ($this->getSubscriptions() as $subscription) { - if (isset($subscription->payload->name) && $subscription->payload->name === $name) { - return $subscription; - } - } - - return null; - } - - public function hasSubscribed($name = 'default'): bool - { - $subscription = $this->getSubscription($name); - - return $subscription && $subscription->status === 'settled' || $subscription && $subscription->resumeable; - } - /** * Create a new subscription. * - * @param array $attributes array which requires following attributes: + * @param array $attributes array which requires following attributes: * name, description, period, price * and following attributes are optional: * vat, payload, ends_at, webhook_url, webhook_secret - * @param array $payload optional data that is stored in the subscription - * @param bool $checkout optional checkout it directly + * @param array $payload optional data that is stored in the subscription + * @param bool $checkout optional checkout it directly * @return object the subscription object * @throws GuzzleException */ @@ -153,7 +151,10 @@ trait HasBitinflowPaymentsWallet 'client_id' => config('bitinflow-accounts.client_id') ]; $defaults = ['period' => 'monthly']; - $attributes = array_merge(array_merge($defaults, $attributes), ['payload' => array_merge($payload, $client), 'checkout' => $checkout]); + $attributes = array_merge(array_merge($defaults, $attributes), [ + 'payload' => array_merge($payload, $client), + 'checkout' => $checkout + ]); return $this->paymentsGatewayRequest('POST', 'subscriptions', $attributes)->data; } diff --git a/src/GhostZero/BitinflowAccounts/Traits/HasBitinflowTokens.php b/src/Accounts/Traits/HasBitinflowTokens.php similarity index 95% rename from src/GhostZero/BitinflowAccounts/Traits/HasBitinflowTokens.php rename to src/Accounts/Traits/HasBitinflowTokens.php index 327248d..ec3d49c 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/HasBitinflowTokens.php +++ b/src/Accounts/Traits/HasBitinflowTokens.php @@ -1,6 +1,6 @@ client->request('POST', '/oauth/token', [ - 'form_params' => $attributes + [ + 'form_params' => $attributes + [ 'grant_type' => $grantType, 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), ], - ]); + ]); $result = new Result($response, null); } catch (RequestException $exception) { diff --git a/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php b/src/Accounts/Traits/SshKeysTrait.php similarity index 77% rename from src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php rename to src/Accounts/Traits/SshKeysTrait.php index 5d6dd0a..aa0fffa 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php +++ b/src/Accounts/Traits/SshKeysTrait.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Traits; +namespace Bitinflow\Accounts\Traits; -use GhostZero\BitinflowAccounts\ApiOperations\Delete; -use GhostZero\BitinflowAccounts\ApiOperations\Get; -use GhostZero\BitinflowAccounts\ApiOperations\Post; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\ApiOperations\Delete; +use Bitinflow\Accounts\ApiOperations\Get; +use Bitinflow\Accounts\ApiOperations\Post; +use Bitinflow\Accounts\Result; trait SshKeysTrait { @@ -29,7 +29,7 @@ trait SshKeysTrait /** * Creates ssh key for the currently authed user * - * @param string $publicKey + * @param string $publicKey * @param string|null $name * * @return Result Result object diff --git a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php b/src/Accounts/Traits/UsersTrait.php similarity index 85% rename from src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php rename to src/Accounts/Traits/UsersTrait.php index 84e4148..88a893d 100644 --- a/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php +++ b/src/Accounts/Traits/UsersTrait.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Traits; +namespace Bitinflow\Accounts\Traits; -use GhostZero\BitinflowAccounts\ApiOperations\Get; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\ApiOperations\Get; +use Bitinflow\Accounts\Result; trait UsersTrait { @@ -14,6 +14,7 @@ trait UsersTrait /** * Get currently authed user with Bearer Token + * * @return Result Result object */ public function getAuthedUser(): Result diff --git a/tests/GhostZero/BitinflowAccounts/ApiOauthTest.php b/tests/Accounts/ApiOauthTest.php similarity index 80% rename from tests/GhostZero/BitinflowAccounts/ApiOauthTest.php rename to tests/Accounts/ApiOauthTest.php index 21088d9..f1c28b8 100644 --- a/tests/GhostZero/BitinflowAccounts/ApiOauthTest.php +++ b/tests/Accounts/ApiOauthTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests; +namespace Bitinflow\Accounts\Tests; -use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; +use Bitinflow\Accounts\Tests\TestCases\ApiTestCase; /** * @author René Preuß diff --git a/tests/GhostZero/BitinflowAccounts/ApiSshKeysTest.php b/tests/Accounts/ApiSshKeysTest.php similarity index 91% rename from tests/GhostZero/BitinflowAccounts/ApiSshKeysTest.php rename to tests/Accounts/ApiSshKeysTest.php index 9383e5b..f82e04f 100644 --- a/tests/GhostZero/BitinflowAccounts/ApiSshKeysTest.php +++ b/tests/Accounts/ApiSshKeysTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests; +namespace Bitinflow\Accounts\Tests; -use GhostZero\BitinflowAccounts\Result; -use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; +use Bitinflow\Accounts\Result; +use Bitinflow\Accounts\Tests\TestCases\ApiTestCase; /** * @author René Preuß diff --git a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php b/tests/Accounts/ApiUsersTest.php similarity index 92% rename from tests/GhostZero/BitinflowAccounts/ApiUsersTest.php rename to tests/Accounts/ApiUsersTest.php index db19fbd..a1cf78a 100644 --- a/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php +++ b/tests/Accounts/ApiUsersTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests; +namespace Bitinflow\Accounts\Tests; -use GhostZero\BitinflowAccounts\Enums\Scope; -use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; +use Bitinflow\Accounts\Enums\Scope; +use Bitinflow\Accounts\Tests\TestCases\ApiTestCase; use Illuminate\Support\Str; /** diff --git a/tests/GhostZero/BitinflowAccounts/ServiceInstantiationTest.php b/tests/Accounts/ServiceInstantiationTest.php similarity index 64% rename from tests/GhostZero/BitinflowAccounts/ServiceInstantiationTest.php rename to tests/Accounts/ServiceInstantiationTest.php index c9165d3..fde149b 100644 --- a/tests/GhostZero/BitinflowAccounts/ServiceInstantiationTest.php +++ b/tests/Accounts/ServiceInstantiationTest.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests; +namespace Bitinflow\Accounts\Tests; -use GhostZero\BitinflowAccounts\BitinflowAccounts; -use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts as BitinflowAccountsFacade; -use GhostZero\BitinflowAccounts\Tests\TestCases\TestCase; +use Bitinflow\Accounts\BitinflowAccounts; +use Bitinflow\Accounts\Facades\BitinflowAccounts as BitinflowAccountsFacade; +use Bitinflow\Accounts\Tests\TestCases\TestCase; /** * @author René Preuß diff --git a/tests/GhostZero/BitinflowAccounts/TestCases/ApiTestCase.php b/tests/Accounts/TestCases/ApiTestCase.php similarity index 90% rename from tests/GhostZero/BitinflowAccounts/TestCases/ApiTestCase.php rename to tests/Accounts/TestCases/ApiTestCase.php index 332330f..67fa516 100644 --- a/tests/GhostZero/BitinflowAccounts/TestCases/ApiTestCase.php +++ b/tests/Accounts/TestCases/ApiTestCase.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests\TestCases; +namespace Bitinflow\Accounts\Tests\TestCases; -use GhostZero\BitinflowAccounts\BitinflowAccounts; -use GhostZero\BitinflowAccounts\Result; +use Bitinflow\Accounts\BitinflowAccounts; +use Bitinflow\Accounts\Result; /** * @author René Preuß diff --git a/tests/GhostZero/BitinflowAccounts/TestCases/TestCase.php b/tests/Accounts/TestCases/TestCase.php similarity index 72% rename from tests/GhostZero/BitinflowAccounts/TestCases/TestCase.php rename to tests/Accounts/TestCases/TestCase.php index f9c811d..f519189 100644 --- a/tests/GhostZero/BitinflowAccounts/TestCases/TestCase.php +++ b/tests/Accounts/TestCases/TestCase.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace GhostZero\BitinflowAccounts\Tests\TestCases; +namespace Bitinflow\Accounts\Tests\TestCases; -use GhostZero\BitinflowAccounts\BitinflowAccounts; -use GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider; +use Bitinflow\Accounts\BitinflowAccounts; +use Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; /**