nivv / fortnox-laravel
启用简单的Fortnox集成
Requires
- guzzlehttp/guzzle: ~6.0
- sabre/xml: ^1.2
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2024-08-29 04:54:07 UTC
README
Fortnox Laravel (来自 wetcat-studios/fortie 的分支)
这是一个简单的 Fortnox PHP 包,包括 Laravel Service Provider 以便于在 Laravel 中集成。
来自 wetcat-studios/fortie 的分支
安装
安装此包的最简单方法是使用 Composer。
composer require nivv/fortnox-laravel dev-master
或者将 "nivv/fortnox-laravel": "dev-master"
添加到您的 composer.json
文件中。
如果您没有 Composer,您应该 安装它。
配置
在 Laravel 中,您可以通过位于 config/fortie.php
的发布配置文件来更改配置,它应该看起来像以下内容。用 Fortnox 在您注册时提供的详细信息填写此内容。
在注册时不会提供访问令牌,您需要使用您的 Auth Code 和 Client Secret 分别获取它。有关此过程的更多信息,请参阅 此处。
<?php return [ 'default' => [ // Your specific access token 'access_token' => '<your access token>', // Your specific client secret 'client_secret' => '<your client secret>', // The type you're sending 'content_type' => 'application/json', // The type you're accepting as response 'accepts' => 'application/json', // The URL to the Fortnox API 'endpoint' => 'https://api.fortnox.se/3/', ], ];
请注意,XML 尚未完全支持,该包可以读取并尝试将 Fortnox 的响应转换为 XML 结构,但在向 Fortnox 发送数据时,它将始终以 json 格式发送。
使用方法
Laravel
在 Laravel 中,使用 Fortie 的最简单方法是添加 ServiceProvider,在 config/app.php
中将以下行添加到 providers
数组。
<?php return [ ... 'providers' => [ ... Nivv\Fortie\FortieServiceProvider::class, ], ... ];
添加 ServiceProvider 后,您可以在您的 BaseController 中使用依赖注入,使 fortie 可用于所有控制器。
abstract class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; protected $fortie; public function __construct(Fortie $fortie) { $this->fortie = $fortie; } }
只需调用 $this->fortie->...
来访问 Fortie。
class MyController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { dd($this->fortie->accounts()->listAllAccounts()); } ... }
当然,您也可以将 Fortie 注入任何 Laravel 控制器方法,以限制应用程序对 Fortnox 的访问。
use Nivv\Fortie\Fortie as Fortie; class MyController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Fortie $fortie) { dd($fortie->accounts()->listAllAccounts()); } ... }
非 Laravel
在 Laravel 中,ServiceProvider 负责使用配置文件设置 Fortie,如果在外部使用 Laravel,则需要使用 Fortnox 提供的配置来实例化 Fortie。
$fortie = new Fortie( $endpoint, $access_token, $client_secret, $content_type, $accepts );
访问令牌
要获取访问令牌(用于您的集成),您需要使用 authroization-code
请求它。
在 Laravel 中,您可以使用 Artisan 命令轻松获取访问令牌。
php artisan fortie:activate code=<your authorization code>
提供商
该包配置了多个提供商,每个提供商都映射到 REST API 中的特定端点。例如,accounts 映射到 accounts() 方法。
$arrayOfAccounts = $fortie->accounts()->all();
有关所有提供商的用法详细信息,请参阅 Wiki。
当前已实现的提供商
- 账户
- 存档
- 文章
- 公司设置
- 合同
- 货币
- 客户
- 发票
- 报价
- 订单
- 价格列表
- 价格
- 项目
- 供应商
- 单位
- 收据
尚未实现
- 文章文件连接
- 文章 URL 连接
- 合同摊销
- 合同模板
- 成本中心
- 财务年度
- 收件箱
- 发票摊销
- 发票付款
- 锁定期间
- 支付方式
- 打印模板
- 供应商发票摊销
- 供应商发票外部URL连接
- 供应商发票文件连接
- 供应商发票付款
- 供应商发票
- 税收减免
- 交货条款
- 付款条款
- 凭证文件连接
- 凭证系列
- 交货方式
依赖关系
此软件包是用以下依赖项构建的。
许可证
版权所有2015 安德烈亚斯·戈兰松
根据Apache许可证第2版(“许可证”)许可;除非适用法律要求或书面同意,否则不得使用此文件,除非遵守许可证。您可以在以下位置获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“现状”分发,不提供任何明示或暗示的保证或条件。有关许可证下权限和限制的具体语言,请参阅许可证。