diff --git a/composer.json b/composer.json index bf82135..c956a6b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "hotmeteor/phinch-laravel", + "name": "getclair/phinch-laravel", "description": "Laravel package for Finch API SDK", "type": "library", "license": "MIT", @@ -12,14 +12,14 @@ "authors": [ { "name": "Adam Campbell", - "email": "adam@hotmeteor.com" + "email": "adam@getclair.com" } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "ext-json": "*", - "hotmeteor/phinch": "dev-main", - "illuminate/support": "^7.0|^8.0" + "getclair/phinch": "^0.1.0", + "illuminate/support": "^8.0|^9.0" }, "require-dev": { "nunomaduro/collision": "^5.1", @@ -28,12 +28,12 @@ }, "autoload": { "psr-4": { - "Phinch\\": "src" + "Phinch\\Phinch\\": "src/" } }, "autoload-dev": { "psr-4": { - "Phinch\\Tests\\": "tests/" + "Phinch\\Phinch\\Tests\\": "tests/" } }, "scripts": { @@ -42,10 +42,11 @@ "extra": { "laravel": { "providers": [ - "Phinch\\PhinchServiceProvider" + "Phinch\\Phinch\\PhinchServiceProvider" ], "aliases": { - "Phinch": "Phinch\\Facade" + "Phinch": "Phinch\\Phinch\\Facades\\Phinch", + "Connect": "Phinch\\Phinch\\Facades\\Connect" } } }, diff --git a/config/phinch.php b/config/phinch.php index 364d66a..77947a8 100644 --- a/config/phinch.php +++ b/config/phinch.php @@ -1,6 +1,7 @@ env('PHINCH_API_VERSION', '2020-09-17'), + 'api_version' => env('FINCH_API_VERSION', '2020-09-17'), + + /* + |-------------------------------------------------------------------------- + | Environment + |-------------------------------------------------------------------------- + | + | Here you may specify if the app is in Sandbox mode. + | + */ + + 'sandbox' => env('FINCH_SANDBOX_MODE', false), ]; diff --git a/src/ConnectFactory.php b/src/ConnectFactory.php new file mode 100644 index 0000000..8e20972 --- /dev/null +++ b/src/ConnectFactory.php @@ -0,0 +1,38 @@ +inSandbox(); + } + + return $connect; + } + +} \ No newline at end of file diff --git a/src/Facade.php b/src/Facade.php deleted file mode 100644 index 9d6c5fc..0000000 --- a/src/Facade.php +++ /dev/null @@ -1,22 +0,0 @@ -redirectUrl()); + } + + /** + * @return string + * @throws BindingResolutionException + */ + public static function token(): string + { + $instance = static::getFacadeRoot(); + + return $instance->exchange( + static::$app->make('request')->input('code') + ); + } +} diff --git a/src/Facades/Phinch.php b/src/Facades/Phinch.php new file mode 100644 index 0000000..c50b255 --- /dev/null +++ b/src/Facades/Phinch.php @@ -0,0 +1,20 @@ +mergeConfig(); - $this->app->singleton(Finch::class, function ($app) { - return new Finch( - new FinchClient( - config('services.finch.client_id'), - config('services.finch.client_secret'), - config('phinch.api_version'), - config('services.finch.redirect_url'), - ) + $this->app->singleton(Phinch::class, function ($app) { + return new Phinch( + new PhinchClient(config('phinch.api_version')) ); }); + + $this->app->singleton(Connect::class, function ($app) { + return ConnectFactory::make( + config('services.finch'), + config('phinch.sandbox') + ); + }); + + $this->app->alias(Phinch::class, 'phinch'); + $this->app->alias(Connect::class, 'phinch.connect'); } protected function mergeConfig() { - $configPath = __DIR__.'/../config/phinch.php'; + $configPath = __DIR__ . '/../config/phinch.php'; $this->mergeConfigFrom($configPath, 'phinch'); } protected function publishConfig() { - $configPath = __DIR__.'/../config/phinch.php'; + $configPath = __DIR__ . '/../config/phinch.php'; $this->publishes([$configPath => config_path('phinch.php')], 'config'); }