mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-17 23:45:52 +00:00
Improve api operations
Change directory structure Add bitinflow-accounts socialite provider Improve docs generation
This commit is contained in:
63
README.md
63
README.md
@@ -9,9 +9,10 @@ PHP bitinflow Accounts API Client for Laravel 5+
|
|||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
1. [Installation](#installation)
|
1. [Installation](#installation)
|
||||||
2. [Configuration](#configuration)
|
2. [Event Listener](#event-listener)
|
||||||
3. [Examples](#examples)
|
3. [Configuration](#configuration)
|
||||||
4. [Documentation](#documentation)
|
4. [Examples](#examples)
|
||||||
|
5. [Documentation](#documentation)
|
||||||
6. [Development](#Development)
|
6. [Development](#Development)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@@ -28,6 +29,28 @@ Add Service Provider to your `app.php` configuration file:
|
|||||||
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class,
|
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class,
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Event Listener
|
||||||
|
|
||||||
|
- Add `SocialiteProviders\Manager\SocialiteWasCalled` event to your `listen[]` array in `app/Providers/EventServiceProvider`.
|
||||||
|
- Add your listeners (i.e. the ones from the providers) to the `SocialiteProviders\Manager\SocialiteWasCalled[]` that you just created.
|
||||||
|
- The listener that you add for this provider is `'GhostZero\\BitinflowAccounts\\Socialite\\BitinflowExtendSocialite@handle',`.
|
||||||
|
- Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
/**
|
||||||
|
* The event handler mappings for the application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $listen = [
|
||||||
|
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
|
||||||
|
// add your listeners (aka providers) here
|
||||||
|
'GhostZero\\BitinflowAccounts\\Socialite\\BitinflowExtendSocialite@handle',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Copy configuration to config folder:
|
Copy configuration to config folder:
|
||||||
@@ -44,6 +67,18 @@ BITINFLOW_ACCOUNTS_SECRET=
|
|||||||
BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost
|
BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
||||||
|
|
||||||
|
**Add to `config/services.php`:**
|
||||||
|
|
||||||
|
```php
|
||||||
|
'bitinflow-accounts' => [
|
||||||
|
'client_id' => env('BITINFLOW_ACCOUNTS_KEY'),
|
||||||
|
'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'),
|
||||||
|
'redirect' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI')
|
||||||
|
],
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
#### Basic
|
#### Basic
|
||||||
@@ -114,10 +149,20 @@ BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedU
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### Users
|
### Charges
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function getAuthedUser()
|
public function createCharge(array $parameters)
|
||||||
|
public function getCharge(string $id)
|
||||||
|
public function updateCharge(string $id, array $parameters)
|
||||||
|
public function captureCharge(string $id, array $parameters = [])
|
||||||
|
```
|
||||||
|
|
||||||
|
### CheckoutSessions
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function getCheckoutSession(string $id)
|
||||||
|
public function createCheckoutSession(array $parameters)
|
||||||
```
|
```
|
||||||
|
|
||||||
### SshKeys
|
### SshKeys
|
||||||
@@ -128,7 +173,13 @@ public function createSshKey(string $publicKey, string $name = NULL)
|
|||||||
public function deleteSshKey(int $id)
|
public function deleteSshKey(int $id)
|
||||||
```
|
```
|
||||||
|
|
||||||
[**OAuth Scopes Enums**](https://git.preuss.io/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php)
|
### Users
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function getAuthedUser()
|
||||||
|
```
|
||||||
|
|
||||||
|
[**OAuth Scopes Enums**](https://github.com/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
|||||||
36
README.stub
36
README.stub
@@ -28,6 +28,28 @@ Add Service Provider to your `app.php` configuration file:
|
|||||||
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class,
|
GhostZero\BitinflowAccounts\Providers\BitinflowAccountsServiceProvider::class,
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Event Listener
|
||||||
|
|
||||||
|
- Add `SocialiteProviders\Manager\SocialiteWasCalled` event to your `listen[]` array in `app/Providers/EventServiceProvider`.
|
||||||
|
- Add your listeners (i.e. the ones from the providers) to the `SocialiteProviders\Manager\SocialiteWasCalled[]` that you just created.
|
||||||
|
- The listener that you add for this provider is `'GhostZero\\BitinflowAccounts\\Socialite\\BitinflowExtendSocialite@handle',`.
|
||||||
|
- Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
/**
|
||||||
|
* The event handler mappings for the application.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $listen = [
|
||||||
|
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
|
||||||
|
// add your listeners (aka providers) here
|
||||||
|
'GhostZero\\BitinflowAccounts\\Socialite\\BitinflowExtendSocialite@handle',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Copy configuration to config folder:
|
Copy configuration to config folder:
|
||||||
@@ -44,6 +66,18 @@ BITINFLOW_ACCOUNTS_SECRET=
|
|||||||
BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost
|
BITINFLOW_ACCOUNTS_REDIRECT_URI=http://localhost
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
||||||
|
|
||||||
|
**Add to `config/services.php`:**
|
||||||
|
|
||||||
|
```php
|
||||||
|
'bitinflow-accounts' => [
|
||||||
|
'client_id' => env('BITINFLOW_ACCOUNTS_KEY'),
|
||||||
|
'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'),
|
||||||
|
'redirect' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI')
|
||||||
|
],
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
#### Basic
|
#### Basic
|
||||||
@@ -116,7 +150,7 @@ BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedU
|
|||||||
|
|
||||||
<!-- GENERATED-DOCS -->
|
<!-- GENERATED-DOCS -->
|
||||||
|
|
||||||
[**OAuth Scopes Enums**](https://git.preuss.io/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php)
|
[**OAuth Scopes Enums**](https://github.com/ghostzero/bitinflow-accounts/blob/master/src/Enums/Scope.php)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,11 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2",
|
"php": ">=7.2",
|
||||||
|
"ext-json": "*",
|
||||||
"illuminate/support": "^5.5",
|
"illuminate/support": "^5.5",
|
||||||
"illuminate/console": "^5.5",
|
"illuminate/console": "^5.5",
|
||||||
"guzzlehttp/guzzle": "^6.3"
|
"guzzlehttp/guzzle": "^6.3",
|
||||||
|
"socialiteproviders/manager": "^3.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^8.0",
|
"phpunit/phpunit": "^8.0",
|
||||||
@@ -21,12 +23,12 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"GhostZero\\BitinflowAccounts\\": "src"
|
"GhostZero\\BitinflowAccounts\\": "src/GhostZero/BitinflowAccounts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"GhostZero\\BitinflowAccounts\\Tests\\": "tests"
|
"GhostZero\\BitinflowAccounts\\Tests\\": "tests/GhostZero/BitinflowAccounts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
189
composer.lock
generated
189
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "d862392957845962bdb82aeb0ee836fe",
|
"content-hash": "d05b61cfebf348cc424dbf01ec508a51",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "doctrine/inflector",
|
"name": "doctrine/inflector",
|
||||||
@@ -627,6 +627,70 @@
|
|||||||
],
|
],
|
||||||
"time": "2019-08-27T14:35:59+00:00"
|
"time": "2019-08-27T14:35:59+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "laravel/socialite",
|
||||||
|
"version": "v4.2.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/laravel/socialite.git",
|
||||||
|
"reference": "f509d06e1e7323997b804c5152874f8aad4508e9"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/laravel/socialite/zipball/f509d06e1e7323997b804c5152874f8aad4508e9",
|
||||||
|
"reference": "f509d06e1e7323997b804c5152874f8aad4508e9",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*",
|
||||||
|
"guzzlehttp/guzzle": "~6.0",
|
||||||
|
"illuminate/http": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||||
|
"illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||||
|
"league/oauth1-client": "~1.0",
|
||||||
|
"php": "^7.1.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"illuminate/contracts": "~5.7.0|~5.8.0|^6.0|^7.0",
|
||||||
|
"mockery/mockery": "^1.0",
|
||||||
|
"phpunit/phpunit": "^7.0|^8.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "4.0-dev"
|
||||||
|
},
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Laravel\\Socialite\\SocialiteServiceProvider"
|
||||||
|
],
|
||||||
|
"aliases": {
|
||||||
|
"Socialite": "Laravel\\Socialite\\Facades\\Socialite"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Laravel\\Socialite\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.",
|
||||||
|
"homepage": "https://laravel.com",
|
||||||
|
"keywords": [
|
||||||
|
"laravel",
|
||||||
|
"oauth"
|
||||||
|
],
|
||||||
|
"time": "2019-09-03T15:27:17+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "league/flysystem",
|
"name": "league/flysystem",
|
||||||
"version": "1.0.55",
|
"version": "1.0.55",
|
||||||
@@ -711,6 +775,69 @@
|
|||||||
],
|
],
|
||||||
"time": "2019-08-24T11:17:19+00:00"
|
"time": "2019-08-24T11:17:19+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "league/oauth1-client",
|
||||||
|
"version": "1.7.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/thephpleague/oauth1-client.git",
|
||||||
|
"reference": "fca5f160650cb74d23fc11aa570dd61f86dcf647"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/fca5f160650cb74d23fc11aa570dd61f86dcf647",
|
||||||
|
"reference": "fca5f160650cb74d23fc11aa570dd61f86dcf647",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"guzzlehttp/guzzle": "^6.0",
|
||||||
|
"php": ">=5.5.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mockery/mockery": "^0.9",
|
||||||
|
"phpunit/phpunit": "^4.0",
|
||||||
|
"squizlabs/php_codesniffer": "^2.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"League\\OAuth1\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Ben Corlett",
|
||||||
|
"email": "bencorlett@me.com",
|
||||||
|
"homepage": "http://www.webcomm.com.au",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "OAuth 1.0 Client Library",
|
||||||
|
"keywords": [
|
||||||
|
"Authentication",
|
||||||
|
"SSO",
|
||||||
|
"authorization",
|
||||||
|
"bitbucket",
|
||||||
|
"identity",
|
||||||
|
"idp",
|
||||||
|
"oauth",
|
||||||
|
"oauth1",
|
||||||
|
"single sign on",
|
||||||
|
"trello",
|
||||||
|
"tumblr",
|
||||||
|
"twitter"
|
||||||
|
],
|
||||||
|
"time": "2016-08-17T00:36:58+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
"version": "1.24.0",
|
"version": "1.24.0",
|
||||||
@@ -1328,6 +1455,63 @@
|
|||||||
],
|
],
|
||||||
"time": "2018-07-19T23:38:55+00:00"
|
"time": "2018-07-19T23:38:55+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "socialiteproviders/manager",
|
||||||
|
"version": "v3.4.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/SocialiteProviders/Manager.git",
|
||||||
|
"reference": "e3e8e78b9a3060801cd008941a0894a0a0c479e1"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/SocialiteProviders/Manager/zipball/e3e8e78b9a3060801cd008941a0894a0a0c479e1",
|
||||||
|
"reference": "e3e8e78b9a3060801cd008941a0894a0a0c479e1",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/support": "~5.4|~5.7.0|~5.8.0|^6.0",
|
||||||
|
"laravel/socialite": "~3.0|~4.0",
|
||||||
|
"php": "^5.6 || ^7.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mockery/mockery": "^0.9.4",
|
||||||
|
"phpunit/phpunit": "^5.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"SocialiteProviders\\Manager\\ServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SocialiteProviders\\Manager\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Andy Wendt",
|
||||||
|
"email": "andy@awendt.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Anton Komarev",
|
||||||
|
"email": "a.komarev@cybercog.su"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Miguel Piedrafita",
|
||||||
|
"email": "soy@miguelpiedrafita.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Easily add new or override built-in providers in Laravel Socialite.",
|
||||||
|
"time": "2019-09-09T03:07:52+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "swiftmailer/swiftmailer",
|
"name": "swiftmailer/swiftmailer",
|
||||||
"version": "v6.2.1",
|
"version": "v6.2.1",
|
||||||
@@ -4810,7 +4994,8 @@
|
|||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=7.2"
|
"php": ">=7.2",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": []
|
"platform-dev": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ $markdown = collect(class_uses(BitinflowAccounts::class))
|
|||||||
return $markdown;
|
return $markdown;
|
||||||
})->join(PHP_EOL . PHP_EOL);
|
})->join(PHP_EOL . PHP_EOL);
|
||||||
|
|
||||||
|
$markdown = str_replace("array (\n)", '[]', $markdown);
|
||||||
|
|
||||||
$content = file_get_contents(__DIR__ . '/../README.stub');
|
$content = file_get_contents(__DIR__ . '/../README.stub');
|
||||||
|
|
||||||
$content = str_replace('<!-- GENERATED-DOCS -->', $markdown, $content);
|
$content = str_replace('<!-- GENERATED-DOCS -->', $markdown, $content);
|
||||||
|
|||||||
@@ -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';
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
|||||||
|
|
||||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author René Preuß <rene@preuss.io>
|
||||||
|
*/
|
||||||
trait Delete
|
trait Delete
|
||||||
{
|
{
|
||||||
|
|
||||||
abstract public function delete(string $path = '', array $parameters = [], Paginator $paginator = null);
|
abstract public function delete(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
|||||||
|
|
||||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author René Preuß <rene@preuss.io>
|
||||||
|
*/
|
||||||
trait Get
|
trait Get
|
||||||
{
|
{
|
||||||
|
|
||||||
abstract public function get(string $path = '', array $parameters = [], Paginator $paginator = null);
|
abstract public function get(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
|||||||
|
|
||||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author René Preuß <rene@preuss.io>
|
||||||
|
*/
|
||||||
trait Post
|
trait Post
|
||||||
{
|
{
|
||||||
|
|
||||||
abstract public function post(string $path = '', array $parameters = [], Paginator $paginator = null);
|
abstract public function post(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations;
|
|||||||
|
|
||||||
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
use GhostZero\BitinflowAccounts\Helpers\Paginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author René Preuß <rene@preuss.io>
|
||||||
|
*/
|
||||||
trait Put
|
trait Put
|
||||||
{
|
{
|
||||||
|
|
||||||
abstract public function put(string $path = '', array $parameters = [], Paginator $paginator = null);
|
abstract public function put(string $path = '', array $parameters = [], Paginator $paginator = null);
|
||||||
}
|
}
|
||||||
@@ -17,8 +17,10 @@ use GuzzleHttp\Exception\RequestException;
|
|||||||
class BitinflowAccounts
|
class BitinflowAccounts
|
||||||
{
|
{
|
||||||
|
|
||||||
use Traits\UsersTrait;
|
use Traits\ChargesTrait;
|
||||||
|
use Traits\CheckoutSessionsTrait;
|
||||||
use Traits\SshKeysTrait;
|
use Traits\SshKeysTrait;
|
||||||
|
use Traits\UsersTrait;
|
||||||
|
|
||||||
const BASE_URI = 'https://accounts.bitinflow.com/api/';
|
const BASE_URI = 'https://accounts.bitinflow.com/api/';
|
||||||
const OAUTH_BASE_URI = 'https://accounts.bitinflow.com/api/';
|
const OAUTH_BASE_URI = 'https://accounts.bitinflow.com/api/';
|
||||||
38
src/GhostZero/BitinflowAccounts/Enums/Scope.php
Normal file
38
src/GhostZero/BitinflowAccounts/Enums/Scope.php
Normal file
@@ -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';
|
||||||
|
}
|
||||||
@@ -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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
src/GhostZero/BitinflowAccounts/Socialite/Provider.php
Normal file
89
src/GhostZero/BitinflowAccounts/Socialite/Provider.php
Normal file
@@ -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',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
69
src/GhostZero/BitinflowAccounts/Traits/ChargesTrait.php
Normal file
69
src/GhostZero/BitinflowAccounts/Traits/ChargesTrait.php
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ trait SshKeysTrait
|
|||||||
return $this->post('ssh-keys', [
|
return $this->post('ssh-keys', [
|
||||||
'public_key' => $publicKey,
|
'public_key' => $publicKey,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
], null);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +51,6 @@ trait SshKeysTrait
|
|||||||
*/
|
*/
|
||||||
public function deleteSshKey(int $id): Result
|
public function deleteSshKey(int $id): Result
|
||||||
{
|
{
|
||||||
return $this->delete("ssh-keys/$id", [], null);
|
return $this->delete("ssh-keys/$id", []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user