picqer/xero-php-client

此包已被弃用且不再维护。作者建议使用 calcinai/xero-php 包代替。

PHP 客户端库,用于 Xero oAuth API,仅适用于私有应用

v0.1.14 2019-01-30 08:33 UTC

This package is auto-updated.

Last update: 2022-02-01 12:46:33 UTC


README

PHP 客户端库,用于 Xero oAuth API,仅适用于私有应用

此包不再维护,我们推荐这个优秀的替代方案:https://packagist.org.cn/packages/calcinai/xero-php

Composer 安装

可以通过 Composer 安装此 PHP Xero API 客户端。

composer require picqer/xero-php-client

使用方法

在你的 Xero 账户中创建一个新的私有应用: https://app.xero.com/Application/Add

创建一个私钥和证书,并上传你的证书。

启动 Xero 客户端

$xero = new Picqer\Xero\Xero('--api key--', '--api secret--', '--path to private key file--');

提供你的 API 密钥、API 密码和私钥文件的路径。

现在检索你的发票

$invoices = $xero->getInvoices();

创建新的联系人

$contact = new Picqer\Xero\Entities\Contact();
$contact->Name = 'Casper Bakker Demo';
    
$address = new Picqer\Xero\Entities\ContactAddress();
$address->City = 'Doesburg';
$contact->Addresses = [ $address ];
    
$response = $xero->create($contact);

创建新的发票

$invoice = new Picqer\Xero\Entities\Invoice();
$invoice->Type = 'ACCREC';
$invoice->LineAmountTypes = 'Exclusive';
$invoice->Date = new DateTime();
$invoice->DueDate = new DateTime('+2 weeks');
    
$lineitem = new Picqer\Xero\Entities\InvoiceLineItem();
$lineitem->Description = 'Subscription';
$lineitem->UnitAmount = 12.95;
$lineitem->AccountCode = '8100';
$lineitem->Quantity = 2;
    
$invoice->addLineItem($lineitem);
    
$invoice->Contact = $xero->getContact('--existing customer id--');

$response = $xero->create($invoice);