From 7eaf68c905e1c15355d65849f0081fd7ed8c4672 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:03:35 +0200 Subject: [PATCH 01/13] move config and add env variables --- config/config.php | 8 ++++++++ src/config.php | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 config/config.php delete mode 100644 src/config.php diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..cd3bba1 --- /dev/null +++ b/config/config.php @@ -0,0 +1,8 @@ + env('FAKTUROID_NAME', 'XXX'), + 'account_email' => env('FAKTUROID_EMAIL', 'XXX'), + 'account_api_key' => env('FAKTUROID_API_KEY', 'XXX'), + 'app_contact' => env('FAKTUROID_APP_CONTACT', 'Application '), +]; diff --git a/src/config.php b/src/config.php deleted file mode 100644 index fb07924..0000000 --- a/src/config.php +++ /dev/null @@ -1,7 +0,0 @@ - 'XXX', - 'account_email' => 'XXX', - 'account_api_key' => 'XXX', - 'app_contact' => 'PHPlib ', -]; \ No newline at end of file From 468176cbae181c879104701dfad0defb415f692d Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:03:47 +0200 Subject: [PATCH 02/13] make it work with L7 --- composer.json | 82 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index f4b4246..e8eb560 100644 --- a/composer.json +++ b/composer.json @@ -1,20 +1,64 @@ { - "name": "dominik-wbz/laravel-fakturoid", - "license": "MIT", - "authors": [ - { - "name": "Dominik Nguyen", - "email": "dom@webiz.cz" - } - ], - "require": { - "php": ">=5.6.0", - "illuminate/support": "5.*", - "fakturoid/fakturoid-php": "^1.0" - }, - "autoload": { - "psr-4": { - "WEBIZ\\LaravelFakturoid\\": "src/" - } - } -} + "name": "dominik-wbz/laravel-fakturoid", + "description": "Fakturoid Laravel Wrapper", + "keywords": [ + "webiz", + "laravel", + "ecommerce", + "invoicing" + ], + "homepage": "https://github.com/dominik-wbz/laravel-fakturoid", + "license": "MIT", + "type": "library", + "authors": [ + { + "name": "Dominik Nguyen", + "email": "dom@webiz.cz", + "role": "Developer" + }, + { + "name": "Jakub Theimer", + "email": "theimer@madne.st", + "role": "Developer" + } + ], + "require": { + "php": ">=7.2.0", + "laravel/framework": "^7.0", + "illuminate/support": "^6.18|^7.0", + }, + "require-dev": { + "mockery/mockery": "^1.3", + "orchestra/testbench": "^5.1", + "phpunit/phpunit": "^8.0|^9.0" + }, + "autoload": { + "psr-4": { + "WEBIZ\\LaravelFakturoid\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "WEBIZ\\LaravelFakturoid\\Tests\\": "tests" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "test": "vendor/bin/phpunit", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + }, + "config": { + "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "WEBIZ\\LaravelFakturoid\\FakturoidServiceProvider" + ], + "aliases": { + "Fakturoid": "WEBIZ\\LaravelFakturoid\\Facade" + } + } + } +} \ No newline at end of file From 6c57e8f8a6100201e3110a0243cb6dca895b44e1 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:04:14 +0200 Subject: [PATCH 03/13] indent with 4 spaces --- src/LaravelFakturoid.php | 60 +++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/LaravelFakturoid.php b/src/LaravelFakturoid.php index cc0fdd3..1826b35 100644 --- a/src/LaravelFakturoid.php +++ b/src/LaravelFakturoid.php @@ -4,33 +4,35 @@ use Fakturoid; -class LaravelFakturoid { - - public function __construct() { - $this->config = [ - 'account_name' => config('fakturoid.account_name'), - 'account_email' => config('fakturoid.account_email'), - 'account_api_key' => config('fakturoid.account_api_key'), - 'app_contact' => config('fakturoid.app_contact'), - ]; - $this->initFakturoid(); - } - - protected function initFakturoid() { - $this->fakturoid = new Fakturoid\Client($this->config['account_name'], $this->config['account_email'], $this->config['account_api_key'], $this->config['app_contact']); - - return $this->fakturoid; - } - - public function __call($name, $arguments) { - if (method_exists($this, $name)) { - return $this->{$name}(...$arguments); - } else if (method_exists($this->fakturoid, $name)) { - $fakturoid = $this->fakturoid; - $methodResult = $fakturoid->{$name}(...$arguments); - return $methodResult; - } - return null; - } - +class LaravelFakturoid +{ + public function __construct() + { + $this->config = [ + 'account_name' => config('fakturoid.account_name'), + 'account_email' => config('fakturoid.account_email'), + 'account_api_key' => config('fakturoid.account_api_key'), + 'app_contact' => config('fakturoid.app_contact'), + ]; + $this->initFakturoid(); + } + + protected function initFakturoid() + { + $this->fakturoid = new Fakturoid\Client($this->config['account_name'], $this->config['account_email'], $this->config['account_api_key'], $this->config['app_contact']); + + return $this->fakturoid; + } + + public function __call($name, $arguments) + { + if (method_exists($this, $name)) { + return $this->{$name}(...$arguments); + } else if (method_exists($this->fakturoid, $name)) { + $fakturoid = $this->fakturoid; + $methodResult = $fakturoid->{$name}(...$arguments); + return $methodResult; + } + return null; + } } From 52140d12389fa3874ffe2e96ec3a238a86e0bcc5 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:04:26 +0200 Subject: [PATCH 04/13] edit facade accessor --- src/Facade.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Facade.php b/src/Facade.php index 7d2bb09..1139abf 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -4,11 +4,15 @@ use Illuminate\Support\Facades\Facade as LaravelFacade; -class Facade extends LaravelFacade { +class Facade extends LaravelFacade +{ /** * Get the registered name of the component. * * @return string */ - protected static function getFacadeAccessor() {return 'Fakturoid';} -} \ No newline at end of file + protected static function getFacadeAccessor() + { + return 'laravel-fakturoid'; + } +} From a0e0a091257a871c3cefd59e2463c51c0df2b8bf Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:04:50 +0200 Subject: [PATCH 05/13] edit gitignore --- .gitignore | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 97896f7..0e5cbaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ -composer.lock +build vendor -.DS_Store \ No newline at end of file +tests/TestSupport/temp +tests/temp +composer.lock +phpunit.xml +.env +.phpunit.result.cache +.php_cs.cache \ No newline at end of file From 1bd8e750a1147d30c6b633b5bb3c1b8f34a8e436 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:05:18 +0200 Subject: [PATCH 06/13] fix trailing comma --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e8eb560..8407600 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require": { "php": ">=7.2.0", "laravel/framework": "^7.0", - "illuminate/support": "^6.18|^7.0", + "illuminate/support": "^6.18|^7.0" }, "require-dev": { "mockery/mockery": "^1.3", From 946a2c28e46b66dbf1fae49db982d9fd84bbc07a Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:10:31 +0200 Subject: [PATCH 07/13] rename config --- config/{config.php => fakturoid.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename config/{config.php => fakturoid.php} (100%) diff --git a/config/config.php b/config/fakturoid.php similarity index 100% rename from config/config.php rename to config/fakturoid.php From bc5c1198bf979a96aeda0f8d0989c31b004ce421 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:10:40 +0200 Subject: [PATCH 08/13] set up for autoregistering package --- src/FakturoidServiceProvider.php | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/FakturoidServiceProvider.php b/src/FakturoidServiceProvider.php index 3aa56ba..5f07612 100644 --- a/src/FakturoidServiceProvider.php +++ b/src/FakturoidServiceProvider.php @@ -5,29 +5,33 @@ use Illuminate\Support\ServiceProvider; use WEBIZ\LaravelFakturoid\LaravelFakturoid; -class FakturoidServiceProvider extends ServiceProvider { - /** - * Bootstrap services. - * - * @return void - */ - public function boot() { - $this->publishes([ - __DIR__ . '/config.php' => config_path('fakturoid.php'), - ]); - } +class FakturoidServiceProvider extends ServiceProvider +{ + /** + * Bootstrap the application services. + */ + public function boot() + { + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__ . '/../config/fakturoid.php' => config_path('fakturoid.php'), + ], 'config'); + } + } - /** - * Register services. - * - * @return void - */ - public function register() { - if (is_dir($vendor = __DIR__ . '/../vendor')) { - require_once $vendor . '/autoload.php'; - } - $this->app->singleton('Fakturoid', function ($app) { - return new LaravelFakturoid(); - }); - } + /** + * Register services. + * + * @return void + */ + public function register() + { + // Automatically apply the package configuration + $this->mergeConfigFrom(__DIR__ . '/../config/fakturoid.php', 'fakturoid'); + + // Register the main class to use with the facade + $this->app->singleton('laravel-fakturoid', function () { + return new LaravelFakturoid; + }); + } } From 2dfc1b6c882001a67d5541de36fb2c3a3f483348 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:10:47 +0200 Subject: [PATCH 09/13] edit readme --- README.md | 83 +++++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 6331ecf..b2aeed7 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Simple wrapper for official php package https://github.com/fakturoid/fakturoid-p ### Docs -- [Installation](#installation) -- [Configuration](#configuration) -- [Examples](#examples) +- [Installation](#installation) +- [Configuration](#configuration) +- [Examples](#examples) ## Installation @@ -20,28 +20,6 @@ composer require dominik-wbz/laravel-fakturoid This will both update composer.json and install the package into the vendor/ directory. -Next, add the service provider and facade to `config/app.php` - -Add the service provider to providers: - -``` -'providers' => [ - ... - WEBIZ\LaravelFakturoid\FakturoidServiceProvider::class, - ... -] -``` - -And add the facade to aliases: - -``` -'aliases' => [ - ... - 'Fakturoid' => WEBIZ\LaravelFakturoid\Facade::class, - ... -] -``` - ### Step 2: Configuration First initialise the config file by running this command: @@ -56,10 +34,10 @@ With this command, initialize the configuration and modify the created file, loc ```php return [ - 'account_name' => 'XXX', - 'account_email' => 'XXX', - 'account_api_key' => 'XXX', - 'app_contact' => 'PHPlib ', + 'account_name' => env('FAKTUROID_NAME', 'XXX'), + 'account_email' => env('FAKTUROID_EMAIL', 'XXX'), + 'account_api_key' => env('FAKTUROID_API_KEY', 'XXX'), + 'app_contact' => env('FAKTUROID_APP_CONTACT', 'Application '), ]; ``` @@ -73,32 +51,35 @@ use Fakturoid; use Fakturoid\Exception; try { - // create subject - $subject = Fakturoid::createSubject(array( - 'name' => 'Firma s.r.o.', - 'email' => 'aloha@pokus.cz' - )); - if ($subject->getBody()) { - $subject = $subject->getBody(); - - // create invoice with lines - $lines = array(array( - 'name' => 'Big sale', - 'quantity' => 1, - 'unit_price' => 1000 - )); - $invoice = Fakturoid::createInvoice(array('subject_id' => $subject->id, 'lines' => $lines)); - $invoice = $invoice->getBody(); - - // send created invoice - Fakturoid::fireInvoice($invoice->id, 'deliver'); - } + // create subject + $subject = Fakturoid::createSubject(array( + 'name' => 'Firma s.r.o.', + 'email' => 'aloha@pokus.cz' + )); + if ($subject->getBody()) { + $subject = $subject->getBody(); + + // create invoice with lines + $lines = [ + [ + 'name' => 'Big sale', + 'quantity' => 1, + 'unit_price' => 1000 + ], + ]; + + $invoice = Fakturoid::createInvoice(array('subject_id' => $subject->id, 'lines' => $lines)); + $invoice = $invoice->getBody(); + + // send created invoice + Fakturoid::fireInvoice($invoice->id, 'deliver'); + } } catch (Exception $e) { - dd($e->getCode() . ": " . $e->getMessage()); + dd($e->getCode() . ": " . $e->getMessage()); } ``` ## License -Copyright (c) 2019 webiz eu s.r.o MIT Licensed. +Copyright (c) 2019 - 2020 webiz eu s.r.o MIT Licensed. From 537a604a6fda436637dd1b49cb0fb356e0603073 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:12:48 +0200 Subject: [PATCH 10/13] update readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b2aeed7..7f7bf99 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ return [ ```php use Fakturoid; -use Fakturoid\Exception; try { // create subject @@ -74,7 +73,7 @@ try { // send created invoice Fakturoid::fireInvoice($invoice->id, 'deliver'); } -} catch (Exception $e) { +} catch (\Exception $e) { dd($e->getCode() . ": " . $e->getMessage()); } From 2148e4d0c9475c40170880b11db7131372ce332d Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:14:29 +0200 Subject: [PATCH 11/13] remove ugly else if --- src/LaravelFakturoid.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/LaravelFakturoid.php b/src/LaravelFakturoid.php index 1826b35..2d7c261 100644 --- a/src/LaravelFakturoid.php +++ b/src/LaravelFakturoid.php @@ -28,11 +28,14 @@ public function __call($name, $arguments) { if (method_exists($this, $name)) { return $this->{$name}(...$arguments); - } else if (method_exists($this->fakturoid, $name)) { + } + + if (method_exists($this->fakturoid, $name)) { $fakturoid = $this->fakturoid; $methodResult = $fakturoid->{$name}(...$arguments); return $methodResult; } + return null; } } From 64b04d799b3a562d4a61a86cfe4695fd67dee9b1 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:14:35 +0200 Subject: [PATCH 12/13] edit composer --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8407600..8a5e848 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "require": { "php": ">=7.2.0", "laravel/framework": "^7.0", - "illuminate/support": "^6.18|^7.0" + "illuminate/support": "^6.18|^7.0", + "fakturoid/fakturoid-php": "^1.0" }, "require-dev": { "mockery/mockery": "^1.3", From 59a16dc64b6f2bdf65299a992d11f4f4e2850c99 Mon Sep 17 00:00:00 2001 From: Jakub Theimer Date: Tue, 23 Jun 2020 20:20:34 +0200 Subject: [PATCH 13/13] refactor --- src/LaravelFakturoid.php | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/LaravelFakturoid.php b/src/LaravelFakturoid.php index 2d7c261..ee1f4bd 100644 --- a/src/LaravelFakturoid.php +++ b/src/LaravelFakturoid.php @@ -2,40 +2,32 @@ namespace WEBIZ\LaravelFakturoid; -use Fakturoid; +use Fakturoid\Client as FakturoidClient; class LaravelFakturoid { - public function __construct() - { - $this->config = [ - 'account_name' => config('fakturoid.account_name'), - 'account_email' => config('fakturoid.account_email'), - 'account_api_key' => config('fakturoid.account_api_key'), - 'app_contact' => config('fakturoid.app_contact'), - ]; - $this->initFakturoid(); - } + protected FakturoidClient $fakturoid; - protected function initFakturoid() + public function __construct() { - $this->fakturoid = new Fakturoid\Client($this->config['account_name'], $this->config['account_email'], $this->config['account_api_key'], $this->config['app_contact']); - - return $this->fakturoid; + $this->fakturoid = new FakturoidClient( + config('fakturoid.account_name'), + config('fakturoid.account_email'), + config('fakturoid.account_api_key'), + config('fakturoid.app_contact') + ); } - public function __call($name, $arguments) + public function __call($method, $arguments) { - if (method_exists($this, $name)) { - return $this->{$name}(...$arguments); + if (method_exists($this, $method)) { + return $this->{$method}(...$arguments); } - if (method_exists($this->fakturoid, $name)) { - $fakturoid = $this->fakturoid; - $methodResult = $fakturoid->{$name}(...$arguments); - return $methodResult; + if (method_exists($this->fakturoid, $method)) { + return $this->fakturoid->{$method}(...$arguments); } - return null; + throw new \BadMethodCallException("Method '{$method}' does not exist on Fakturoid instance."); } }