Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add revrec support to php #793

Merged
merged 16 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Tests/Recurly/Addon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Recurly_AddonTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/plans/gold/add_ons/ipaddresses', 'addons/show-200.xml')
array('GET', '/plans/gold/add_ons/ipaddresses', 'addons/show-200.xml'),
array('GET', '/plans/gold/add_ons/ipaddresses_revrec', 'addons/show-200-revrec.xml'),
);
}

Expand All @@ -19,6 +20,18 @@ public function testConstructor() {
$this->assertSame($client, $prop->getValue($plan));
}

public function testGetAddonWithRevRec() {
$addon = Recurly_Addon::get('gold', 'ipaddresses_revrec', $this->client);
$this->assertInstanceOf('Recurly_Addon', $addon);
$this->assertSame('ipaddresses_revrec', $addon->add_on_code);
$this->assertSame('IP Addresses', $addon->name);
$this->assertSame(200, $addon->unit_amount_in_cents->USD->amount_in_cents);
$this->assertSame(1, $addon->default_quantity);
$this->assertSame('udexyr9hjgkc', $addon->liability_gl_account_id);
$this->assertSame('uelq7rzkydlu', $addon->revenue_gl_account_id);
$this->assertSame('6', $addon->performance_obligation_id);
}

public function testDelete() {
$this->client->addResponse(
'DELETE',
Expand Down Expand Up @@ -48,6 +61,29 @@ public function testCreateXmlItemBackedAddOn() {
</add_on>", $addon->xml());
}

public function testCreateXmlItemBackedAddOnWithRevRec() {
$item = new Recurly_Item();
$item->item_code = 'little_llama';
$addon = new Recurly_Addon();
$addon->plan_code = 'gold';
$addon->item_code = $item->item_code;
$addon->unit_amount_in_cents->addCurrency('USD', 400);
$addon->liability_gl_account_id = 'udexyr9hjgkc';
$addon->revenue_gl_account_id = 'uelq7rzkydlu';
$addon->performance_obligation_id = '6';

$this->assertXmlStringEqualsXmlString("
<add_on>
<item_code>little_llama</item_code>
<unit_amount_in_cents>
<USD>400</USD>
</unit_amount_in_cents>
<liability_gl_account_id>udexyr9hjgkc</liability_gl_account_id>
<revenue_gl_account_id>uelq7rzkydlu</revenue_gl_account_id>
<performance_obligation_id>6</performance_obligation_id>
</add_on>", $addon->xml());
}

public function testCreateXmlTieredAddOn() {
$item = new Recurly_Item();
$addon = new Recurly_Addon();
Expand Down
16 changes: 14 additions & 2 deletions Tests/Recurly/Adjustment_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Recurly_AdjustmentTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/adjustments/abcdef1234567890', 'adjustments/show-200.xml')
array('GET', '/adjustments/abcdef1234567890', 'adjustments/show-200.xml'),
array('GET', '/adjustments/abcdef1234567890_revrec', 'adjustments/show-200-revrec.xml'),
);
}

Expand Down Expand Up @@ -54,6 +55,14 @@ public function testGetAdjustment() {
$this->assertEquals(2000, $county->tax_in_cents);
}

public function testGetAdjustmentWithRevRec() {
$adjustment = Recurly_Adjustment::get('abcdef1234567890_revrec', $this->client);

$this->assertSame('100', $adjustment->liability_gl_account_code);
$this->assertSame('200', $adjustment->revenue_gl_account_code);
$this->assertSame('5', $adjustment->performance_obligation_id);
}

public function testDelete() {
$this->client->addResponse('GET', '/adjustments/abcdef1234567890', 'adjustments/show-200.xml');
$this->client->addResponse('DELETE', 'https://api.recurly.com/v2/adjustments/abcdef1234567890', 'adjustments/destroy-204.xml');
Expand Down Expand Up @@ -122,11 +131,14 @@ public function testXml() {
$charge->shipping_address->state = "CA";
$charge->shipping_address->zip = "94110";
$charge->shipping_address->country = "US";
$charge->revenue_gl_account_id = 'revenue-gl-account-id';
$charge->liability_gl_account_id = 'liability_gl_account_id';
$charge->performance_obligation_id = '6';

// This deprecated parameter should be ignored:
$charge->taxable = 0;

$expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><quantity_decimal>1.2</quantity_decimal><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>[email protected]</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address_id>123456789</shipping_address_id></adjustment>\n";
$expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><quantity_decimal>1.2</quantity_decimal><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>[email protected]</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address_id>123456789</shipping_address_id><revenue_gl_account_id>revenue-gl-account-id</revenue_gl_account_id><liability_gl_account_id>liability_gl_account_id</liability_gl_account_id><performance_obligation_id>6</performance_obligation_id></adjustment>\n";
$this->assertEquals($expected, $charge->xml());
}
}
2 changes: 2 additions & 0 deletions Tests/Recurly/BusinessEntity_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public function testGetAll() {
$this->assertEquals(2, count($subscriber_location_countries));
$this->assertInstanceOf('Recurly_SubscriberLocationCountry', $subscriber_location_countries[0]);
$this->assertInstanceOf('Recurly_SubscriberLocationCountry', $subscriber_location_countries[1]);
$this->assertEquals($business_entity->default_liability_gl_account_id, '12345');
$this->assertEquals($business_entity->default_revenue_gl_account_id, '56789');
}
}
2 changes: 2 additions & 0 deletions Tests/Recurly/BusinessEntity_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public function testGetBusinessEntity() {
$this->assertEquals(2, count($subscriber_location_countries));
$this->assertInstanceOf('Recurly_SubscriberLocationCountry', $subscriber_location_countries[0]);
$this->assertInstanceOf('Recurly_SubscriberLocationCountry', $subscriber_location_countries[1]);
$this->assertEquals($business_entity->default_liability_gl_account_id, '12345');
$this->assertEquals($business_entity->default_revenue_gl_account_id, '56789');
}
}
52 changes: 52 additions & 0 deletions Tests/Recurly/GeneralLedgerAccountList_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

class Recurly_GeneralLedgerAccountListTest extends Recurly_TestCase
{
public function testGetGeneralLedgerAccountListAll() {
$this->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);
}
}
67 changes: 67 additions & 0 deletions Tests/Recurly/GeneralLedgerAccount_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

class Recurly_GeneralLedgerAccountTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/general_ledger_accounts/u90r5deeaxix', 'general_ledger_accounts/show-200.xml'),
);
}

public function testGetGeneralLedgerAccount() {
$gla = Recurly_GeneralLedgerAccount::get('u90r5deeaxix', $this->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(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<general_ledger_account>
<code>little_llama</code>
<account_type>revenue</account_type>
<description>A description about llamas</description>
</general_ledger_account>",
$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(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<general_ledger_account>
<code>little_llama</code>
<account_type>revenue</account_type>
<description>A new description about llamas</description>
</general_ledger_account>",
$gla->xml()
);
}
}
31 changes: 31 additions & 0 deletions Tests/Recurly/GiftCard_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,37 @@ public function testGetGiftCard() {
$this->assertInstanceOf('Recurly_Stub', $giftCard->gifter_account);
$this->assertInstanceOf('Recurly_Delivery', $giftCard->delivery);
$this->assertEquals($giftCard->getHref(),'https://api.recurly.com/v2/gift_cards/1988596967980562362');
$this->assertEquals($giftCard->redemption_code,'AI4VOVO1RC74H9E2');
$this->assertEquals($giftCard->product_code,'gift_card');
$this->assertEquals($giftCard->unit_amount_in_cents,'2000');
$this->assertEquals($giftCard->currency,'USD');
$this->assertEquals($giftCard->balance_in_cents,'2000');
$this->assertInstanceOf('DateTime', $giftCard->created_at);
$this->assertInstanceOf('DateTime', $giftCard->updated_at);
$this->assertInstanceOf('DateTime', $giftCard->redeemed_at);
$this->assertInstanceOf('DateTime', $giftCard->delivered_at);
}

public function testGetGiftCardWithRevRec() {
$this->client->addResponse('GET', '/gift_cards/1988596967980562362', 'gift_cards/show-200-revrec.xml');
$giftCard = Recurly_GiftCard::get(1988596967980562362, $this->client);

$this->assertInstanceOf('Recurly_GiftCard', $giftCard);
$this->assertInstanceOf('Recurly_Stub', $giftCard->gifter_account);
$this->assertInstanceOf('Recurly_Delivery', $giftCard->delivery);
$this->assertEquals($giftCard->getHref(),'https://api.recurly.com/v2/gift_cards/1988596967980562362');
$this->assertEquals($giftCard->redemption_code,'AI4VOVO1RC74H9E2');
$this->assertEquals($giftCard->product_code,'gift_card');
$this->assertEquals($giftCard->unit_amount_in_cents,'2000');
$this->assertEquals($giftCard->currency,'USD');
$this->assertEquals($giftCard->balance_in_cents,'2000');
$this->assertEquals($giftCard->liability_gl_account_id,'t5ejtge1xw0x');
$this->assertEquals($giftCard->revenue_gl_account_id,'t5ejtgf1vxh1');
$this->assertEquals($giftCard->performance_obligation_id,'4');
$this->assertInstanceOf('DateTime', $giftCard->created_at);
$this->assertInstanceOf('DateTime', $giftCard->updated_at);
$this->assertInstanceOf('DateTime', $giftCard->redeemed_at);
$this->assertInstanceOf('DateTime', $giftCard->delivered_at);
}

public function testRedeemGiftCard() {
Expand Down
18 changes: 17 additions & 1 deletion Tests/Recurly/Item_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public function testGetItem() {
$this->assertEquals('Sleek Plastic', $item->description);
}

public function testGetItemWithRevRec() {
$this->client->addResponse('GET', '/items/plastic_gloves', 'items/show-200-revrec.xml');
$item = Recurly_Item::get('plastic_gloves', $this->client);

$this->assertInstanceOf('Recurly_Item', $item);
$this->assertEquals('plastic_gloves', $item->item_code);
$this->assertEquals('Awesome Plastic Gloves', $item->name);
$this->assertEquals('Sleek Plastic', $item->description);
$this->assertEquals($item->liability_gl_account_id,'t5ejtge1xw0x');
$this->assertEquals($item->revenue_gl_account_id,'t5ejtgf1vxh1');
$this->assertEquals($item->performance_obligation_id,'5');
}

public function testNestedCustomFields() {
$item = Recurly_Item::get('plastic_gloves', $this->client);
$item->custom_fields[] = new Recurly_CustomField('size', 'small');
Expand Down Expand Up @@ -72,9 +85,12 @@ public function testCreateXml() {
$item->name = 'Little Llama';
$item->description = 'A description about llamas';
$item->custom_fields[] = new Recurly_CustomField('size', 'small');
$item->liability_gl_account_id = 't5ejtge1xw0x';
$item->revenue_gl_account_id = 't5ejtgf1vxh1';
$item->performance_obligation_id = '5';

$this->assertEquals(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<item><item_code>little_llama</item_code><name>Little Llama</name><description>A description about llamas</description><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields></item>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<item><item_code>little_llama</item_code><name>Little Llama</name><description>A description about llamas</description><custom_fields><custom_field><name>size</name><value>small</value></custom_field></custom_fields><liability_gl_account_id>t5ejtge1xw0x</liability_gl_account_id><revenue_gl_account_id>t5ejtgf1vxh1</revenue_gl_account_id><performance_obligation_id>5</performance_obligation_id></item>\n",
$item->xml()
);
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Recurly/PerformanceObligation_List_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Recurly_PerformanceObligationListTest extends Recurly_TestCase
{
public function testPerformanceObligationListAll() {
$this->client->addResponse(
'GET',
'/performance_obligations',
'performance_obligations/list-200.xml'
);

$performance_obligations = Recurly_PerformanceObligationList::get(null, $this->client);
$this->assertInstanceOf('Recurly_PerformanceObligationList', $performance_obligations);

$performance_obligation = $performance_obligations->current();
$this->assertInstanceOf('Recurly_PerformanceObligation', $performance_obligation);

$this->assertEquals(iterator_count($performance_obligations), 3);
}
}
20 changes: 20 additions & 0 deletions Tests/Recurly/PerformanceObligation_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Recurly_PerformanceObligationTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/performance_obligations/6', 'performance_obligations/show-200.xml'),
);
}

public function testPerformanceObligation() {
$pob = Recurly_PerformanceObligation::get('6', $this->client);

$this->assertInstanceOf('Recurly_PerformanceObligation', $pob);
$this->assertEquals('Over Time (Daily)', $pob->name);
$this->assertEquals('6', $pob->id);
$this->assertInstanceOf('DateTime', $pob->created_at);
$this->assertInstanceOf('DateTime', $pob->updated_at);
}
}
6 changes: 6 additions & 0 deletions Tests/Recurly/Plan_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public function testGetPlan() {
$this->assertTrue($plan->tax_exempt);
$this->assertEquals('1234abcd', $plan->dunning_campaign_id);
$this->assertEquals('fixed', $plan->pricing_model);
$this->assertEquals('twrbsq39zvo5', $plan->liability_gl_account_id);
$this->assertEquals('bwrks63lznoi', $plan->revenue_gl_account_id);
$this->assertEquals('rkslzn', $plan->performance_obligation_id);
$this->assertEquals('twrisqjjzvo5', $plan->setup_fee_liability_gl_account_id);
$this->assertEquals('dlrk123lzabc', $plan->setup_fee_revenue_gl_account_id);
$this->assertEquals('bks6noi', $plan->setup_fee_performance_obligation_id);
}

public function testGetPlanWithRamps() {
Expand Down
25 changes: 25 additions & 0 deletions Tests/Recurly/ShippingMethod_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class Recurly_ShippingMethodTest extends Recurly_TestCase
{
function defaultResponses() {
return array(
array('GET', '/shipping_methods/fedex_ground', 'shipping_methods/show-200.xml'),
);
}

public function testShippingMethod() {
$shipping_method = Recurly_ShippingMethod::get('fedex_ground', $this->client);

$this->assertInstanceOf('Recurly_ShippingMethod', $shipping_method);
$this->assertEquals('fedex_ground', $shipping_method->code);
$this->assertEquals('FedEx Ground', $shipping_method->name);
$this->assertEquals('acc1', $shipping_method->accounting_code);
$this->assertEquals('r101', $shipping_method->tax_code);
$this->assertEquals('twywqfr48v9l', $shipping_method->liability_gl_account_id);
$this->assertEquals('thproqnpcuwp', $shipping_method->revenue_gl_account_id);
$this->assertEquals('4', $shipping_method->performance_obligation_id);
$this->assertInstanceOf('DateTime', $shipping_method->created_at);
$this->assertInstanceOf('DateTime', $shipping_method->updated_at);
}
}
Loading
Loading