isinlor / freshbooks-php
该软件包最新版本(v1.0)没有提供许可证信息。
freshbooks-php 软件包
v1.0
2015-02-05 10:30 UTC
This package is auto-updated.
Last update: 2024-09-05 19:04:30 UTC
README
Freshbooks PHP 库(来源: https://code.google.com/p/freshbooks-php-library/)
感谢 Milan Rukavina(邮箱:rukavinamilan@gmail.com)在上述 URL 开发了原始库。
警告
请注意,从这个分支出来的库自2011年5月以来未更新或维护。它有很多错误。对于一些基本任务(如发送发票、通过支付网关触发支付)表现良好,但有很多“基本”功能是损坏的(通过发票编号获取发票详情、更新已发送的发票等。)
这个库仅适用于勇敢的人和对帮助修复过时的 Freshbooks PHP 库感兴趣的人。
初始化
要初始化库,包括以下初始化块。
// Include particular file(s) for entity you need (Client, Invoice, Category…)
include_once "library/FreshBooks/Client.php";
// Your API url and token obtained from Freshbooks.com
$url = "your-url-please-replace";
$token = "your-token-please-replace";
// Cnit singleton FreshBooks_HttpClient
FreshBooks_HttpClient::init($url,$token);
获取客户数据
// New Client object
$client = new FreshBooks_Client();
// Try to get client with client_id 3
if (!$client->get(3)){
// No data – read error
echo $client->lastError;
}
else {
// Investigate populated data
print_r($client);
}
新建客户
// new Client object
$client = new FreshBooks_Client();
//populate client’s properties
$client->email = ‘test@test.com’;
$client->firstName = ‘Chad’;
$client->lastName = ‘Smith’;
//all other required properties should be populated
//try to create new client with provided data on FB server
if(!$client->create()){
//read error
echo $client->lastError;
}
else {
//investigate populated data
print_r($client);
}
通过发票编号 #00000324301 查找发票
$invoice = new Freshbooks_Invoice();
$invoice->get('00000324301')
or die("Unable to get Invoice: " . $invoice->lastError);
print_r($invoice);
查找客户编号 #17992 的发票
$invoice = new Freshbooks_Invoice();
$invoice->listing($rows, $resultInfo, 1, 3, array('clientId' => 17992,
'status' => '',
'dateTo' => '',
'dateFrom' => '',
'recurringId' => ''))
or die("Unable to grab Invoice listing: " . $invoice->lastError);
if ($invoice) {
print_r($rows);
print_r($resultInfo);
}
标记发票为已支付
$payment = new Freshbooks_Payment();
$payment->invoiceId = '00000324300';
// To mark payment as 'PAID', this amount must be the full amount outstanding on the invoice
$payment->amount = '2.44';
$payment->type = 'Bank Transfer';
$payment->create()
or die("Unable to mark Invoice as paid: " . $payment->lastError);
// Note: this will automatically send the client a payment notification e-mail
// letting them know that their invoice has been paid.