adman9000 / laravel-xero
此包的最新版本(v2.2)没有可用的许可信息。
用于Xero PHP API的Laravel 5包装器,由drawmyattention/xerolaravel派生。
v2.2
2020-11-22 16:04 UTC
Requires
- calcinai/xero-php: ^2.2
README
Xero会计API Laravel 5包装器
calcinai/xero-php(与Xero集成的自定义API)的Laravel 5包装器。
通过Composer安装
需要此包
composer require adman9000/laravel-xero
将服务提供者添加到你的 config/app.php
中的 providers
'adman9000\LaravelXero\Providers\XeroServiceProvider',
在 config/app.php
下的 aliases
中注册Facades
'XeroPrivate'=> 'adman9000\LaravelXero\Facades\XeroPrivate',
发布配置文件
php artisan vendor:publish
这将创建一个 xero/config.php
文件在你的 config
目录中。(注意:确保你已经生成了必要的令牌,并且生成了Xero认证所需的RSA密钥。)编辑 config.php
文件中的相关值。
确保RSA密钥的位置与所需的格式 (file://absolutepath)
匹配
依赖项和需求
此服务提供者当前包装了 calcinai/xero-php 版本 1.1.* 包。
此外,你必须安装以下扩展的PHP
- php_curl (7.30+)
- php_openssl
使用方法
有两种方式可以使用类:通过IoC容器或通过Facades。它们都提供相同的功能,因此根据您的偏好选择使用。
获取所有发票
Facades
$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或发票编号获取单个发票
Facades
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);
IoC容器
$xero = $this->app->make('XeroPrivate');
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);
更新现有发票
Facades
$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);