gyvex-com/maakeenfactuur-laravel

Laravel 包,用于轻松连接 MaakEenFactuur.nl

v1.1.0 2024-06-08 10:35 UTC

README

📜 概述
MaakEenFactuur-Laravel 是一个 PHP 库,它提供了简化接口来通过我们的 API 管理客户和发票。它包括两个主要的外层封装:CustomerInvoice,它们由强大的服务类支持,负责与 API 的所有交互。

功能

  • 客户管理:轻松检索、创建和管理客户信息。
  • 发票处理:轻松创建、更新和获取发票。
  • 异常处理:强大的错误管理,以便优雅地处理 API 响应。

安装

要在您的项目中使用 Gyvex MaakEenFactuur,请通过 Composer 需求它

composer require gyvex-com/maakeenfactuur-laravel

配置

该包的 ApiService 处理 API 密钥。设置您的 API 密钥以验证请求。

默认情况下,它将从配置文件 config/maakeenfactuur.php 中加载,可以通过运行以下命令导出:

php artisan vendor:publish --tag="maakeenfactuur-config"

这将添加默认的 .env 变量 MAAKEENFACTUUR_API_KEY,可以设置

MAAKEENFACTUUR_API_KEY="YOUR_API_KEY"

使用

管理客户

use Gyvex\MaakEenFactuur\Facades\Customer;

// Fetch all customers
$customers = Customer::all();

// Create a new customer
$newCustomer = Customer::create(['name' => 'John Doe', 'email' => 'john@example.com']);

// Find a specific customer
$customer = Customer::find(1);

处理发票

use Gyvex\MaakEenFactuur\Facades\Invoice;

// Create an invoice
$newInvoice = Invoice::create(['customer_id' => 1, 'amount' => 100.00]);

// Update an existing invoice
$updatedInvoice = Invoice::update(1, ['amount' => 150.00]);

// Fetch all invoices
$invoices = Invoice::all();

// Find a specific invoice
$invoice = Invoice::find(1);

处理 API 错误

如果 API 请求失败,CustomerInvoice 服务都会抛出 ApiErrorException,这允许您在应用程序中优雅地处理错误。

try {
    $invoice = Invoice::find(1);
} catch (Gyvex\MaakEenFactuur\Exception\ApiErrorException $e) {
    // Handle error
    echo 'Error: ' . $e->getMessage();
}

贡献

欢迎贡献!如果您有任何建议或发现任何错误,请随时提交拉取请求或创建一个问题。

许可

本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE.md 文件。

此 README 结构旨在提供对如何使用库的全面介绍和指南,包括安装说明、使用示例和基本错误处理。根据您的实际项目结构和要求调整详细信息。