-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# FreshBooks PHP SDK Changelog | ||
|
||
## Unreleased | ||
|
||
Basic Invoicing workflow functionality | ||
|
||
- Supports clients, invoices, line items, taxes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace amcintosh\FreshBooks\Model; | ||
|
||
use DateTimeImmutable; | ||
use Spatie\DataTransferObject\Attributes\CastWith; | ||
use Spatie\DataTransferObject\Attributes\MapFrom; | ||
use Spatie\DataTransferObject\Attributes\MapTo; | ||
use Spatie\DataTransferObject\Caster; | ||
use Spatie\DataTransferObject\DataTransferObject; | ||
use amcintosh\FreshBooks\Model\DataModel; | ||
use amcintosh\FreshBooks\Model\Caster\AccountingDateTimeImmutableCaster; | ||
|
||
/** | ||
* System-wide taxes for invoices. | ||
* | ||
* @package amcintosh\FreshBooks\Model | ||
* @link https://www.freshbooks.com/api/taxes | ||
*/ | ||
class Tax extends DataTransferObject implements DataModel | ||
{ | ||
public const RESPONSE_FIELD = 'tax'; | ||
|
||
/** | ||
* @var int Get the unique identifier of this tax within this business. | ||
*/ | ||
public ?int $id; | ||
|
||
/** | ||
* @var string Unique identifier of account the tax exists on. | ||
*/ | ||
#[MapFrom('accounting_systemid')] | ||
public ?string $accountingSystemId; | ||
|
||
/** | ||
* @var string Percentage value of tax. | ||
*/ | ||
public ?string $amount; | ||
|
||
/** | ||
* @var string Identifiable name for the tax. | ||
* | ||
* Eg. "GST" | ||
*/ | ||
public ?string $name; | ||
|
||
/** | ||
* @var string An external number that identifies your tax submission. | ||
*/ | ||
public ?string $number; | ||
|
||
/** | ||
* @var int Duplicate of id. | ||
*/ | ||
#[MapFrom('taxid')] | ||
public ?int $taxId; | ||
|
||
/** | ||
* @var DateTimeImmutable The time of last modification. | ||
*/ | ||
#[CastWith(AccountingDateTimeImmutableCaster::class)] | ||
public ?DateTimeImmutable $updated; | ||
|
||
/** | ||
* Get the client data as an array to POST or PUT to FreshBooks, removing any read-only fields. | ||
* | ||
* @return array | ||
*/ | ||
public function getContent(): array | ||
{ | ||
return $this | ||
->except('id') | ||
->except('accountingSystemId') | ||
->except('taxId') | ||
->except('updated') | ||
->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace amcintosh\FreshBooks\Model; | ||
|
||
use Spatie\DataTransferObject\Attributes\CastWith; | ||
use Spatie\DataTransferObject\Attributes\MapFrom; | ||
use Spatie\DataTransferObject\Casters\ArrayCaster; | ||
use Spatie\DataTransferObject\DataTransferObject; | ||
use amcintosh\FreshBooks\Model\Tax; | ||
|
||
/** | ||
* Results of taxes list call containing list of taxes and pagination data. | ||
* | ||
* @package amcintosh\FreshBooks\Model | ||
* @link https://www.freshbooks.com/api/taxes | ||
*/ | ||
class TaxList extends DataTransferObject | ||
{ | ||
public const RESPONSE_FIELD = 'taxes'; | ||
|
||
public int $page; | ||
|
||
public int $pages; | ||
|
||
#[MapFrom('per_page')] | ||
public int $perPage; | ||
|
||
public int $total; | ||
|
||
#[CastWith(ArrayCaster::class, itemType: Tax::class)] | ||
public array $taxes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace amcintosh\FreshBooks\Tests\Model; | ||
|
||
use DateTime; | ||
use DateTimeZone; | ||
use PHPUnit\Framework\TestCase; | ||
use amcintosh\FreshBooks\Model\Tax; | ||
use amcintosh\FreshBooks\Model\VisState; | ||
|
||
final class TaxTest extends TestCase | ||
{ | ||
private $sampleTaxData = '{"tax":{ | ||
"accounting_systemid": "ACM123", | ||
"amount": "13", | ||
"compound": false, | ||
"id": 7840, | ||
"name": "HST", | ||
"number": "RT 1234", | ||
"taxid": 7840, | ||
"updated": "2020-06-16 10:04:37"}}'; | ||
|
||
public function testTaxFromResponse(): void | ||
{ | ||
$taxData = json_decode($this->sampleTaxData, true); | ||
|
||
$tax = new Tax($taxData[Tax::RESPONSE_FIELD]); | ||
|
||
$this->assertSame(7840, $tax->id); | ||
$this->assertSame('ACM123', $tax->accountingSystemId); | ||
$this->assertSame('13', $tax->amount); | ||
$this->assertSame('HST', $tax->name); | ||
$this->assertSame('RT 1234', $tax->number); | ||
$this->assertEquals(new DateTime('2020-06-16T14:04:37Z'), $tax->updated); | ||
} | ||
|
||
public function testClientGetContent(): void | ||
{ | ||
$taxData = json_decode($this->sampleTaxData, true); | ||
$tax = new Tax($taxData['tax']); | ||
$this->assertSame([ | ||
'amount' => '13', | ||
'name' => 'HST', | ||
'number' => 'RT 1234' | ||
], $tax->getContent()); | ||
} | ||
} |