承接 invoiceninja/sdk-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

invoiceninja/sdk-php

Composer 安装命令:

composer require invoiceninja/sdk-php

包简介

The Invoice Ninja v5 PHP SDK

README 文档

README

Installation

Add the Invoice Ninja SDK

composer require invoiceninja/sdk-php

Setup

use InvoiceNinja\Sdk\InvoiceNinja;
   
$ninja = new InvoiceNinja("your_token");
$invoices = $ninja->invoices->all();
  • To connect to a self hosted version use ->setUrl() on the $ninja object.

Supports

  • Clients
  • Invoices
  • Quotes
  • Products
  • Payments
  • TaxRates
  • Statics
  • Expenses
  • Expense Categories
  • Recurring Invoices
  • Credits
  • Projects
  • Tasks
  • Vendors
  • Companies
  • Subscriptions
  • Purchase Orders
  • Bank Integrations
  • Bank Transactions

Retrieving Models

Retrieve all clients

    $clients = $ninja->clients->all();

You can perform complex filtering on the ->all() method.

Query parameters can be chained together to form complex queries. The current supported values are:

per_page: The number of clients per page you want returned
page: The page number
include: A comma separated list of relations to include ie. contacts,documents,gateway_tokens
balance: A query to return clients with a balance using an operator and value

  • ie ?balance=lt:10 Returns clients with a balance less than 10
  • available operators lt, lte, gt, gte, eq

between_balance: Returns clients with a balance between two values

  • ie ?between_balance=10:20 - Returns clients with a balance between 10 and 20

email: Returns clients with a contacts.email field equal to an email
id_number: Search by id_number
number: Search by number
filter: Search across multiple columns (name, id_number, first_name, last_name, email, custom_value1, custom_value2, custom_value3, custom_value4)
created_at: Search by created at (Unix timestamp)
is_deleted: Search using is_deleted boolean flag

For example,

$clients = $ninja->clients->all([
    'balance' => 'lt:10', // get all clients with a balance less than 10
    'per_page' => 10, // return 10 results per page
    'page' => 2, // paginate to page 2
    'include' => 'documents', // include the documents relationship
]);

Retrieve a client by its primary key.

    $client = $ninja->clients->get("CLIENT_HASHED_ID");

Retrieving an invoice by it's number:

    $client = $ninja->invoices->all(['number' => '0001']);

Inserting & Updating Models

Create a new client

    $client = $ninja->clients->create(['name' => 'A new client']);

Create a new Client with a contact

    $clients = $ninja->clients->create([
        'name' => 'Brand spanking new client',
        'contacts' => [
            [
                'first_name' => 'first',
                'last_name' => 'last',
                'send_email' => true,
                'email' => 'gi-joe@example.com',
            ],

        ]
    ]);
    

Update an existing client

    $client = $ninja->clients->update("CLIENT_HASHED_ID",['name' => 'A client with a updated name']);

Please Note

When updating a client, you must always include the current contacts (array), if no contacts are included, the system will wipe the contacts from the client record.

Create an invoice

    $invoice = $ninja->invoices->create([
        'client_id' => $client_hashed_id,
        'date' => '2022-10-31',
        'due_date' => '2022-12-01',
        'terms' => 'These are your invoice terms.',
        'footer' => 'Invoice footer text',
        'line_items' => [
            [
                'product_key' => 'some_product_key',
                'notes' => 'description',
                'quantity' => 1,
                'cost' => 10
            ],
            [                
                'product_key' => 'another_product_key',
                'notes' => 'description',
                'quantity' => 1,
                'cost' => 10
            ],
        ],
    ]);

When creating an invoice, you can perform actions on the invoice in a single call, for example, say you wish to create an invoice and also apply a payment to the invoice:

    $invoice = $ninja->invoices->create([
        'client_id' => $client_hashed_id,
        'date' => '2022-10-31',
        'due_date' => '2022-12-01',
        'terms' => 'These are your invoice terms.',
        'footer' => 'Invoice footer text',
        'line_items' => [
            [
                'product_key' => 'some_product_key',
                'notes' => 'description',
                'quantity' => 1,
                'cost' => 10
            ],
            [                
                'product_key' => 'another_product_key',
                'notes' => 'description',
                'quantity' => 1,
                'cost' => 10
            ],
        ],
    ], 
    ['paid' => true] //the second parameter in this method is an array of actions ie paid,mark_sent_send_email,auto_bill
);

Or if you wish to apply a partial payment

    $invoice = $ninja->invoices->create(['client_id'=> 'CLIENT_HASHED_ID'], ['amount_paid' => 10]);

Or you may want to automatically send and charge the invoice note requires a payment method on file

    $invoice = $ninja->invoices->create(['client_id'=> 'CLIENT_HASHED_ID'], ['auto_bill' => true, 'send_email' => true]);

Bulk actions

You can perform bulk actions against one or many entities. For example if you wish to batch archive a range of invoice you would do

  $bulk = $ninja->invoices->archive(["hash_1","hash_2"]);

You can access the raw bulk method using the following:

$bulk = $ninja->invoices->bulk("archive", ["hash_1","hash_2"]);

If you wanted to download a invoice PDF

    $pdf = $ninja->invoices->bulk("download", ["hash_1"]);

The following are a list of available bulk actions for invoices:

  • mark_sent
  • download
  • restore
  • archive
  • delete
  • paid
  • clone_to_quote
  • clone_to_invoice
  • cancel
  • reverse
  • email

For more examples of what can be achieved with the SDK, please inspect the tests folder in this repository. If you need clarity or more explicit examples of how to use the SDK, please create a issue.

invoiceninja/sdk-php 适用场景与选型建议

invoiceninja/sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56.8k 次下载、GitHub Stars 达 87, 最近一次更新时间为 2016 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 invoiceninja/sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 invoiceninja/sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 invoiceninja/sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 56.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 87
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 87
  • Watchers: 8
  • Forks: 40
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-13