byrontudhope / xerolaravel
此包的最新版本(v1.0.9)没有可用的许可信息。
Laravel 5 对 Xero 的 PHP API 的包装
v1.0.9
2016-05-06 08:42 UTC
Requires
- calcinai/xero-php: ^1.2
This package is not auto-updated.
Last update: 2024-09-20 21:17:11 UTC
README
calcinai/xero-php(用于与 Xero 集成的自定义 API)的 Laravel 5 包装器。
通过 Composer 安装
要求安装此包
composer require byrontudhope/xerolaravel "1.0.*"
发布配置文件
php artisan vendor:publish
这将创建一个位于您的 config
目录下的 xero/config.php
文件。(注意:请确保您已生成必要的令牌,并已生成 Xero 所需的 RSA 密钥进行身份验证。)编辑 config.php
文件中的相关值。
确保 RSA 密钥的位置与所需的格式 (file://absolutepath)
相匹配
将服务提供者添加到您的 config/app.php
中的 providers
'ByronTudhope\XeroLaravel\Providers\XeroServiceProvider',
**在 config/app.php
中的 aliases
下注册 Facades
'XeroPrivate'=> 'ByronTudhope\XeroLaravel\Facades\XeroPrivate',
依赖关系和需求
此服务提供者当前包装了 calcinai/xero-php 版本 1.1.* 包。
此外,您必须安装以下 PHP 扩展
- php_curl (7.30+)
- php_openssl
使用方法
使用类有两种方式:通过 IoC 容器或通过 Facade。它们都提供相同的功能,因此根据您的偏好选择使用。
获取所有发票
Facade
$invoices = XeroPrivate::load('Accounting\\Invoice')->execute();
IoC 容器
// Create an instance of the class, resolved out of the IoC container
$xero = $this->app->make('XeroPrivate');
$invoices = $xero->load('Accounting\\Invoice')->execute();
通过 GUID 或发票号获取单个发票
Facade
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);
IoC 容器
$xero = $this->app->make('XeroPrivate');
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);
更新现有发票
Facade
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);
$invoice->setStatus('Paid');
XeroPrivate::save($invoice);
IoC 容器
$xero = $this->app->make('XeroPrivate');
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);
$invoice->setStatus('Paid');
$xero->save($invoice);
创建新的发票
/*
* Resolve instances of Xero, XeroInvoice, XeroContact
* and XeroInvoiceLine out of the IoC container.
*/
$xero = $this->app->make('XeroPrivate');
$invoice = $this->app->make('XeroInvoice');
$contact = $this->app->make('XeroContact');
$line1 = $this->app->make('XeroInvoiceLine');
$line2 = $this->app->make('XeroInvoiceLine');
// Set up the invoice contact
$contact->setAccountNumber('DMA01');
$contact->setContactStatus('ACTIVE');
$contact->setName('Amo Chohan');
$contact->setFirstName('Amo');
$contact->setLastName('Chohan');
$contact->setEmailAddress('amo.chohan@gmail.com');
$contact->setDefaultCurrency('GBP');
// Assign the contact to the invoice
$invoice->setContact($contact);
// Set the type of invoice being created (ACCREC / ACCPAY)
$invoice->setType('ACCREC');
$dateInstance = new DateTime();
$invoice->setDate($dateInstance);
$invoice->setDueDate($dateInstance);
$invoice->setInvoiceNumber('DMA-00001');
$invoice->setReference('DMA-00001');
// Provide an URL which can be linked to from Xero to view the full order
$invoice->setUrl('http://yourdomain/fullpathtotheorder');
$invoice->setCurrencyCode('GBP');
$invoice->setStatus('Draft');
// Create some order lines
$line1->setDescription('Blue tshirt');
$line1->setQuantity(1);
$line1->setUnitAmount(99.99);
$line1->setTaxAmount(0);
$line1->setLineAmount(99.99);
$line1->setDiscountRate(0); // Percentage
// Add the line to the order
$invoice->addLineItem($line1);
// Repeat for all lines...
$xero->save($invoice);
创建附件
$xero = $this->app->make('XeroPrivate');
$attachment = $this->app->make('XeroAttachment')
->createFromLocalFile(storage_path('your_file.pdf'));
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'AMO-00002');
$invoice->addAttachment($attachment);