mirror of
https://github.com/bitinflow/accounts.git
synced 2026-11-01 05:09:07 +00:00
Improve api operations
Change directory structure Add bitinflow-accounts socialite provider Improve docs generation
This commit is contained in:
1 parent
8a3d7e0411
commit
228c845bb5
32 files changed
+569
-37
No files matched your search
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Enums;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class Scope
|
||||
{
|
||||
|
||||
/*
|
||||
* v0 API
|
||||
*/
|
||||
|
||||
// Deprecated scope.
|
||||
const API = 'api';
|
||||
|
||||
// Read nonpublic user information, including email address.
|
||||
const READ_USER = 'read_user';
|
||||
}
|
||||
+4
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait Delete
|
||||
{
|
||||
|
||||
abstract public function delete(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||
}
|
||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait Get
|
||||
{
|
||||
|
||||
abstract public function get(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||
}
|
||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait Post
|
||||
{
|
||||
|
||||
abstract public function post(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||
}
|
||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait Put
|
||||
{
|
||||
|
||||
abstract public function put(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||
}
|
||||
@@ -17,8 +17,10 @@ use GuzzleHttp\Exception\RequestException;
|
||||
class BitinflowAccounts
|
||||
{
|
||||
|
||||
use Traits\UsersTrait;
|
||||
use Traits\ChargesTrait;
|
||||
use Traits\CheckoutSessionsTrait;
|
||||
use Traits\SshKeysTrait;
|
||||
use Traits\UsersTrait;
|
||||
|
||||
const BASE_URI = 'https://accounts.bitinflow.com/api/';
|
||||
const OAUTH_BASE_URI = 'https://accounts.bitinflow.com/api/';
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Enums;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class Scope
|
||||
{
|
||||
|
||||
/*
|
||||
* v0 API
|
||||
*/
|
||||
|
||||
// Deprecated scope.
|
||||
const API = 'api';
|
||||
|
||||
// Read nonpublic user information, including email address.
|
||||
const READ_USER = 'read_user';
|
||||
|
||||
/*
|
||||
* v1 API
|
||||
*/
|
||||
|
||||
// Read authorized user´s email address.
|
||||
const USERS_READ_EMAIL = 'users:read:email';
|
||||
|
||||
// Manage a authorized user object.
|
||||
const USERS_EDIT = 'users:edit';
|
||||
|
||||
// Read authorized user´s transactions.
|
||||
const TRANSACTIONS_READ = 'transactions:read';
|
||||
|
||||
// Create a new charge for the authorized user.
|
||||
const CHARGES_CREATE = 'charges:create';
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Socialite;
|
||||
|
||||
use SocialiteProviders\Manager\SocialiteWasCalled;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class BitinflowExtendSocialite
|
||||
{
|
||||
|
||||
/**
|
||||
* Register the provider.
|
||||
*
|
||||
* @param SocialiteWasCalled $socialiteWasCalled
|
||||
*/
|
||||
public function handle(SocialiteWasCalled $socialiteWasCalled)
|
||||
{
|
||||
$socialiteWasCalled->extendSocialite(
|
||||
'bitinflow-accounts', __NAMESPACE__ . '\Provider'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Socialite;
|
||||
|
||||
use GhostZero\BitinflowAccounts\Enums\Scope;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laravel\Socialite\Two\ProviderInterface;
|
||||
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
|
||||
use SocialiteProviders\Manager\OAuth2\User;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
class Provider extends AbstractProvider implements ProviderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Unique Provider Identifier.
|
||||
*/
|
||||
const IDENTIFIER = 'BITINFLOW_ACCOUNTS';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $scopes = [Scope::READ_USER];
|
||||
|
||||
/**
|
||||
* {@inherticdoc}.
|
||||
*/
|
||||
protected $scopeSeparator = ' ';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAuthUrl($state)
|
||||
{
|
||||
return $this->buildAuthUrlFromBase(
|
||||
'https://accounts.bitinflow.com/oauth/authorize', $state
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenUrl()
|
||||
{
|
||||
return 'https://accounts.bitinflow.com/oauth/token';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getUserByToken($token)
|
||||
{
|
||||
$response = $this->getHttpClient()->get(
|
||||
'https://accounts.bitinflow.com/api/user', [
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
],
|
||||
]);
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function mapUserToObject(array $user)
|
||||
{
|
||||
return (new User())->setRaw($user)->map([
|
||||
'id' => $user['id'],
|
||||
'nickname' => $user['name'],
|
||||
'name' => $user['name'],
|
||||
'email' => Arr::get($user, 'email'),
|
||||
'avatar' => $user['avatar'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTokenFields($code)
|
||||
{
|
||||
return array_merge(parent::getTokenFields($code), [
|
||||
'grant_type' => 'authorization_code',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Traits;
|
||||
|
||||
use GhostZero\BitinflowAccounts\ApiOperations\Get;
|
||||
use GhostZero\BitinflowAccounts\ApiOperations\Post;
|
||||
use GhostZero\BitinflowAccounts\ApiOperations\Put;
|
||||
use GhostZero\BitinflowAccounts\Result;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait ChargesTrait
|
||||
{
|
||||
|
||||
use Get, Post, Put;
|
||||
|
||||
/**
|
||||
* Create a Charge object
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Result Result object
|
||||
*/
|
||||
public function createCharge(array $parameters): Result
|
||||
{
|
||||
return $this->post('charges', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Charge object
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return Result Result object
|
||||
*/
|
||||
public function getCharge(string $id): Result
|
||||
{
|
||||
return $this->get("charges/$id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a Charge object
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Result Result object
|
||||
*/
|
||||
public function updateCharge(string $id, array $parameters): Result
|
||||
{
|
||||
return $this->put("charges/$id", $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture a Charge object
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Result Result object
|
||||
*/
|
||||
public function captureCharge(string $id, array $parameters = []): Result
|
||||
{
|
||||
return $this->post("charges/$id/capture", $parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GhostZero\BitinflowAccounts\Traits;
|
||||
|
||||
use GhostZero\BitinflowAccounts\ApiOperations\Get;
|
||||
use GhostZero\BitinflowAccounts\ApiOperations\Post;
|
||||
use GhostZero\BitinflowAccounts\Result;
|
||||
|
||||
/**
|
||||
* @author René Preuß <rene@preuss.io>
|
||||
*/
|
||||
trait CheckoutSessionsTrait
|
||||
{
|
||||
|
||||
use Get, Post;
|
||||
|
||||
/**
|
||||
* Get a Session object
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return Result Result object
|
||||
*/
|
||||
public function getCheckoutSession(string $id): Result
|
||||
{
|
||||
return $this->get("checkout/sessions/$id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Session object
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Result
|
||||
*/
|
||||
public function createCheckoutSession(array $parameters): Result
|
||||
{
|
||||
return $this->post('payments/sessions', $parameters);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -39,7 +39,7 @@ trait SshKeysTrait
|
||||
return $this->post('ssh-keys', [
|
||||
'public_key' => $publicKey,
|
||||
'name' => $name,
|
||||
], null);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,6 +51,6 @@ trait SshKeysTrait
|
||||
*/
|
||||
public function deleteSshKey(int $id): Result
|
||||
{
|
||||
return $this->delete("ssh-keys/$id", [], null);
|
||||
return $this->delete("ssh-keys/$id", []);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user