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: This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
```php ```php
use GhostZero\BitinflowAccounts\BitinflowAccounts; use Bitinflow\Accounts\BitinflowAccounts;
use GhostZero\BitinflowAccounts\Providers\BitinflowAccountsSsoUserProvider; use Bitinflow\Accounts\Providers\BitinflowAccountsSsoUserProvider;
use Illuminate\Http\Request; use Illuminate\Http\Request;
/** /**

View File

@@ -27,7 +27,7 @@ composer require ghostzero/bitinflow-accounts
Add Service Provider to your `app.php` configuration file: Add Service Provider to your `app.php` configuration file:
```php ```php
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider::class,
``` ```
## Event Listener ## Event Listener
@@ -85,7 +85,7 @@ You will need to add an entry to the services configuration file so that after c
#### Basic #### Basic
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
@@ -106,7 +106,7 @@ echo $sshKey->name;
#### Setters #### Setters
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
$bitinflowAccounts->setClientSecret('abc456'); $bitinflowAccounts->setClientSecret('abc456');
@@ -120,7 +120,7 @@ $bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456');
#### OAuth Tokens #### OAuth Tokens
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
$bitinflowAccounts->setToken('abcdef123456'); $bitinflowAccounts->setToken('abcdef123456');
@@ -143,7 +143,7 @@ $result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser();
#### Facade #### Facade
```php ```php
use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; use Bitinflow\Accounts\Facades\BitinflowAccounts;
BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); 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: Add Service Provider to your `app.php` configuration file:
```php ```php
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class, Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider::class,
``` ```
## Event Listener ## Event Listener
@@ -56,7 +56,7 @@ protected $listen = [
Copy configuration to config folder: 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` 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 #### Basic
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
@@ -105,7 +105,7 @@ echo $sshKey->name;
#### Setters #### Setters
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
$bitinflowAccounts->setClientSecret('abc456'); $bitinflowAccounts->setClientSecret('abc456');
@@ -119,7 +119,7 @@ $bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456');
#### OAuth Tokens #### OAuth Tokens
```php ```php
$bitinflowAccounts = new GhostZero\BitinflowAccounts\BitinflowAccounts(); $bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts();
$bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientId('abc123');
$bitinflowAccounts->setToken('abcdef123456'); $bitinflowAccounts->setToken('abcdef123456');
@@ -142,7 +142,7 @@ $result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser();
#### Facade #### Facade
```php ```php
use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts; use Bitinflow\Accounts\Facades\BitinflowAccounts;
BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser(); BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser();
``` ```

View File

@@ -5,7 +5,11 @@
"authors": [ "authors": [
{ {
"name": "René Preuß", "name": "René Preuß",
"email": "rene@preuss.io" "email": "rene@bitinflow.com"
},
{
"name": "Maurice Preuß",
"email": "maurice@bitinflow.com"
} }
], ],
"require": { "require": {
@@ -24,12 +28,12 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"GhostZero\\BitinflowAccounts\\": "src/GhostZero/BitinflowAccounts" "Bitinflow\\Accounts\\": "src/Accounts"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"GhostZero\\BitinflowAccounts\\Tests\\": "tests/GhostZero/BitinflowAccounts" "Bitinflow\\Accounts\\Tests\\": "tests/Accounts"
} }
}, },
"scripts": { "scripts": {
@@ -39,10 +43,10 @@
"extra": { "extra": {
"laravel": { "laravel": {
"providers": [ "providers": [
"GhostZero\\BitinflowAccounts\\Providers\\BitinflowAccountsServiceProvider" "Bitinflow\\Accounts\\Providers\\BitinflowAccountsServiceProvider"
], ],
"aliases": { "aliases": {
"BitinflowAccounts": "GhostZero\\BitinflowAccounts\\Facades\\BitinflowAccounts" "BitinflowAccounts": "Bitinflow\\Accounts\\Facades\\BitinflowAccounts"
} }
} }
} }

View File

@@ -1,10 +1,13 @@
<?php <?php
return [ return [
// Accounts
'client_id' => env('BITINFLOW_ACCOUNTS_KEY'), 'client_id' => env('BITINFLOW_ACCOUNTS_KEY'),
'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'), 'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'),
'redirect_url' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI'), 'redirect_url' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI'),
'base_url' => env('BITINFLOW_ACCOUNTS_BASE_URL'), 'base_url' => env('BITINFLOW_ACCOUNTS_BASE_URL'),
// Payments
'payments' => [ 'payments' => [
'base_url' => env('BITINFLOW_PAYMENTS_BASE_URL', 'https://api.pay.bitinflow.com/v1/'), '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/'), 'dashboard_url' => env('BITINFLOW_PAYMENTS_DASHBOARD_URL', 'https://pay.bitinflow.com/v1/'),

View File

@@ -2,7 +2,7 @@
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
use GhostZero\BitinflowAccounts\BitinflowAccounts; use Bitinflow\Accounts\BitinflowAccounts;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
$markdown = collect(class_uses(BitinflowAccounts::class)) $markdown = collect(class_uses(BitinflowAccounts::class))

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\ApiOperations; namespace Bitinflow\Accounts\ApiOperations;
use GhostZero\BitinflowAccounts\Helpers\Paginator; use Bitinflow\Accounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\ApiOperations; namespace Bitinflow\Accounts\ApiOperations;
use GhostZero\BitinflowAccounts\Helpers\Paginator; use Bitinflow\Accounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\ApiOperations; namespace Bitinflow\Accounts\ApiOperations;
use GhostZero\BitinflowAccounts\Helpers\Paginator; use Bitinflow\Accounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\ApiOperations; namespace Bitinflow\Accounts\ApiOperations;
use GhostZero\BitinflowAccounts\Helpers\Paginator; use Bitinflow\Accounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

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

View File

@@ -1,13 +1,12 @@
<?php <?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 Exception;
use Firebase\JWT\JWT; 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\AuthenticationException;
use Illuminate\Auth\GuardHelpers; use Illuminate\Auth\GuardHelpers;
use Illuminate\Container\Container; use Illuminate\Container\Container;
@@ -16,6 +15,7 @@ use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Encryption\Encrypter; use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Cookie\CookieValuePrefix; use Illuminate\Cookie\CookieValuePrefix;
use Illuminate\Cookie\Middleware\EncryptCookies; use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use stdClass; use stdClass;
use Throwable; use Throwable;

View File

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

View File

@@ -1,16 +1,17 @@
<?php <?php
namespace GhostZero\BitinflowAccounts; namespace Bitinflow\Accounts;
use GhostZero\BitinflowAccounts\ApiOperations; use Bitinflow\Accounts\ApiOperations;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresAuthenticationException; use Bitinflow\Accounts\Exceptions\RequestRequiresAuthenticationException;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresClientIdException; use Bitinflow\Accounts\Exceptions\RequestRequiresClientIdException;
use GhostZero\BitinflowAccounts\Exceptions\RequestRequiresRedirectUriException; use Bitinflow\Accounts\Exceptions\RequestRequiresRedirectUriException;
use GhostZero\BitinflowAccounts\Helpers\Paginator; use Bitinflow\Accounts\Helpers\Paginator;
use GhostZero\BitinflowAccounts\Traits; use Bitinflow\Accounts\Traits;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use Illuminate\Contracts\Auth\Authenticatable;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>
@@ -29,61 +30,63 @@ class BitinflowAccounts
use ApiOperations\Post; use ApiOperations\Post;
use ApiOperations\Put; use ApiOperations\Put;
private static $baseUrl = 'https://accounts.bitinflow.com/api/';
/** /**
* The name for API token cookies. * The name for API token cookies.
* *
* @var string * @var string
*/ */
public static $cookie = 'bitinflow_token'; public static $cookie = 'bitinflow_token';
/** /**
* Indicates if Bitinflow Accounts should ignore incoming CSRF tokens. * Indicates if Bitinflow Accounts should ignore incoming CSRF tokens.
* *
* @var bool * @var bool
*/ */
public static $ignoreCsrfToken = false; public static $ignoreCsrfToken = false;
/** /**
* Indicates if Bitinflow Accounts should unserializes cookies. * Indicates if Bitinflow Accounts should unserializes cookies.
* *
* @var bool * @var bool
*/ */
public static $unserializesCookies = false; public static $unserializesCookies = false;
private static $baseUrl = 'https://accounts.bitinflow.com/api/';
/** /**
* Guzzle is used to make http requests. * Guzzle is used to make http requests.
* @var \GuzzleHttp\Client *
* @var Client
*/ */
protected $client; protected $client;
/** /**
* Paginator object. * Paginator object.
*
* @var Paginator * @var Paginator
*/ */
protected $paginator; protected $paginator;
/** /**
* bitinflow Accounts OAuth token. * bitinflow Accounts OAuth token.
*
* @var string|null * @var string|null
*/ */
protected $token = null; protected $token = null;
/** /**
* bitinflow Accounts client id. * bitinflow Accounts client id.
*
* @var string|null * @var string|null
*/ */
protected $clientId = null; protected $clientId = null;
/** /**
* bitinflow Accounts client secret. * bitinflow Accounts client secret.
*
* @var string|null * @var string|null
*/ */
protected $clientSecret = null; protected $clientSecret = null;
/** /**
* bitinflow Accounts OAuth redirect url. * bitinflow Accounts OAuth redirect url.
*
* @var string|null * @var string|null
*/ */
protected $redirectUri = 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. * Get or set the name for API token cookies.
* *
* @param string|null $cookie * @param string|null $cookie
* @return string|static * @return string|static
*/ */
public static function cookie($cookie = null) public static function cookie($cookie = null)
@@ -130,15 +143,14 @@ class BitinflowAccounts
/** /**
* Set the current user for the application with the given scopes. * 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 array $scopes
* @param string $guard * @param string $guard
* @return \Illuminate\Contracts\Auth\Authenticatable * @return Authenticatable
*/ */
public static function actingAs($user, $scopes = [], $guard = 'api') public static function actingAs($user, $scopes = [], $guard = 'api')
{ {
$user->withBitinflowAccessToken((object)[
$user->withBitinflowAccessToken((object) [
'scopes' => $scopes 'scopes' => $scopes
]); ]);
@@ -153,42 +165,6 @@ class BitinflowAccounts
return $user; 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. * Fluid client id setter.
* *
@@ -205,6 +181,7 @@ class BitinflowAccounts
/** /**
* Get client secret. * Get client secret.
*
* @return string * @return string
* @throws RequestRequiresClientIdException * @throws RequestRequiresClientIdException
*/ */
@@ -245,6 +222,7 @@ class BitinflowAccounts
/** /**
* Get redirect url. * Get redirect url.
*
* @return string * @return string
* @throws RequestRequiresRedirectUriException * @throws RequestRequiresRedirectUriException
*/ */
@@ -285,6 +263,7 @@ class BitinflowAccounts
/** /**
* Get OAuth token. * Get OAuth token.
*
* @return string bitinflow Accounts token * @return string bitinflow Accounts token
* @return string|null * @return string|null
* @throws RequestRequiresAuthenticationException * @throws RequestRequiresAuthenticationException
@@ -325,8 +304,8 @@ class BitinflowAccounts
} }
/** /**
* @param string $path * @param string $path
* @param array $parameters * @param array $parameters
* @param Paginator|null $paginator * @param Paginator|null $paginator
* *
* @return Result * @return Result
@@ -338,73 +317,13 @@ class BitinflowAccounts
return $this->query('GET', $path, $parameters, $paginator); 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. * Build query & execute.
* *
* @param string $method HTTP method * @param string $method HTTP method
* @param string $path Query path * @param string $path Query path
* @param array $parameters Query parameters * @param array $parameters Query parameters
* @param Paginator $paginator Paginator object * @param Paginator $paginator Paginator object
* @param mixed|null $jsonBody JSON data * @param mixed|null $jsonBody JSON data
* *
* @return Result Result object * @return Result Result object
@@ -431,26 +350,6 @@ class BitinflowAccounts
return $result; 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. * Build headers for request.
* *
@@ -474,4 +373,111 @@ class BitinflowAccounts
return $headers; 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); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Enums; namespace Bitinflow\Accounts\Enums;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,9 +2,9 @@
declare(strict_types=1); 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; use Illuminate\Support\Facades\Facade;
/** /**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Providers; namespace Bitinflow\Accounts\Providers;
use GhostZero\BitinflowAccounts\Auth\TokenGuard; use Bitinflow\Accounts\Auth\TokenGuard;
use GhostZero\BitinflowAccounts\Auth\UserProvider; use Bitinflow\Accounts\Auth\UserProvider;
use GhostZero\BitinflowAccounts\BitinflowAccounts; use Bitinflow\Accounts\BitinflowAccounts;
use GhostZero\BitinflowAccounts\Helpers\JwtParser; use Bitinflow\Accounts\Helpers\JwtParser;
use Illuminate\Auth\RequestGuard; use Illuminate\Auth\RequestGuard;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -17,6 +17,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider
/** /**
* Bootstrap the application services. * Bootstrap the application services.
*
* @return void * @return void
*/ */
public function boot() public function boot()
@@ -28,6 +29,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider
/** /**
* Register the application services. * Register the application services.
*
* @return void * @return void
*/ */
public function register() public function register()
@@ -40,15 +42,6 @@ class BitinflowAccountsServiceProvider extends ServiceProvider
$this->registerGuard(); $this->registerGuard();
} }
/**
* Get the services provided by the provider.
* @return array
*/
public function provides()
{
return [BitinflowAccounts::class];
}
/** /**
* Register the token guard. * Register the token guard.
* *
@@ -68,7 +61,7 @@ class BitinflowAccountsServiceProvider extends ServiceProvider
/** /**
* Make an instance of the token guard. * Make an instance of the token guard.
* *
* @param array $config * @param array $config
* @return RequestGuard * @return RequestGuard
*/ */
protected function makeGuard(array $config): RequestGuard protected function makeGuard(array $config): RequestGuard
@@ -81,4 +74,14 @@ class BitinflowAccountsServiceProvider extends ServiceProvider
))->user($request); ))->user($request);
}, $this->app['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); 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\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
@@ -35,7 +35,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider
} }
/** /**
* @param mixed $identifier * @param mixed $identifier
* @return Builder|Model|object|null * @return Builder|Model|object|null
*/ */
public function retrieveById($identifier) public function retrieveById($identifier)
@@ -85,7 +85,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider
*/ */
public function createModel(): Model public function createModel(): Model
{ {
$class = '\\'.ltrim($this->model, '\\'); $class = '\\' . ltrim($this->model, '\\');
return new $class; return new $class;
} }
@@ -93,7 +93,7 @@ class BitinflowAccountsSsoUserProvider implements UserProvider
/** /**
* Get a new query builder for the model instance. * Get a new query builder for the model instance.
* *
* @param Model|null $model * @param Model|null $model
* @return Builder * @return Builder
*/ */
protected function newModelQuery(Model $model = null): Builder protected function newModelQuery(Model $model = null): Builder

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts; namespace Bitinflow\Accounts;
use Bitinflow\Accounts\Helpers\Paginator;
use Exception; use Exception;
use GhostZero\BitinflowAccounts\Helpers\Paginator;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use stdClass; use stdClass;
@@ -18,54 +18,63 @@ class Result
/** /**
* Query successfull. * Query successfull.
*
* @var boolean * @var boolean
*/ */
public $success = false; public $success = false;
/** /**
* Guzzle exception, if present. * Guzzle exception, if present.
*
* @var null|mixed * @var null|mixed
*/ */
public $exception = null; public $exception = null;
/** /**
* Query result data. * Query result data.
*
* @var array * @var array
*/ */
public $data = []; public $data = [];
/** /**
* Total amount of result data. * Total amount of result data.
*
* @var integer * @var integer
*/ */
public $total = 0; public $total = 0;
/** /**
* Status Code. * Status Code.
*
* @var integer * @var integer
*/ */
public $status = 0; public $status = 0;
/** /**
* bitinflow Accounts response pagination cursor. * bitinflow Accounts response pagination cursor.
* @var null|\stdClass *
* @var null|stdClass
*/ */
public $pagination; public $pagination;
/** /**
* Internal paginator. * Internal paginator.
*
* @var null|Paginator * @var null|Paginator
*/ */
public $paginator; public $paginator;
/** /**
* Original Guzzle HTTP Response. * Original Guzzle HTTP Response.
*
* @var ResponseInterface|null * @var ResponseInterface|null
*/ */
public $response; public $response;
/** /**
* Original bitinflow Accounts instance. * Original bitinflow Accounts instance.
*
* @var BitinflowAccounts * @var BitinflowAccounts
*/ */
public $bitinflow; public $bitinflow;
@@ -73,9 +82,9 @@ class Result
/** /**
* Constructor, * Constructor,
* *
* @param ResponseInterface|null $response HTTP response * @param ResponseInterface|null $response HTTP response
* @param Exception|mixed $exception Exception, if present * @param Exception|mixed $exception Exception, if present
* @param null|Paginator $paginator Paginator, if present * @param null|Paginator $paginator Paginator, if present
*/ */
public function __construct(?ResponseInterface $response, Exception $exception = null, Paginator $paginator = null) 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. * Sets a class attribute by given JSON Response Body.
* *
* @param stdClass $jsonResponse Response Body * @param stdClass $jsonResponse Response Body
* @param string $responseProperty Response property name * @param string $responseProperty Response property name
* @param string|null $attribute Class property name * @param string|null $attribute Class property name
*/ */
private function setProperty(stdClass $jsonResponse, string $responseProperty, string $attribute = null): void private function setProperty(stdClass $jsonResponse, string $responseProperty, string $attribute = null): void
{ {
@@ -111,6 +120,7 @@ class Result
/** /**
* Returns wether the query was successfull. * Returns wether the query was successfull.
*
* @return bool Success state * @return bool Success state
*/ */
public function success(): bool public function success(): bool
@@ -120,6 +130,7 @@ class Result
/** /**
* Get the response data, also available as public attribute. * Get the response data, also available as public attribute.
*
* @return mixed * @return mixed
*/ */
public function data() public function data()
@@ -129,6 +140,7 @@ class Result
/** /**
* Returns the last HTTP or API error. * Returns the last HTTP or API error.
*
* @return string Error message * @return string Error message
*/ */
public function error(): string public function error(): string
@@ -137,7 +149,7 @@ class Result
if ($this->exception === null || !$this->exception->hasResponse()) { if ($this->exception === null || !$this->exception->hasResponse()) {
return 'bitinflow Accounts API Unavailable'; return 'bitinflow Accounts API Unavailable';
} }
$exception = (string) $this->exception->getResponse()->getBody(); $exception = (string)$this->exception->getResponse()->getBody();
$exception = @json_decode($exception); $exception = @json_decode($exception);
if (property_exists($exception, 'message') && !empty($exception->message)) { if (property_exists($exception, 'message') && !empty($exception->message)) {
return $exception->message; return $exception->message;
@@ -148,6 +160,7 @@ class Result
/** /**
* Shifts the current result (Use for single user/video etc. query). * Shifts the current result (Use for single user/video etc. query).
*
* @return mixed Shifted data * @return mixed Shifted data
*/ */
public function shift() public function shift()
@@ -163,24 +176,17 @@ class Result
/** /**
* Return the current count of items in dataset. * Return the current count of items in dataset.
*
* @return int Count * @return int Count
*/ */
public function count(): int public function count(): int
{ {
return count((array) $this->data); 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. * Set the Paginator to fetch the next set of results.
*
* @return null|Paginator * @return null|Paginator
*/ */
public function next(): ?Paginator public function next(): ?Paginator
@@ -190,6 +196,7 @@ class Result
/** /**
* Set the Paginator to fetch the last set of results. * Set the Paginator to fetch the last set of results.
*
* @return null|Paginator * @return null|Paginator
*/ */
public function back(): ?Paginator public function back(): ?Paginator
@@ -210,9 +217,9 @@ class Result
return null; return null;
} }
$rateLimit = [ $rateLimit = [
'limit' => (int) $this->response->getHeaderLine('X-RateLimit-Limit'), 'limit' => (int)$this->response->getHeaderLine('X-RateLimit-Limit'),
'remaining' => (int) $this->response->getHeaderLine('X-RateLimit-Remaining'), 'remaining' => (int)$this->response->getHeaderLine('X-RateLimit-Remaining'),
'reset' => (int) $this->response->getHeaderLine('Retry-After'), 'reset' => (int)$this->response->getHeaderLine('Retry-After'),
]; ];
if ($key === null) { if ($key === null) {
return $rateLimit; return $rateLimit;
@@ -225,7 +232,7 @@ class Result
* Insert users in data response. * Insert users in data response.
* *
* @param string $identifierAttribute Attribute to identify the users * @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 * @return self
*/ */
@@ -248,4 +255,14 @@ class Result
return $this; 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 <?php
namespace GhostZero\BitinflowAccounts\Socialite; namespace Bitinflow\Accounts\Socialite;
use SocialiteProviders\Manager\SocialiteWasCalled; use SocialiteProviders\Manager\SocialiteWasCalled;

View File

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

View File

@@ -1,13 +1,11 @@
<?php <?php
namespace GhostZero\BitinflowAccounts\Traits; namespace Bitinflow\Accounts\Traits;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Log;
use RuntimeException;
/** /**
* @property string access_token todo: can we get this from HasBitinflowTokens ? * @property string access_token todo: can we get this from HasBitinflowTokens ?
@@ -15,7 +13,33 @@ use RuntimeException;
*/ */
trait HasBitinflowPaymentsWallet 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. * Create a new payment gateway request.
@@ -44,32 +68,6 @@ trait HasBitinflowPaymentsWallet
return json_decode($response->getBody()); 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 public function getWalletSetupIntent(string $success_path = ''): string
{ {
return sprintf('%swallet?continue_url=%s', config('bitinflow-accounts.payments.dashboard_url'), url($success_path)); 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; 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. * Get vat from user.
* *
@@ -116,33 +132,15 @@ trait HasBitinflowPaymentsWallet
return $subscriptions; 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. * Create a new subscription.
* *
* @param array $attributes array which requires following attributes: * @param array $attributes array which requires following attributes:
* name, description, period, price * name, description, period, price
* and following attributes are optional: * and following attributes are optional:
* vat, payload, ends_at, webhook_url, webhook_secret * vat, payload, ends_at, webhook_url, webhook_secret
* @param array $payload optional data that is stored in the subscription * @param array $payload optional data that is stored in the subscription
* @param bool $checkout optional checkout it directly * @param bool $checkout optional checkout it directly
* @return object the subscription object * @return object the subscription object
* @throws GuzzleException * @throws GuzzleException
*/ */
@@ -153,7 +151,10 @@ trait HasBitinflowPaymentsWallet
'client_id' => config('bitinflow-accounts.client_id') 'client_id' => config('bitinflow-accounts.client_id')
]; ];
$defaults = ['period' => 'monthly']; $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; return $this->paymentsGatewayRequest('POST', 'subscriptions', $attributes)->data;
} }

View File

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

View File

@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Traits; namespace Bitinflow\Accounts\Traits;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
/** /**
@@ -17,7 +17,7 @@ trait OauthTrait
* Retrieving a oauth token using a given grant type. * Retrieving a oauth token using a given grant type.
* *
* @param string $grantType * @param string $grantType
* @param array $attributes * @param array $attributes
* *
* @return Result * @return Result
*/ */
@@ -25,12 +25,12 @@ trait OauthTrait
{ {
try { try {
$response = $this->client->request('POST', '/oauth/token', [ $response = $this->client->request('POST', '/oauth/token', [
'form_params' => $attributes + [ 'form_params' => $attributes + [
'grant_type' => $grantType, 'grant_type' => $grantType,
'client_id' => $this->getClientId(), 'client_id' => $this->getClientId(),
'client_secret' => $this->getClientSecret(), 'client_secret' => $this->getClientSecret(),
], ],
]); ]);
$result = new Result($response, null); $result = new Result($response, null);
} catch (RequestException $exception) { } catch (RequestException $exception) {

View File

@@ -2,12 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Traits; namespace Bitinflow\Accounts\Traits;
use GhostZero\BitinflowAccounts\ApiOperations\Delete; use Bitinflow\Accounts\ApiOperations\Delete;
use GhostZero\BitinflowAccounts\ApiOperations\Get; use Bitinflow\Accounts\ApiOperations\Get;
use GhostZero\BitinflowAccounts\ApiOperations\Post; use Bitinflow\Accounts\ApiOperations\Post;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
trait SshKeysTrait trait SshKeysTrait
{ {
@@ -29,7 +29,7 @@ trait SshKeysTrait
/** /**
* Creates ssh key for the currently authed user * Creates ssh key for the currently authed user
* *
* @param string $publicKey * @param string $publicKey
* @param string|null $name * @param string|null $name
* *
* @return Result Result object * @return Result Result object

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Traits; namespace Bitinflow\Accounts\Traits;
use GhostZero\BitinflowAccounts\ApiOperations\Get; use Bitinflow\Accounts\ApiOperations\Get;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
trait UsersTrait trait UsersTrait
{ {
@@ -14,6 +14,7 @@ trait UsersTrait
/** /**
* Get currently authed user with Bearer Token * Get currently authed user with Bearer Token
*
* @return Result Result object * @return Result Result object
*/ */
public function getAuthedUser(): Result public function getAuthedUser(): Result

View File

@@ -2,9 +2,9 @@
declare(strict_types=1); 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> * @author René Preuß <rene@preuss.io>

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Tests; namespace Bitinflow\Accounts\Tests;
use GhostZero\BitinflowAccounts\Result; use Bitinflow\Accounts\Result;
use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; use Bitinflow\Accounts\Tests\TestCases\ApiTestCase;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Tests; namespace Bitinflow\Accounts\Tests;
use GhostZero\BitinflowAccounts\Enums\Scope; use Bitinflow\Accounts\Enums\Scope;
use GhostZero\BitinflowAccounts\Tests\TestCases\ApiTestCase; use Bitinflow\Accounts\Tests\TestCases\ApiTestCase;
use Illuminate\Support\Str; use Illuminate\Support\Str;
/** /**

View File

@@ -2,11 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Tests; namespace Bitinflow\Accounts\Tests;
use GhostZero\BitinflowAccounts\BitinflowAccounts; use Bitinflow\Accounts\BitinflowAccounts;
use GhostZero\BitinflowAccounts\Facades\BitinflowAccounts as BitinflowAccountsFacade; use Bitinflow\Accounts\Facades\BitinflowAccounts as BitinflowAccountsFacade;
use GhostZero\BitinflowAccounts\Tests\TestCases\TestCase; use Bitinflow\Accounts\Tests\TestCases\TestCase;
/** /**
* @author René Preuß <rene@preuss.io> * @author René Preuß <rene@preuss.io>

View File

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

View File

@@ -2,10 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
namespace GhostZero\BitinflowAccounts\Tests\TestCases; namespace Bitinflow\Accounts\Tests\TestCases;
use GhostZero\BitinflowAccounts\BitinflowAccounts; use Bitinflow\Accounts\BitinflowAccounts;
use GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider; use Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase; use Orchestra\Testbench\TestCase as BaseTestCase;
/** /**