diff --git a/README.md b/README.md index 2e715b8..e42f53e 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,10 @@ PHP bitinflow Accounts API Client for Laravel 5+ ## Table of contents 1. [Installation](#installation) -2. [Configuration](#configuration) -3. [Examples](#examples) -4. [Documentation](#documentation) +2. [Event Listener](#event-listener) +3. [Configuration](#configuration) +4. [Examples](#examples) +5. [Documentation](#documentation) 6. [Development](#Development) ## Installation @@ -28,6 +29,28 @@ Add Service Provider to your `app.php` configuration file: 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 Copy configuration to config folder: @@ -44,6 +67,18 @@ BITINFLOW_ACCOUNTS_SECRET= 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 #### Basic @@ -114,10 +149,20 @@ BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedU ## Documentation -### Users +### Charges ```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 @@ -128,7 +173,13 @@ public function createSshKey(string $publicKey, string $name = NULL) 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 diff --git a/README.stub b/README.stub index 4d433c0..167870d 100644 --- a/README.stub +++ b/README.stub @@ -28,6 +28,28 @@ Add Service Provider to your `app.php` configuration file: 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 Copy configuration to config folder: @@ -44,6 +66,18 @@ BITINFLOW_ACCOUNTS_SECRET= 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 #### Basic @@ -116,7 +150,7 @@ BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedU -[**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 diff --git a/composer.json b/composer.json index 8621d70..7469fe0 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,11 @@ ], "require": { "php": ">=7.2", + "ext-json": "*", "illuminate/support": "^5.5", "illuminate/console": "^5.5", - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3", + "socialiteproviders/manager": "^3.4" }, "require-dev": { "phpunit/phpunit": "^8.0", @@ -21,12 +23,12 @@ }, "autoload": { "psr-4": { - "GhostZero\\BitinflowAccounts\\": "src" + "GhostZero\\BitinflowAccounts\\": "src/GhostZero/BitinflowAccounts" } }, "autoload-dev": { "psr-4": { - "GhostZero\\BitinflowAccounts\\Tests\\": "tests" + "GhostZero\\BitinflowAccounts\\Tests\\": "tests/GhostZero/BitinflowAccounts" } }, "scripts": { diff --git a/composer.lock b/composer.lock index 033db11..ea18296 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "d862392957845962bdb82aeb0ee836fe", + "content-hash": "d05b61cfebf348cc424dbf01ec508a51", "packages": [ { "name": "doctrine/inflector", @@ -627,6 +627,70 @@ ], "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", "version": "1.0.55", @@ -711,6 +775,69 @@ ], "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", "version": "1.24.0", @@ -1328,6 +1455,63 @@ ], "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", "version": "v6.2.1", @@ -4810,7 +4994,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2" + "php": ">=7.2", + "ext-json": "*" }, "platform-dev": [] } diff --git a/generator/generate-docs.php b/generator/generate-docs.php index 05ad1c7..cc40a13 100644 --- a/generator/generate-docs.php +++ b/generator/generate-docs.php @@ -76,6 +76,8 @@ $markdown = collect(class_uses(BitinflowAccounts::class)) return $markdown; })->join(PHP_EOL . PHP_EOL); +$markdown = str_replace("array (\n)", '[]', $markdown); + $content = file_get_contents(__DIR__ . '/../README.stub'); $content = str_replace('', $markdown, $content); diff --git a/src/Enums/Scope.php b/src/Enums/Scope.php deleted file mode 100644 index f298fc7..0000000 --- a/src/Enums/Scope.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ -class Scope -{ - - /* - * v0 API - */ - - // Deprecated scope. - const API = 'api'; - - // Read nonpublic user information, including email address. - const READ_USER = 'read_user'; -} \ No newline at end of file diff --git a/src/ApiOperations/Delete.php b/src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php similarity index 84% rename from src/ApiOperations/Delete.php rename to src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php index 02ed22b..68d7393 100644 --- a/src/ApiOperations/Delete.php +++ b/src/GhostZero/BitinflowAccounts/ApiOperations/Delete.php @@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations; use GhostZero\BitinflowAccounts\Helpers\Paginator; +/** + * @author René Preuß + */ trait Delete { + abstract public function delete(string $path = '', array $parameters = [], Paginator $paginator = null); } \ No newline at end of file diff --git a/src/ApiOperations/Get.php b/src/GhostZero/BitinflowAccounts/ApiOperations/Get.php similarity index 83% rename from src/ApiOperations/Get.php rename to src/GhostZero/BitinflowAccounts/ApiOperations/Get.php index 6a09439..6816961 100644 --- a/src/ApiOperations/Get.php +++ b/src/GhostZero/BitinflowAccounts/ApiOperations/Get.php @@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations; use GhostZero\BitinflowAccounts\Helpers\Paginator; +/** + * @author René Preuß + */ trait Get { + abstract public function get(string $path = '', array $parameters = [], Paginator $paginator = null); } \ No newline at end of file diff --git a/src/ApiOperations/Post.php b/src/GhostZero/BitinflowAccounts/ApiOperations/Post.php similarity index 83% rename from src/ApiOperations/Post.php rename to src/GhostZero/BitinflowAccounts/ApiOperations/Post.php index 51d4593..56c4c35 100644 --- a/src/ApiOperations/Post.php +++ b/src/GhostZero/BitinflowAccounts/ApiOperations/Post.php @@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations; use GhostZero\BitinflowAccounts\Helpers\Paginator; +/** + * @author René Preuß + */ trait Post { + abstract public function post(string $path = '', array $parameters = [], Paginator $paginator = null); } \ No newline at end of file diff --git a/src/ApiOperations/Put.php b/src/GhostZero/BitinflowAccounts/ApiOperations/Put.php similarity index 83% rename from src/ApiOperations/Put.php rename to src/GhostZero/BitinflowAccounts/ApiOperations/Put.php index fcbaa4b..03fc532 100644 --- a/src/ApiOperations/Put.php +++ b/src/GhostZero/BitinflowAccounts/ApiOperations/Put.php @@ -6,7 +6,11 @@ namespace GhostZero\BitinflowAccounts\ApiOperations; use GhostZero\BitinflowAccounts\Helpers\Paginator; +/** + * @author René Preuß + */ trait Put { + abstract public function put(string $path = '', array $parameters = [], Paginator $paginator = null); } \ No newline at end of file diff --git a/src/BitinflowAccounts.php b/src/GhostZero/BitinflowAccounts/BitinflowAccounts.php similarity index 99% rename from src/BitinflowAccounts.php rename to src/GhostZero/BitinflowAccounts/BitinflowAccounts.php index 8891298..43de378 100644 --- a/src/BitinflowAccounts.php +++ b/src/GhostZero/BitinflowAccounts/BitinflowAccounts.php @@ -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/'; diff --git a/src/GhostZero/BitinflowAccounts/Enums/Scope.php b/src/GhostZero/BitinflowAccounts/Enums/Scope.php new file mode 100644 index 0000000..0329c89 --- /dev/null +++ b/src/GhostZero/BitinflowAccounts/Enums/Scope.php @@ -0,0 +1,38 @@ + + */ +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'; +} \ No newline at end of file diff --git a/src/Exceptions/RateLimitException.php b/src/GhostZero/BitinflowAccounts/Exceptions/RateLimitException.php similarity index 100% rename from src/Exceptions/RateLimitException.php rename to src/GhostZero/BitinflowAccounts/Exceptions/RateLimitException.php diff --git a/src/Exceptions/RequestRequiresAuthenticationException.php b/src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresAuthenticationException.php similarity index 100% rename from src/Exceptions/RequestRequiresAuthenticationException.php rename to src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresAuthenticationException.php diff --git a/src/Exceptions/RequestRequiresClientIdException.php b/src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresClientIdException.php similarity index 100% rename from src/Exceptions/RequestRequiresClientIdException.php rename to src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresClientIdException.php diff --git a/src/Exceptions/RequestRequiresParameter.php b/src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresParameter.php similarity index 100% rename from src/Exceptions/RequestRequiresParameter.php rename to src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresParameter.php diff --git a/src/Exceptions/RequestRequiresRedirectUriException.php b/src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresRedirectUriException.php similarity index 100% rename from src/Exceptions/RequestRequiresRedirectUriException.php rename to src/GhostZero/BitinflowAccounts/Exceptions/RequestRequiresRedirectUriException.php diff --git a/src/Facades/BitinflowAccounts.php b/src/GhostZero/BitinflowAccounts/Facades/BitinflowAccounts.php similarity index 100% rename from src/Facades/BitinflowAccounts.php rename to src/GhostZero/BitinflowAccounts/Facades/BitinflowAccounts.php diff --git a/src/Helpers/Paginator.php b/src/GhostZero/BitinflowAccounts/Helpers/Paginator.php similarity index 100% rename from src/Helpers/Paginator.php rename to src/GhostZero/BitinflowAccounts/Helpers/Paginator.php diff --git a/src/Providers/BitinflowAccountsServiceProvider.php b/src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsServiceProvider.php similarity index 100% rename from src/Providers/BitinflowAccountsServiceProvider.php rename to src/GhostZero/BitinflowAccounts/Providers/BitinflowAccountsServiceProvider.php diff --git a/src/Result.php b/src/GhostZero/BitinflowAccounts/Result.php similarity index 100% rename from src/Result.php rename to src/GhostZero/BitinflowAccounts/Result.php diff --git a/src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php b/src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php new file mode 100644 index 0000000..f050e89 --- /dev/null +++ b/src/GhostZero/BitinflowAccounts/Socialite/BitinflowExtendSocialite.php @@ -0,0 +1,24 @@ + + */ +class BitinflowExtendSocialite +{ + + /** + * Register the provider. + * + * @param SocialiteWasCalled $socialiteWasCalled + */ + public function handle(SocialiteWasCalled $socialiteWasCalled) + { + $socialiteWasCalled->extendSocialite( + 'bitinflow-accounts', __NAMESPACE__ . '\Provider' + ); + } +} \ No newline at end of file diff --git a/src/GhostZero/BitinflowAccounts/Socialite/Provider.php b/src/GhostZero/BitinflowAccounts/Socialite/Provider.php new file mode 100644 index 0000000..4294e5f --- /dev/null +++ b/src/GhostZero/BitinflowAccounts/Socialite/Provider.php @@ -0,0 +1,89 @@ + + */ +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', + ]); + } +} \ No newline at end of file diff --git a/src/GhostZero/BitinflowAccounts/Traits/ChargesTrait.php b/src/GhostZero/BitinflowAccounts/Traits/ChargesTrait.php new file mode 100644 index 0000000..eb5a31e --- /dev/null +++ b/src/GhostZero/BitinflowAccounts/Traits/ChargesTrait.php @@ -0,0 +1,69 @@ + + */ +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); + } +} \ No newline at end of file diff --git a/src/GhostZero/BitinflowAccounts/Traits/CheckoutSessionsTrait.php b/src/GhostZero/BitinflowAccounts/Traits/CheckoutSessionsTrait.php new file mode 100644 index 0000000..bd1dfbb --- /dev/null +++ b/src/GhostZero/BitinflowAccounts/Traits/CheckoutSessionsTrait.php @@ -0,0 +1,42 @@ + + */ +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); + } +} \ No newline at end of file diff --git a/src/Traits/SshKeysTrait.php b/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php similarity index 94% rename from src/Traits/SshKeysTrait.php rename to src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php index cccecb0..eda731a 100644 --- a/src/Traits/SshKeysTrait.php +++ b/src/GhostZero/BitinflowAccounts/Traits/SshKeysTrait.php @@ -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", []); } } \ No newline at end of file diff --git a/src/Traits/UsersTrait.php b/src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php similarity index 100% rename from src/Traits/UsersTrait.php rename to src/GhostZero/BitinflowAccounts/Traits/UsersTrait.php diff --git a/tests/ApiSshKeysTest.php b/tests/GhostZero/BitinflowAccounts/ApiSshKeysTest.php similarity index 100% rename from tests/ApiSshKeysTest.php rename to tests/GhostZero/BitinflowAccounts/ApiSshKeysTest.php diff --git a/tests/ApiUsersTest.php b/tests/GhostZero/BitinflowAccounts/ApiUsersTest.php similarity index 100% rename from tests/ApiUsersTest.php rename to tests/GhostZero/BitinflowAccounts/ApiUsersTest.php diff --git a/tests/ServiceInstantiationTest.php b/tests/GhostZero/BitinflowAccounts/ServiceInstantiationTest.php similarity index 100% rename from tests/ServiceInstantiationTest.php rename to tests/GhostZero/BitinflowAccounts/ServiceInstantiationTest.php diff --git a/tests/TestCases/ApiTestCase.php b/tests/GhostZero/BitinflowAccounts/TestCases/ApiTestCase.php similarity index 100% rename from tests/TestCases/ApiTestCase.php rename to tests/GhostZero/BitinflowAccounts/TestCases/ApiTestCase.php diff --git a/tests/TestCases/TestCase.php b/tests/GhostZero/BitinflowAccounts/TestCases/TestCase.php similarity index 100% rename from tests/TestCases/TestCase.php rename to tests/GhostZero/BitinflowAccounts/TestCases/TestCase.php