change namespace and cleanup code

This commit is contained in:
2022-05-14 18:21:55 +02:00
parent 76edd961b7
commit 377dc53037
46 changed files with 400 additions and 360 deletions

View File

@@ -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;
/**

View File

@@ -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();
```

View File

@@ -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();
```

View File

@@ -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"
}
}
}

View File

@@ -1,10 +1,13 @@
<?php
return [
// Accounts
'client_id' => 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/'),

View File

@@ -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))

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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ß <rene@preuss.io>

View File

@@ -1,6 +1,6 @@
<?php
namespace GhostZero\BitinflowAccounts;
namespace Bitinflow\Accounts;
use Carbon\Carbon;
use Firebase\JWT\JWT;

View File

@@ -1,13 +1,12 @@
<?php
namespace GhostZero\BitinflowAccounts\Auth;
namespace Bitinflow\Accounts\Auth;
use Bitinflow\Accounts\BitinflowAccounts;
use Bitinflow\Accounts\Helpers\JwtParser;
use Bitinflow\Accounts\Traits\HasBitinflowTokens;
use Exception;
use Firebase\JWT\JWT;
use GhostZero\BitinflowAccounts\BitinflowAccounts;
use GhostZero\BitinflowAccounts\Helpers\JwtParser;
use GhostZero\BitinflowAccounts\Traits\HasBitinflowTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\GuardHelpers;
use Illuminate\Container\Container;
@@ -16,6 +15,7 @@ use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Cookie\CookieValuePrefix;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Request;
use stdClass;
use Throwable;

View File

@@ -1,6 +1,6 @@
<?php
namespace GhostZero\BitinflowAccounts\Auth;
namespace Bitinflow\Accounts\Auth;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider as Base;

View File

@@ -1,16 +1,17 @@
<?php
namespace GhostZero\BitinflowAccounts;
namespace Bitinflow\Accounts;
use GhostZero\BitinflowAccounts\ApiOperations;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresAuthenticationException;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresClientIdException;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresRedirectUriException;
use GhostZero\BitinflowAccounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Traits;
use Bitinflow\Accounts\ApiOperations;
use Bitinflow\Accounts\Exceptions\RequestRequiresAuthenticationException;
use Bitinflow\Accounts\Exceptions\RequestRequiresClientIdException;
use Bitinflow\Accounts\Exceptions\RequestRequiresRedirectUriException;
use Bitinflow\Accounts\Helpers\Paginator;
use Bitinflow\Accounts\Traits;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Contracts\Auth\Authenticatable;
/**
* @author René Preuß <rene@preuss.io>
@@ -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);
}
}

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Enums;
namespace Bitinflow\Accounts\Enums;
/**
* @author René Preuß <rene@preuss.io>

View File

@@ -1,6 +1,6 @@
<?php
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Arr;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Exception;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Exception;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Exception;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Exception;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Exceptions;
namespace Bitinflow\Accounts\Exceptions;
use Exception;

View File

@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Facades;
namespace Bitinflow\Accounts\Facades;
use GhostZero\BitinflowAccounts\BitinflowAccounts as BitinflowAccountsService;
use Bitinflow\Accounts\BitinflowAccounts as BitinflowAccountsService;
use Illuminate\Support\Facades\Facade;
/**

View File

@@ -1,7 +1,7 @@
<?php
namespace GhostZero\BitinflowAccounts\Helpers;
namespace Bitinflow\Accounts\Helpers;
use Firebase\JWT\JWT;

View File

@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Helpers;
namespace Bitinflow\Accounts\Helpers;
use GhostZero\BitinflowAccounts\Result;
use Bitinflow\Accounts\Result;
use stdClass;
/**
@@ -13,17 +13,18 @@ use stdClass;
class Paginator
{
/**
* bitinflow Accounts response pagination cursor.
* @var null|stdClass
*/
private $pagination;
/**
* Next desired action (first, after, before).
*
* @var null|string
*/
public $action = null;
/**
* bitinflow Accounts response pagination cursor.
*
* @var null|stdClass
*/
private $pagination;
/**
* Constructor.
@@ -38,7 +39,7 @@ class Paginator
/**
* Create Paginator from Result object.
*
* @param Result $result Result object
* @param Result $result Result object
*
* @return self Paginator object
*/
@@ -49,6 +50,7 @@ class Paginator
/**
* Return the current active cursor.
*
* @return string bitinflow Accounts cursor
*/
public function cursor(): string
@@ -58,6 +60,7 @@ class Paginator
/**
* Set the Paginator to fetch the next set of results.
*
* @return self
*/
public function first(): self
@@ -69,6 +72,7 @@ class Paginator
/**
* Set the Paginator to fetch the first set of results.
*
* @return self
*/
public function next(): self
@@ -80,6 +84,7 @@ class Paginator
/**
* Set the Paginator to fetch the last set of results.
*
* @return self
*/
public function back(): self

View File

@@ -1,8 +1,8 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use GhostZero\BitinflowAccounts\Exceptions\MissingScopeException;
use Bitinflow\Accounts\Exceptions\MissingScopeException;
use stdClass;
class CheckClientCredentials extends CheckCredentials

View File

@@ -1,8 +1,8 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use GhostZero\BitinflowAccounts\Exceptions\MissingScopeException;
use Bitinflow\Accounts\Exceptions\MissingScopeException;
use stdClass;
class CheckClientCredentialsForAnyScope extends CheckCredentials

View File

@@ -1,10 +1,10 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use Bitinflow\Accounts\Exceptions\MissingScopeException;
use Bitinflow\Accounts\Helpers\JwtParser;
use Closure;
use GhostZero\BitinflowAccounts\Exceptions\MissingScopeException;
use GhostZero\BitinflowAccounts\Helpers\JwtParser;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use stdClass;

View File

@@ -1,11 +1,11 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use Bitinflow\Accounts\Exceptions\MissingScopeException;
use Closure;
use GhostZero\BitinflowAccounts\Exceptions\MissingScopeException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -15,16 +15,16 @@ class CheckForAnyScope
/**
* Handle the incoming request.
*
* @param Request $request
* @param Closure $next
* @param mixed ...$scopes
* @param Request $request
* @param Closure $next
* @param mixed ...$scopes
* @return Response
*
* @throws AuthenticationException|MissingScopeException
*/
public function handle($request, $next, ...$scopes)
{
if (! $request->user() || ! $request->user()->bitinflowToken()) {
if (!$request->user() || !$request->user()->bitinflowToken()) {
throw new AuthenticationException;
}

View File

@@ -1,9 +1,9 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use Bitinflow\Accounts\Exceptions\MissingScopeException;
use Closure;
use GhostZero\BitinflowAccounts\Exceptions\MissingScopeException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -13,21 +13,21 @@ class CheckScopes
/**
* Handle the incoming request.
*
* @param Request $request
* @param Closure $next
* @param mixed ...$scopes
* @param Request $request
* @param Closure $next
* @param mixed ...$scopes
* @return Response
*
* @throws AuthenticationException|MissingScopeException
*/
public function handle($request, $next, ...$scopes)
{
if (! $request->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);
}
}

View File

@@ -1,10 +1,10 @@
<?php
namespace GhostZero\BitinflowAccounts\Http\Middleware;
namespace Bitinflow\Accounts\Http\Middleware;
use Bitinflow\Accounts\ApiTokenCookieFactory;
use Bitinflow\Accounts\BitinflowAccounts;
use Closure;
use GhostZero\BitinflowAccounts\ApiTokenCookieFactory;
use GhostZero\BitinflowAccounts\BitinflowAccounts;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -28,7 +28,7 @@ class CreateFreshApiToken
/**
* Create a new middleware instance.
*
* @param ApiTokenCookieFactory $cookieFactory
* @param ApiTokenCookieFactory $cookieFactory
* @return void
*/
public function __construct(ApiTokenCookieFactory $cookieFactory)
@@ -39,9 +39,9 @@ class CreateFreshApiToken
/**
* Handle an incoming request.
*
* @param Request $request
* @param Request $request
* @param Closure $next
* @param string|null $guard
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
@@ -62,7 +62,7 @@ class CreateFreshApiToken
/**
* Determine if the given request should receive a fresh token.
*
* @param Request $request
* @param Request $request
* @param Response $response
* @return bool
*/
@@ -75,7 +75,7 @@ class CreateFreshApiToken
/**
* Determine if the request should receive a fresh token.
*
* @param Request $request
* @param Request $request
* @return bool
*/
protected function requestShouldReceiveFreshToken($request)
@@ -93,7 +93,7 @@ class CreateFreshApiToken
{
return ($response instanceof Response ||
$response instanceof JsonResponse) &&
! $this->alreadyContainsToken($response);
!$this->alreadyContainsToken($response);
}
/**

View File

@@ -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];
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace GhostZero\BitinflowAccounts\Socialite;
namespace Bitinflow\Accounts\Socialite;
use SocialiteProviders\Manager\SocialiteWasCalled;

View File

@@ -1,8 +1,8 @@
<?php
namespace GhostZero\BitinflowAccounts\Socialite;
namespace Bitinflow\Accounts\Socialite;
use GhostZero\BitinflowAccounts\Enums\Scope;
use Bitinflow\Accounts\Enums\Scope;
use Illuminate\Support\Arr;
use Laravel\Socialite\Two\ProviderInterface;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;

View File

@@ -1,13 +1,11 @@
<?php
namespace GhostZero\BitinflowAccounts\Traits;
namespace Bitinflow\Accounts\Traits;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Log;
use RuntimeException;
/**
* @property string access_token todo: can we get this from HasBitinflowTokens ?
@@ -15,7 +13,33 @@ use RuntimeException;
*/
trait HasBitinflowPaymentsWallet
{
protected ?object $paymentsUser = null;
protected $paymentsUser = null;
/**
* Check if user has an active wallet.
*
* @return bool
* @throws GuzzleException
*/
public function hasWallet(): bool
{
return $this->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;
}

View File

@@ -1,6 +1,6 @@
<?php
namespace GhostZero\BitinflowAccounts\Traits;
namespace Bitinflow\Accounts\Traits;
use stdClass;

View File

@@ -2,9 +2,9 @@
declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Traits;
namespace Bitinflow\Accounts\Traits;
use GhostZero\BitinflowAccounts\Result;
use Bitinflow\Accounts\Result;
use GuzzleHttp\Exception\RequestException;
/**
@@ -17,7 +17,7 @@ trait OauthTrait
* Retrieving a oauth token using a given grant type.
*
* @param string $grantType
* @param array $attributes
* @param array $attributes
*
* @return Result
*/
@@ -25,12 +25,12 @@ trait OauthTrait
{
try {
$response = $this->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) {

View File

@@ -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

View File

@@ -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

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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;
/**

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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ß <rene@preuss.io>

View File

@@ -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;
/**