audunru/fiken-api-php-client

此包已被废弃且不再维护。未建议替代包。

连接到Fiken API

v3.0.0 2024-04-07 10:00 UTC

README

Coverage Status StyleCI

2024更新:Fiken已发布其API的v2版本。请直接使用此API。此包仅适用于现在已废弃的v1 API。

Fiken.no是一个针对小型企业的在线会计系统,旨在使会计变得简单。

您可以使用此包从Fiken检索资源(公司、产品、账户等),或创建新资源(例如客户或产品)。您还可以创建发票和现金销售。

您可以使用Fiken API的演示账户免费使用,否则按公司每月收取费用。

Fiken API官方文档

我并不为Fiken工作。

一句提醒

请先在Fiken中创建一个演示账户(免费),在将此包集成到您的项目中并使用它之前使用该账户。在连接到Fiken API之前,此包几乎不进行任何检查,因此您很容易犯错并在Fiken中创建错误数据。

安装

composer require audunru/fiken-api-php-client

使用方法

测试认证

use audunru\FikenClient\FikenClient;

$client = new FikenClient();

// The Fiken API uses basic authentication
// According to their documentation, you should create a separate user for accessing the API
$client->authenticate('username', 'password');

// $user is a User object
$user = $client->user();

echo $user->name; // Art Vandelay

公司

use audunru\FikenClient\FikenClient;

$client = new FikenClient();
$client->authenticate('username', 'password');

// $companies is a Collection, so you can use Laravel Collection methods to filter or get etc.
// See https://laravel.net.cn/docs/5.8/collections
$companies = $client->companies();
$company = $companies->first();

echo $company->name; // Vandelay Industries

属于公司的银行账户、产品和其他资源。

要获取这些资源,您首先需要获取一个公司。

use audunru\FikenClient\FikenClient;

$client = new FikenClient();
$client->authenticate('username', 'password');

// $company is a Company object
$company = $client->setCompany('123456789'); // 123456789 is the organization number

echo $company->name; // Vandelay Industries

// These are all collections, so the Laravel Collection methods can be used on them
$bankAccounts = $company->bankAccounts();
$products = $company->products();
$contacts = $company->contacts();
$accounts = $company->accounts(2019); // To get accounts, you need to set a year

// $product is a Product object
$product = $products->firstWhere('name', 'Latex');

创建客户

use audunru\FikenClient\FikenClient;
use audunru\FikenClient\Models\Contact;

$client = new FikenClient();
$client->authenticate('username', 'password');

$company = $client->setCompany('123456789');

$customer = new Contact(['name' => 'Kel Varnsen', 'customer' => true]);

// $saved is a new FikenCustomer object
$saved = $company->add($customer);

创建发票

use audunru\FikenClient\FikenClient;
use audunru\FikenClient\Models\Invoice;
use audunru\FikenClient\Models\InvoiceLine;

$client = new FikenClient();
$client->authenticate('username', 'password');

$company = $client->setCompany('123456789');

// Create a new invoice object
$invoice = new Invoice(['issueDate' => '2019-01-01', 'dueDate' => '2019-01-15']);

// Find an existing customer of this company and set it on the invoice
$customer = $company->contacts()->firstWhere('name', 'Kel Varnsen');
$invoice->setCustomer($customer);

// Find a bank account and set it on the invoice
$bankAccount = $company->bankAccounts()->firstWhere('number', '12341234999');
$invoice->setBankAccount($bankAccount);

// Set invoice text
$invoice->invoiceText = 'Payment for import and export services';

// Find a product
$product = $company->products()->firstWhere('name', 'Chips');

// Create a new invoice line
$line = new InvoiceLine(['netAmount' => 8000, 'vatAmount' => 2000, 'grossAmount' => 10000]);
// Set product on the invoice line
$line->setProduct($product);

// Add the invoice line to the invoice
$invoice->add($line);

// Add the invoice to the company
$saved = $company->add($invoice);
// $saved is a new Invoice object

开发

测试

复制.env文件,然后打开它并设置您的变量

cp .env.example .env.testing

运行测试

composer test

目录tests\Feature中的测试连接到Fiken API。在运行这些测试之前,您必须在文件.env.testing中设置用户名、密码和组织编号。

警告:在Fiken中创建一个虚拟账户并使用该账户运行您的测试,否则测试将在您的Fiken账户中生成假数据!

连接到Fiken API的测试必须使用以下命令运行

composer test -- --group dangerous

运行测试并生成覆盖率报告

composer test-with-coverage
php vendor/bin/php-coveralls