tow-com-au / sageone-php
此包的最新版本(dev-master)没有可用的许可证信息。
SageOne 会计 API 封装(PHP)
dev-master
2015-10-12 00:24 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-18 18:20:09 UTC
README
1. 概述
这是一个为 SageOne 会计平台提供的简单 API 封装库。
官方 API 文档和 API 注册可以在以下网址找到: https://accounting.sageone.co.za/Marketing/DeveloperProgram.aspx
感谢 Tow.com.au 团队 :) - https://www.tow.com.au
2. 安装
使用 composer,将其添加到您的 composer.json 文件中
{
"require": {
"tow-com-au/sageone-php": "dev-master"
}
}
如果您对 composer 不熟悉,以下是简单的步骤。
- 从上述链接下载 composer.phar
- 创建一个名为 composer.json 的 json 文件,其中只包含上述 "require" 块
- 将 composer.phar 和 composer.json 放在一起,您可以使用以下命令运行
php ./composer.phar install
-
composer 将创建一个名为 vendor 的目录,并将所有必需的库下载到其中。
-
在 vendor 目录中,还有一个名为 autoload.php 的文件。这是库内部的 PHP 自动加载器。您可能需要将其注册到现有的自动加载器中,或者手动包含它。
3. 使用方法
要登录到 SageOne API,您需要两样东西。首先,一个 'AuthCode',可以从您的登录详情生成,格式为 base64_encode('username:password'),其次,SageOne 请求的 API 密钥。
创建客户端库实例
// You will need to include this autoload script manually
// if you don't have any autoloader setup.
include "../path/to/vendor/autoload.php";
// Use your login to request an API key from:
// https://accounting.sageone.co.za/Marketing/DeveloperProgram.aspx
$apiKey = '{api key goes here}';
$authCode = base64_encode('username:password');
// SageOne will provide you with a localised endpoint url:
$apiEndpoint = 'https://accounting.sageone.com.au/api/1.1.1';
$companyId = false; // We don't have this yet
$debug = true;
$client = new Sage($apiEndpoint, $apiKey, $authCode, $companyId, $debug);
列出您的公司实体
$result = $client->listItems('Company');
if (!empty($result)) {
// grab the first Company ID
$companyId = $result[0]['ID'];
// re-instantiate with $companyId
$client = new Sage($apiEndpoint, $apiKey, $authCode, $companyId, $debug);
}
创建一个客户实体
// Create a customer
$customer_details = [
'Name' => 'Test Customer',
'Mobile' => '555-555',
'CommunicationMethod' => 0,
'Email' => 'test@test.com',
'PostalAddress01' => '1 test street',
'PostalAddress02' => 'testville',
'PostalAddress03' => 'QLD',
'PostalAddress04' => 4000,
'PostalAddress05' => 'Australia',
'TaxReference' => 'Customer 1',
];
// Save Customer entity
$result = $client->saveItem('Customer', $customer_details);