drawmyattention/xerolaravel

此包的最新版本(v1.2.1)没有提供许可信息。

Xero的PHP API的Laravel 5包装器

v1.2.1 2017-12-12 18:22 UTC

This package is not auto-updated.

Last update: 2024-09-17 18:14:49 UTC


README

Packagist

Xero会计API Laravel 5包装器

calcinai/xero-php(用于与Xero集成的自定义API)的Laravel 5包装器

通过Composer安装

需要此包

composer require drawmyattention/xerolaravel "1.0.*"

将服务提供者添加到您的 config/app.php 中的 providers

'DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider',

**在 config/app.php 下的 aliases 中注册Facades

'XeroPrivate'=> 'DrawMyAttention\XeroLaravel\Facades\XeroPrivate',

发布配置文件

php artisan vendor:publish

这将在您的 config 目录中创建一个 xero/config.php 文件。(注意:请确保已生成必要的令牌,并生成Xero认证所需的RSA密钥。)编辑 config.php 文件中的相关值。

确保RSA密钥的位置符合所需的格式 (file://absolutepath)

依赖项和需求

此服务提供者当前包装了 calcinai/xero-php 版本 1.1.* 包。

此外,您必须安装以下扩展的PHP

  • php_curl (7.30+)
  • php_openssl

用法

使用类有两种方式:通过IoC容器或通过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或发票号码获取单个发票

外观

$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);

IoC容器

$xero = $this->app->make('XeroPrivate');

$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);

更新现有发票

外观

$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);