Skip to content

Commit

Permalink
Merge pull request #1 from theimerj/master
Browse files Browse the repository at this point in the history
Update and refactor
  • Loading branch information
dominik-wbz authored Jun 23, 2020
2 parents e3ce94d + 59a16dc commit b997290
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 139 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
composer.lock
build
vendor
.DS_Store
tests/TestSupport/temp
tests/temp
composer.lock
phpunit.xml
.env
.phpunit.result.cache
.php_cs.cache
86 changes: 33 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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 <your@email.cz>',
'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 <your@email.cz>'),
];
```

Expand All @@ -70,35 +48,37 @@ return [
```php

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');
}
} catch (Exception $e) {
dd($e->getCode() . ": " . $e->getMessage());
// 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());
}

```

## License

Copyright (c) 2019 webiz eu s.r.o MIT Licensed.
Copyright (c) 2019 - 2020 webiz eu s.r.o MIT Licensed.
83 changes: 64 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
{
"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",
"fakturoid/fakturoid-php": "^1.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"
}
}
}
}
8 changes: 8 additions & 0 deletions config/fakturoid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'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 <your@email.cz>'),
];
10 changes: 7 additions & 3 deletions src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';}
}
protected static function getFacadeAccessor()
{
return 'laravel-fakturoid';
}
}
52 changes: 28 additions & 24 deletions src/FakturoidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
59 changes: 28 additions & 31 deletions src/LaravelFakturoid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,32 @@

namespace WEBIZ\LaravelFakturoid;

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;
}

use Fakturoid\Client as FakturoidClient;

class LaravelFakturoid
{
protected FakturoidClient $fakturoid;

public function __construct()
{
$this->fakturoid = new FakturoidClient(
config('fakturoid.account_name'),
config('fakturoid.account_email'),
config('fakturoid.account_api_key'),
config('fakturoid.app_contact')
);
}

public function __call($method, $arguments)
{
if (method_exists($this, $method)) {
return $this->{$method}(...$arguments);
}

if (method_exists($this->fakturoid, $method)) {
return $this->fakturoid->{$method}(...$arguments);
}

throw new \BadMethodCallException("Method '{$method}' does not exist on Fakturoid instance.");
}
}
7 changes: 0 additions & 7 deletions src/config.php

This file was deleted.

0 comments on commit b997290

Please sign in to comment.