iamfredric / fortnox
Fortnox API 集成
0.0.5
2022-04-04 07:24 UTC
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
README
此包是 Fortnox API 的封装。
要求
php ^8.0 Fortnox 开发者账户 https://developer.fortnox.se/
安装
composer reqiure "iamfredric/fortnox"
配置
\Iamfredric\Fortnox\Fortnox::setClientCredentials( clientId: 'your-app-client-id', clientSecret: 'your-app-client-secret', redirectUrl: 'http://your-app-url/fortnox/callback', scope: 'your scopes separated by spaces' );
用户认证
// Redirect user to Fortnox for authentication $url = \Iamfredric\Fortnox\Fortnox::authUrl(); // In your response handler, when fortnox redirects user back to your app, $response = \Iamfredric\Fortnox\Fortnox::verifyAuthCode($_GET['code']); $response['access_token']; $response['refresh_token']; $response['scope']; $response['expires_in']; $response['token_type'];
资源操作
在您可以使用资源之前,您需要认证用户。
// You need to pass an object that implements \Iamfredric\Fortnox\Contracts\Authenticatable // to the authenticateAs method. This object will be used to get the access token and refresh // your access token when it expires. \Iamfredric\Fortnox\Fortnox::authenticateAs(new class implements \Iamfredric\Fortnox\Contracts\Authenticatable { public function getFortnoxAccessToken(): string { return 'your-access-token'; } public function getFortnoxRefreshToken(): string { return 'your-refresh-token'; } public function getFortnoxExpiresAt(): DateTime { return new DateTime('Expiration date for token'); } public function onFortnoxUpdate($data): void { // Update your database with the new access token and refresh token } });
获取所有客户
use \Iamfredric\Fortnox\Resources\Customer; $customers = Customer::all() foreach ($customers as $customer) { /** @var $customer Customer */ }
获取客户
use \Iamfredric\Fortnox\Resources\Customer; $customer = Customer::find(1);
创建客户
use \Iamfredric\Fortnox\Resources\Customer; $customer = Customer::create([ 'Name' => 'Acme INC' ]);
更新客户
use \Iamfredric\Fortnox\Resources\Customer; $customer = Customer::find(1); // Or $customer = new Customer([ "CustomerNumber" => "1", ]) $customer->update([ 'Name' => 'Acme INC'; ]) // Or $customer->Name = 'Acme INC'; $customer->save();
删除客户
use \Iamfredric\Fortnox\Resources\Customer; $customer = Customer::find(1); $customer->delete();
扩展现有包
class Order extends \Iamfredric\Fortnox\Resources\Resource { protected function getIdKey(): string { return 'DocumentNumber'; } } Order::all(); $order = Order::find(1); $order->update([]); $order->save(); $order->delete();
测试
composer run test
composer run analyze
composer run sniff
贡献
贡献
欢迎贡献。
流程
在提交问题之前
- 尝试复现问题,以确保这不是一个偶然事件。
- 检查您的功能建议是否已在项目中存在。
- 检查拉取请求选项卡,以确保该错误没有正在进行的修复工作。
- 检查拉取请求选项卡,以确保该功能尚未开始。
在提交拉取请求之前
- 检查代码库,确保您的功能尚未存在。
- 检查拉取请求,确保其他人尚未提交该功能或修复。
要求
如果项目维护者有其他要求,您将在此找到它们。
-
PSR-2 编码标准 - 应用约定的最简单方法是为安装 PHP Code Sniffer。
-
添加测试! - 如果您的补丁没有测试,则不会接受。
-
记录行为变化 - 确保将
README.md
和任何其他相关文档保持最新。 -
每个功能一个拉取请求 - 如果您想做更多的事情,请发送多个拉取请求。
-
发送连贯的历史记录 - 确保您的拉取请求中的每个单独提交都有意义。如果您在开发过程中必须做出多个中间提交,请在提交之前 压缩它们。
快乐的编码!
许可
MIT 许可证 (MIT)。
特此授予任何获得此软件及其相关文档副本(“软件”)的人免费使用软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向提供软件的人授予上述权利,但须遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他方式,由此软件或其使用或其它交易而产生。