diff --git a/Tests/Recurly/GeneralLedgerAccountList_Test.php b/Tests/Recurly/GeneralLedgerAccountList_Test.php new file mode 100644 index 00000000..8f2e9285 --- /dev/null +++ b/Tests/Recurly/GeneralLedgerAccountList_Test.php @@ -0,0 +1,52 @@ +client->addResponse( + 'GET', + '/general_ledger_accounts', + 'general_ledger_accounts/list-200.xml' + ); + + $general_ledger_accounts = Recurly_GeneralLedgerAccountList::get(null, $this->client); + $this->assertInstanceOf('Recurly_GeneralLedgerAccountList', $general_ledger_accounts); + + $general_ledger_account = $general_ledger_accounts->current(); + $this->assertInstanceOf('Recurly_GeneralLedgerAccount', $general_ledger_account); + + $this->assertEquals(iterator_count($general_ledger_accounts), 13); + } + + public function testGetGeneralLedgerAccountListFilteredByRevenue() { + $this->client->addResponse( + 'GET', + '/general_ledger_accounts?account_type=revenue', + 'general_ledger_accounts/list-200-revenue.xml' + ); + + $general_ledger_accounts = Recurly_GeneralLedgerAccountList::getByAccountType('revenue', $this->client); + $this->assertInstanceOf('Recurly_GeneralLedgerAccountList', $general_ledger_accounts); + + $general_ledger_account = $general_ledger_accounts->current(); + $this->assertInstanceOf('Recurly_GeneralLedgerAccount', $general_ledger_account); + + $this->assertEquals(iterator_count($general_ledger_accounts), 4); + } + + public function testGetGeneralLedgerAccountListFilteredByLiability() { + $this->client->addResponse( + 'GET', + '/general_ledger_accounts?account_type=liability', + 'general_ledger_accounts/list-200-liability.xml' + ); + + $general_ledger_accounts = Recurly_GeneralLedgerAccountList::getByAccountType('liability', $this->client); + $this->assertInstanceOf('Recurly_GeneralLedgerAccountList', $general_ledger_accounts); + + $general_ledger_account = $general_ledger_accounts->current(); + $this->assertInstanceOf('Recurly_GeneralLedgerAccount', $general_ledger_account); + + $this->assertEquals(iterator_count($general_ledger_accounts), 9); + } +} diff --git a/Tests/Recurly/GeneralLedgerAccount_Test.php b/Tests/Recurly/GeneralLedgerAccount_Test.php new file mode 100644 index 00000000..ead14eed --- /dev/null +++ b/Tests/Recurly/GeneralLedgerAccount_Test.php @@ -0,0 +1,67 @@ +client); + + $this->assertInstanceOf('Recurly_GeneralLedgerAccount', $gla); + $this->assertEquals('code1', $gla->code); + $this->assertEquals('revenue', $gla->account_type); + $this->assertEquals('string', $gla->description); + $this->assertEquals('u90r5deeaxix', $gla->id); + } + + public function testCreate() { + $this->client->addResponse('POST', '/general_ledger_accounts', 'general_ledger_accounts/create-201.xml'); + + $gla = new Recurly_GeneralLedgerAccount(null, $this->client); + $gla->code = 'little_llama'; + $gla->account_type = 'revenue'; + $gla->description = 'A description about llamas'; + + $gla->create(); + + $this->assertInstanceOf('Recurly_GeneralLedgerAccount', $gla); + } + + public function testCreateXml() { + $gla = new Recurly_GeneralLedgerAccount(); + $gla->code = 'little_llama'; + $gla->account_type = 'revenue'; + $gla->description = 'A description about llamas'; + + $this->assertXmlStringEqualsXmlString( + " + + little_llama + revenue + A description about llamas + ", + $gla->xml() + ); + } + + public function testUpdateXml() { + $gla = Recurly_GeneralLedgerAccount::get('u90r5deeaxix', $this->client); + $gla->code = 'little_llama'; + $gla->account_type = 'revenue'; + $gla->description = 'A new description about llamas'; + + $this->assertXmlStringEqualsXmlString( + " + + little_llama + revenue + A new description about llamas + ", + $gla->xml() + ); + } +} diff --git a/Tests/fixtures/general_ledger_accounts/create-201.xml b/Tests/fixtures/general_ledger_accounts/create-201.xml new file mode 100644 index 00000000..8e1d6724 --- /dev/null +++ b/Tests/fixtures/general_ledger_accounts/create-201.xml @@ -0,0 +1,12 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 + + + + u90r5deeaxix + code1 + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + \ No newline at end of file diff --git a/Tests/fixtures/general_ledger_accounts/list-200-liability.xml b/Tests/fixtures/general_ledger_accounts/list-200-liability.xml new file mode 100644 index 00000000..f0c2bb4f --- /dev/null +++ b/Tests/fixtures/general_ledger_accounts/list-200-liability.xml @@ -0,0 +1,78 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + ty4utwr0mrgz + 90-557-279-6957 + liability + optimize rich content + 2023-11-22T16:36:34Z + 2023-11-22T16:36:34Z + + + twyyzw8vcm36 + 45-571-736-1179 + liability + incentivize sexy functionalities + 2023-11-16T19:45:05Z + 2023-11-16T19:45:05Z + + + twywtf01wkgb + 70-818-669-8644 + liability + generate transparent metrics + 2023-11-16T19:32:52Z + 2023-11-16T19:32:52Z + + + twywqfr48v9l + 7-271-680-5012 + liability + My main liability account + 2023-11-16T19:32:24Z + 2023-11-16T19:32:24Z + + + twyvjlhbnej2 + 1234 + liability + My main liability account + 2023-11-16T19:25:44Z + 2023-11-16T19:25:44Z + + + trkzlcm2pde8 + validategla + liability + HOWDY + 2023-10-20T15:22:49Z + 2023-10-20T15:22:49Z + + + trkzinjccchm + j + liability + HOWDY + 2023-10-20T15:22:24Z + 2023-10-20T15:22:24Z + + + tep8f2u4qq51 + get dat monayyy + liability + i can has money + 2023-08-16T15:45:40Z + 2023-08-16T15:45:40Z + + + tejv6lw4eovy + demo_liability + liability + i be descriptin' + 2023-08-15T21:42:35Z + 2023-09-13T15:38:04Z + + \ No newline at end of file diff --git a/Tests/fixtures/general_ledger_accounts/list-200-revenue.xml b/Tests/fixtures/general_ledger_accounts/list-200-revenue.xml new file mode 100644 index 00000000..678dae27 --- /dev/null +++ b/Tests/fixtures/general_ledger_accounts/list-200-revenue.xml @@ -0,0 +1,38 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + u90r5deeaxix + string + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + + + trl0h3br1dl7 + 100 + revenue + HOWDY + 2023-10-20T15:27:46Z + 2023-10-20T15:27:46Z + + + trkz0atorlk3 + NEW code + revenue + NEW description + 2023-10-20T15:19:32Z + 2023-10-20T15:29:30Z + + + thproqnpcuwp + 303 + revenue + + 2023-08-31T20:46:04Z + 2023-08-31T20:46:04Z + + \ No newline at end of file diff --git a/Tests/fixtures/general_ledger_accounts/list-200.xml b/Tests/fixtures/general_ledger_accounts/list-200.xml new file mode 100644 index 00000000..c9d66e64 --- /dev/null +++ b/Tests/fixtures/general_ledger_accounts/list-200.xml @@ -0,0 +1,110 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + u90r5deeaxix + string + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + + + ty4utwr0mrgz + 90-557-279-6957 + liability + optimize rich content + 2023-11-22T16:36:34Z + 2023-11-22T16:36:34Z + + + twyyzw8vcm36 + 45-571-736-1179 + liability + incentivize sexy functionalities + 2023-11-16T19:45:05Z + 2023-11-16T19:45:05Z + + + twywtf01wkgb + 70-818-669-8644 + liability + generate transparent metrics + 2023-11-16T19:32:52Z + 2023-11-16T19:32:52Z + + + twywqfr48v9l + 7-271-680-5012 + liability + My main liability account + 2023-11-16T19:32:24Z + 2023-11-16T19:32:24Z + + + twyvjlhbnej2 + 1234 + liability + My main liability account + 2023-11-16T19:25:44Z + 2023-11-16T19:25:44Z + + + trl0h3br1dl7 + 100 + revenue + HOWDY + 2023-10-20T15:27:46Z + 2023-10-20T15:27:46Z + + + trkzlcm2pde8 + validategla + liability + HOWDY + 2023-10-20T15:22:49Z + 2023-10-20T15:22:49Z + + + trkzinjccchm + j + liability + HOWDY + 2023-10-20T15:22:24Z + 2023-10-20T15:22:24Z + + + trkz0atorlk3 + NEW code + revenue + NEW description + 2023-10-20T15:19:32Z + 2023-10-20T15:29:30Z + + + thproqnpcuwp + 303 + revenue + + 2023-08-31T20:46:04Z + 2023-08-31T20:46:04Z + + + tep8f2u4qq51 + get dat monayyy + liability + i can has money + 2023-08-16T15:45:40Z + 2023-08-16T15:45:40Z + + + tejv6lw4eovy + demo_liability + liability + i be descriptin' + 2023-08-15T21:42:35Z + 2023-09-13T15:38:04Z + + \ No newline at end of file diff --git a/Tests/fixtures/general_ledger_accounts/show-200.xml b/Tests/fixtures/general_ledger_accounts/show-200.xml new file mode 100644 index 00000000..509aa331 --- /dev/null +++ b/Tests/fixtures/general_ledger_accounts/show-200.xml @@ -0,0 +1,12 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + u90r5deeaxix + code1 + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + \ No newline at end of file diff --git a/lib/recurly.php b/lib/recurly.php index 056b49bf..4e429fe7 100644 --- a/lib/recurly.php +++ b/lib/recurly.php @@ -63,6 +63,8 @@ require_once(__DIR__ . '/recurly/external_payment_phase_list.php'); require_once(__DIR__ . '/recurly/external_subscription.php'); require_once(__DIR__ . '/recurly/external_subscription_list.php'); +require_once(__DIR__ . '/recurly/general_ledger_account.php'); +require_once(__DIR__ . '/recurly/general_ledger_account_list.php'); require_once(__DIR__ . '/recurly/invoice.php'); require_once(__DIR__ . '/recurly/invoice_collection.php'); require_once(__DIR__ . '/recurly/invoice_list.php'); diff --git a/lib/recurly/client.php b/lib/recurly/client.php index a5869899..bd499fa9 100644 --- a/lib/recurly/client.php +++ b/lib/recurly/client.php @@ -93,6 +93,7 @@ class Recurly_Client const PATH_EXTERNAL_INVOICES = 'external_invoices'; const PATH_EXTERNAL_ACCOUNTS = 'external_accounts'; const PATH_BUSINESS_ENTITIES = 'business_entities'; + const PATH_GENERAL_LEDGER_ACCOUNTS = 'general_ledger_accounts'; /** * Create a new Recurly Client diff --git a/lib/recurly/general_ledger_account.php b/lib/recurly/general_ledger_account.php new file mode 100644 index 00000000..69eb238c --- /dev/null +++ b/lib/recurly/general_ledger_account.php @@ -0,0 +1,53 @@ +_save(Recurly_Client::POST, Recurly_Client::PATH_GENERAL_LEDGER_ACCOUNTS); + } + + /** + * @param $id + * @param Recurly_Client $client Optional client for the request, useful for mocking the client + * @return object + * @throws Recurly_Error + */ + public static function get($id, $client = null) { + return Recurly_Base::_get(Recurly_GeneralLedgerAccount::uriForGeneralLedgerAccount($id), $client); + } + + public function update() { + return $this->_save(Recurly_Client::PUT, $this->uri()); + } + + protected function uri() { + if (!empty($this->_href)) + return $this->getHref(); + else + return Recurly_GeneralLedgerAccount::uriForGeneralLedgerAccount($this->id); + } + + protected static function uriForGeneralLedgerAccount($id) { + return self::_safeUri(Recurly_Client::PATH_GENERAL_LEDGER_ACCOUNTS, $id); + } + + protected function getNodeName() { + return 'general_ledger_account'; + } + + protected function getWriteableAttributes() { + return array( + 'code', 'account_type', 'description', 'created_at', 'updated_at' + ); + } +} diff --git a/lib/recurly/general_ledger_account_list.php b/lib/recurly/general_ledger_account_list.php new file mode 100644 index 00000000..d65e6e66 --- /dev/null +++ b/lib/recurly/general_ledger_account_list.php @@ -0,0 +1,18 @@ + 'Recurly_ExternalSubscriptionList', 'fraud' => 'Recurly_FraudInfo', 'gateway_attributes' => 'Recurly_GatewayAttributes', + 'general_ledger_account' => 'Recurly_GeneralLedgerAccount', + 'general_ledger_accounts' => 'Recurly_GeneralLedgerAccountList', 'gift_card' => 'Recurly_GiftCard', 'gift_cards' => 'Recurly_GiftCardList', 'gifter_account' => 'Recurly_Account',