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,6 +113,16 @@ 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.
*
@@ -130,14 +143,13 @@ class BitinflowAccounts
/**
* Set the current user for the application with the given scopes.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|Traits\HasBitinflowTokens $user
* @param Authenticatable|Traits\HasBitinflowTokens $user
* @param array $scopes
* @param string $guard
* @return \Illuminate\Contracts\Auth\Authenticatable
* @return Authenticatable
*/
public static function actingAs($user, $scopes = [], $guard = 'api')
{
$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
@@ -338,6 +317,110 @@ class BitinflowAccounts
return $this->query('GET', $path, $parameters, $paginator);
}
/**
* Build query & execute.
*
* @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
* @throws GuzzleException
* @throws RequestRequiresClientIdException
*/
public function query(string $method = 'GET', string $path = '', array $parameters = [], Paginator $paginator = null, $jsonBody = null): Result
{
if ($paginator !== null) {
$parameters[$paginator->action] = $paginator->cursor();
}
try {
$response = $this->client->request($method, $path, [
'headers' => $this->buildHeaders($jsonBody ? true : false),
'query' => $this->buildQuery($parameters),
'json' => $jsonBody ?: null,
]);
$result = new Result($response, null, $paginator);
} catch (RequestException $exception) {
$result = new Result($exception->getResponse(), $exception, $paginator);
}
$result->bitinflow = $this;
return $result;
}
/**
* Build headers for request.
*
* @param bool $json Body is JSON
*
* @return array
* @throws RequestRequiresClientIdException
*/
private function buildHeaders(bool $json = false): array
{
$headers = [
'Client-ID' => $this->getClientId(),
'Accept' => 'application/json',
];
if ($this->token) {
$headers['Authorization'] = 'Bearer ' . $this->token;
}
if ($json) {
$headers['Content-Type'] = 'application/json';
}
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
@@ -397,81 +480,4 @@ class BitinflowAccounts
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 mixed|null $jsonBody JSON data
*
* @return Result Result object
* @throws GuzzleException
* @throws RequestRequiresClientIdException
*/
public function query(string $method = 'GET', string $path = '', array $parameters = [], Paginator $paginator = null, $jsonBody = null): Result
{
if ($paginator !== null) {
$parameters[$paginator->action] = $paginator->cursor();
}
try {
$response = $this->client->request($method, $path, [
'headers' => $this->buildHeaders($jsonBody ? true : false),
'query' => $this->buildQuery($parameters),
'json' => $jsonBody ?: null,
]);
$result = new Result($response, null, $paginator);
} catch (RequestException $exception) {
$result = new Result($exception->getResponse(), $exception, $paginator);
}
$result->bitinflow = $this;
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.
*
* @param bool $json Body is JSON
*
* @return array
* @throws RequestRequiresClientIdException
*/
private function buildHeaders(bool $json = false): array
{
$headers = [
'Client-ID' => $this->getClientId(),
'Accept' => 'application/json',
];
if ($this->token) {
$headers['Authorization'] = 'Bearer ' . $this->token;
}
if ($json) {
$headers['Content-Type'] = 'application/json';
}
return $headers;
}
}

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

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;

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;

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

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;
@@ -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
@@ -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,6 +176,7 @@ class Result
/**
* Return the current count of items in dataset.
*
* @return int Count
*/
public function count(): int
@@ -170,17 +184,9 @@ class Result
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;
}
/**
* 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
@@ -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,24 +132,6 @@ 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.
*
@@ -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;
/**

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
{

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