webparking / laravel-visma
Laravel API 辅助工具,用于 Visma eAccounting
2.0.0
2021-04-19 07:29 UTC
Requires
- php: ^7.3
- ext-json: *
- laravel/framework: ^5.5 || ^6.0 || ^7.0 || ^8.0
- league/oauth2-client: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.18
This package is auto-updated.
Last update: 2023-10-10 12:00:14 UTC
README
此工具仅帮助您设置 eAccounting API(https://eaccountingapi.vismaonline.com/swagger/ui/index)的 oAuth 连接,并提供一些简单的包装以使生活更轻松。
安装
composer require webparking/laravel-visma
用法
准备工作
- 注册您的应用 https://selfservice.developer.vismaonline.com/
- 设置 .env 变量(参见 config/visma.php)
1. 创建初始同意的重定向 URL
/** @var Client $client */
$client = app()->make(Client::class)->connect();
return redirect()->away($client->getAuthorizationUrl());
2. 使用接收到的令牌生成访问和刷新令牌
$authorizationCode = ''; // Received through request
/** @var Client $client */
$client = app()->make(Client::class)->connect();
/** @var AccessTokenInterface $tokens */
$tokens = $client->getAccessToken($authorizationCode);
// Store those for future requests
$accessToken = $tokens->getToken();
$refeshToken = $tokens->getRefreshToken();
基本请求准备
/** @var VismaClient $client */
$client = app()->make(VismaClient::class)->connect();
/** @var AccessTokenInterface $tokens */
$tokens = $client->getNewRefreshToken($refeshToken);
// Store those for future requests
$accessToken = $tokens->getToken();
$refeshToken = $tokens->getRefreshToken();
$client->setToken($accessToken);
示例请求
// Get all accounts
$accounts = (new Account($client)->index();
// Get accountBalances at certain date
$balances = (new AccountBalance($client)->index(Carbon::now());
// Get accountBalances at certain date for specific account
$balances = (new AccountBalance($client)->index(Carbon::now(), '4001');
注意
这是一个为 Visma eAccounting API 设计的最小化助手,仅涵盖我们所需要的内容。请随意改进它。
许可证和 Postcardware
此软件为开源,并使用 MIT 许可证。
如果您在日常开发中使用此软件,我们希望收到您家乡的明信片。
请寄至:Webparking BV,Cypresbaan 31a,2908 LT Capelle aan den IJssel,荷兰