Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hotmeteor committed Sep 3, 2022
1 parent 7d704f1 commit 0170bb2
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 45 deletions.
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hotmeteor/phinch-laravel",
"name": "getclair/phinch-laravel",
"description": "Laravel package for Finch API SDK",
"type": "library",
"license": "MIT",
Expand All @@ -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",
Expand All @@ -28,12 +28,12 @@
},
"autoload": {
"psr-4": {
"Phinch\\": "src"
"Phinch\\Phinch\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phinch\\Tests\\": "tests/"
"Phinch\\Phinch\\Tests\\": "tests/"
}
},
"scripts": {
Expand All @@ -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"
}
}
},
Expand Down
14 changes: 13 additions & 1 deletion config/phinch.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default API Version
Expand All @@ -10,6 +11,17 @@
|
*/

'api_version' => 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),

];
38 changes: 38 additions & 0 deletions src/ConnectFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Phinch\Phinch;

use Illuminate\Contracts\Container\Container;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use Phinch\Connect\Connect;
use Phinch\Phinch;

class ConnectFactory
{
/**
* @param array $config
* @param bool $sandbox
* @return Connect
*/
public static function make(array $config, bool $sandbox = false): Connect
{
if (!Str::startsWith($redirect = $config['connect_redirect'], 'http')) {
$redirect = URL::to($redirect);
}

$connect = new Connect(
$config['client_id'],
$config['client_secret'],
$redirect,
);

if ($sandbox) {
$connect->inSandbox();
}

return $connect;
}

}
22 changes: 0 additions & 22 deletions src/Facade.php

This file was deleted.

49 changes: 49 additions & 0 deletions src/Facades/Connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Phinch\Phinch\Facades;

use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Facade as BaseFacade;

class Connect extends BaseFacade
{
/**
* @method static string redirectUrl()
* @method static string exchange($code)
* @method static \Phinch\Connect\Connect products(array $products)
* @method static \Phinch\Connect\Connect state(mixed $value)
* @method static \Phinch\Connect\Connect payrollProvider(string $provider)
* @method static \Phinch\Connect\Connect inSandbox()
*
* @see \Phinch\Connect\Connect
*/
protected static function getFacadeAccessor()
{
return 'phinch.connect';
}

/**
* @return RedirectResponse
*/
public static function redirect(): RedirectResponse
{
$instance = static::getFacadeRoot();

return new RedirectResponse($instance->redirectUrl());
}

/**
* @return string
* @throws BindingResolutionException
*/
public static function token(): string
{
$instance = static::getFacadeRoot();

return $instance->exchange(
static::$app->make('request')->input('code')
);
}
}
20 changes: 20 additions & 0 deletions src/Facades/Phinch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Phinch\Phinch\Facades;

use Illuminate\Support\Facades\Facade as BaseFacade;

class Phinch extends BaseFacade
{
/**
* @method array providers()
* @method array introspect(string $token)
* @method array disconnect(string $token)
*
* @see \Phinch\Phinch
*/
protected static function getFacadeAccessor()
{
return 'phinch';
}
}
32 changes: 19 additions & 13 deletions src/PhinchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace Phinch;
namespace Phinch\Phinch;

use Illuminate\Support\ServiceProvider;
use Phinch\Finch\Finch;
use Phinch\Finch\FinchClient;
use Phinch\Connect\Connect;
use Phinch\Phinch;
use Phinch\PhinchClient;

class PhinchServiceProvider extends ServiceProvider
{
Expand All @@ -17,28 +18,33 @@ public function register()
{
$this->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');
}
Expand Down

0 comments on commit 0170bb2

Please sign in to comment.