budgetinvoice/easyinvoice

用于Budget Invoice发票创建API的包装器包。

3.0.2 2024-01-31 16:26 UTC

This package is auto-updated.

Last update: 2024-09-30 01:52:29 UTC


README

由以下产品提供

Easy Invoice logo

为Web和后端构建 💪


Version Coverage Status
Downloads License Pull Request's Welcome

如果您觉得这个包对您有帮助,请在Github上为我们点个星!
非常感谢!

Pull Request's Welcome

重要

  1. 请注意,此包是API的包装器,因此其逻辑运行在外部服务器上。
  2. 您的数据安全,不会与第三方共享。
  3. 我们尽力使API始终可用,但不能保证100%的在线时间。请为API维护时出现故障的情况构建重试机制。

安装

使用composer

$ composer require budgetinvoice/easyinvoice

示例

Easy Invoice Sample Logo Only Easy Invoice Sample With Background

上述示例使用的JSON配置

注意:由于这些示例是JSON格式的,在使用时请勿忘记将其转换为PHP表示法。

演示

PHPSandbox Notebook

计划


使用付费

  1. 通过以下方式注册
  2. 通过应用中的设置 -> API密钥创建API密钥
  3. 如下完整示例所示,使用API Key。将apiKey属性添加到数据对象中。

注意:虽然GUI(尚未)完全翻译成英语,但获取apiKey的路径应该主要是英语。此外,这还将允许您使用应用内购买机制来支付订阅费。

开发模式

在免费版中,您可以将模式设置为'development',以确保在测试此包或开发发票时不会遇到速率限制。免费版每15天限制为25张发票。当您的发票看起来不错时,您可以将模式切换到'production'以创建生产发票。生产模式可以通过不设置模式或设置模式为'production'来激活。

直接REST API访问

如果您不想使用pip包,但想直接调用我们的发票创建API。

# HTTPS POST 
https://api.budgetinvoice.com/v2/free/invoices

# POST Data
Format: JSON
Structure: {
  "data": { # Parent parameter must be 'data'
    "mode": "development", # Production or development, defaults to production
    "products": [
      {
        "quantity": 2,
        "description": "Test product",
        "taxRate": 6,
        "price": 33.87
      }
    ],
  }
} 

# Optionally add your paid apiKey to the header 
Header: "Authorization": "Bearer 123abc" # Please register to receive a production apiKey: https://app.budgetinvoice.com/register

入门 - 基本示例

require __DIR__ . '/vendor/autoload.php';

use BudgetInvoice\EasyInvoice

// Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "product": [
        "quantity" => 2,
        "description" => "Product 1",
        "tax-rate" => 6,
        "price" => 33.87
    ]
];

// Sample code to test the library
$invoice = EasyInvoice::create($invoiceData);

// The invoice['pdf'] variable wil contain a base64 PDF string
echo $invoice['pdf'];

// Save the file locally as PDF
$fileName = 'invoice';
EasyInvoice::save($invoice['pdf'], $fileName);

高容量:异步发票创建

我们的API能够处理大量的请求。如果您需要快速创建大量发票,请确保异步创建它们。这将允许您同时创建多个发票。

完整示例

require __DIR__ . '/vendor/autoload.php';

use BudgetInvoice\EasyInvoice

//Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production    
    "images" => [
        // The logo on top of your invoice
        "logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
        // The invoice background
        "background" => "https://public.easyinvoice.cloud/img/watermark-draft.jpg"
    ],
    // Your own data
    "sender" => [
        "company" => "Sample Corp",
        "address" => "Sample Street 123",
        "zip" => "1234 AB",
        "city" => "Sampletown",
        "country" => "Samplecountry"
        //"custom1" => "custom value 1",
        //"custom2" => "custom value 2",
        //"custom3" => "custom value 3"
    ],
    // Your recipient
    "client" => [
        "company" => "Client Corp",
        "address" => "Clientstreet 456",
        "zip" => "4567 CD",
        "city" => "Clientcity",
        "country" => "Clientcountry"
        // "custom1" => "custom value 1",
        // "custom2" => "custom value 2",
        // "custom3" => "custom value 3"
    ],
    "information" => [
        // Invoice number
        "number" => "2021.0001",
        // Invoice data
        "date" => "12-12-2021",
        // Invoice due date
        "dueDate" => "31-12-2021"
    ],
    // The products you would like to see on your invoice
    // Total values are being calculated automatically
    "products" => [
        [
            "quantity" => 2,
            "description" => "Product 1",
            "taxRate" => 6,
            "price" => 33.87
        ],
        [
            "quantity" => 4.1,
            "description" => "Product 2",
            "taxRate" => 6,
            "price" => 12.34
        ],
        [
            "quantity" => 4.5678,
            "description" => "Product 3",
            "taxRate" => 21,
            "price" => 6324.453456
        ]
    ],
    // The message you would like to display on the bottom of your invoice
    "bottomNotice" => "Kindly pay your invoice within 15 days.",
    // Settings to customize your invoice
    "settings" => [
        "currency" => "USD", // See documentation 'Locales and Currency' for more info. Leave empty for no currency.
        // "locale" => "nl-NL", // Defaults to en-US, used for number formatting (See documentation 'Locales and Currency')        
        // "marginTop" => 25, // Defaults to '25'
        // "marginRight" => 25, // Defaults to '25'
        // "marginLeft" => 25, // Defaults to '25'
        // "marginBottom" => 25, // Defaults to '25'
        // "format" => "A4", // Defaults to A4, options => A3, A4, A5, Legal, Letter, Tabloid
        // "height" => "1000px", // allowed units: mm, cm, in, px
        // "width" => "500px", // allowed units: mm, cm, in, px
        // "orientation" => "landscape" // portrait or landscape, defaults to portrait
    ],
    // Translate your invoice to your preferred language
    "translate" => [
        // "invoice" => "FACTUUR",  // Default to 'INVOICE'
        // "number" => "Nummer", // Defaults to 'Number'
        // "date" => "Datum", // Default to 'Date'
        // "dueDate" => "Verloopdatum", // Defaults to 'Due Date'
        // "subtotal" => "Subtotaal", // Defaults to 'Subtotal'
        // "products" => "Producten", // Defaults to 'Products'
        // "quantity" => "Aantal", // Default to 'Quantity'
        // "price" => "Prijs", // Defaults to 'Price'
        // "productTotal" => "Totaal", // Defaults to 'Total'
        // "total" => "Totaal" // Defaults to 'Total',
        // "taxNotation" => "btw", // Defaults to 'vat'
    ],
    
    // Customize enables you to provide your own templates
    // Please review the documentation for instructions and examples
    //    "customize" => [
        //  "template" => base64_encode("<p>Hello World</p>"); // Must be base64 encoded html 
    //    ],
];

//Sample code to test the library
$invoice = EasyInvoice::create($invoiceData);

//The invoice object wil contain a base64 PDF string
echo $invoice['pdf'];

// Save the file locally as PDF
$fileName = 'invoice';
EasyInvoice::save($invoice['pdf'], $fileName);

返回值

错误处理

require __DIR__ . '/vendor/autoload.php';

use BudgetInvoice\EasyInvoice

// Set the data you wish to see on your invoice
$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "product": [
        "quantity" => 2,
        "description" => "Product 1",
        "tax-rate" => 6,
        "price" => 33.87
    ]
];

try {
   // Sample code to test the library
   $invoice = EasyInvoice::create($invoiceData);
   
   // The invoice['pdf'] variable wil contain a base64 PDF string
   echo $invoice['pdf'];
   
   // Save the file locally as PDF
   $fileName = 'invoice';
   EasyInvoice::save($invoice['pdf'], $fileName);
} catch (Exception $e){
    echo $e->getMessage();
}

地区和货币

用于数字格式化和货币符号

//E.g. for Germany, prices would look like 123.456,78 €
$data = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "settings" => [
        "locale" => "de-DE", 
        "currency" => "EUR"
    ]
];

//E.g. for US, prices would look like $123,456.78
$data = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "settings" => [
        "locale" => "en-US",
        "currency" => "USD"
    ]
];

格式化和符号通过ECMAScript国际化API应用

点击此处查看地区代码列表
点击此处查看货币代码列表

免责声明:上述列表中可能不是所有地区和货币代码都由ECMAScript国际化API支持。

标志和背景

标志和url输入接受URL或base64编码的文件。

支持的文件类型

  • 标志:图像
  • 背景:图片,PDF

URL

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "images" => [
        "logo" => "https://public.easyinvoice.cloud/img/logo_en_original.png",
        "background" => "https://public.easyinvoice.cloud/img/watermark_draft.jpg"
    ]
];

Base64

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    //Note: Sample base64 string
    //Please use the link below to convert your image to base64
    "images":[  
        "logo" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
        "background" => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
    ] 
];

点击此处获取在线工具,将图片转换为Base64

模板定制

下载我们的默认模板(invoice-v2),以获取可定制的示例:这里

支持的文件类型

  • Base64
  • URL(即将推出)
// You are able to provide your own html template
$html = "<p>Hello world! This is invoice number %number%</p>";

$invoiceData = [
    "apiKey" => "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
    "mode" => "development", // Production or development, defaults to production
    "customize" => [
        "template" => base64_encode($html) // Your template must be base64 encoded
    ],
    "information" => [
        "number" => "2022.0001"
    ]
];

$invoice = EasyInvoice::create($invoiceData);
// This will return a pdf with the following content
// Hello world! This is invoice number 2022.0001

变量占位符

以下占位符可以放入您的模板中。创建时,它们将被相应的值替换。