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 attributes to add ons #801

Merged
merged 1 commit into from
Feb 26, 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
22 changes: 22 additions & 0 deletions Tests/fixtures/addons/show-200-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
ETag: "a81253e90a4f16089b951028675c58d2"

<?xml version="1.0" encoding="UTF-8"?>
<add_on href="https://api.recurly.com/v2/plans/gold/add_ons/ipaddresses_revrec">
<plan href="https://api.recurly.com/v2/plans/gold"/>
<add_on_code>ipaddresses_revrec</add_on_code>
<name>IP Addresses</name>
<display_quantity_on_hosted_page type="boolean">false</display_quantity_on_hosted_page>
<default_quantity type="integer">1</default_quantity>
<unit_amount_in_cents>
<USD type="integer">200</USD>
</unit_amount_in_cents>
<measured_unit_id>123456</measured_unit_id>
<add_on_type>usage</add_on_type>
<usage_type>price</usage_type>
<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>
<created_at type="datetime">2011-06-28T12:34:56Z</created_at>
</add_on>
6 changes: 5 additions & 1 deletion lib/recurly/addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* @property float $usage_percentage If add_on_type = usage and usage_type = percentage, you must set a usage_percentage. Must be between 0.0000 and 100.0000. If item_code is present, usage_percentage must be absent.
* @property string $usage_calculation_type The method of calculation used for usage-based add-ons with type 'price'. Can be 'cumulative' or 'last_in_period'. If no type is selected, type 'cumulative' will apply.
* @property string $revenue_schedule_type Optional field for setting a revenue schedule type. This will determine how revenue for the associated Plan should be recognized. When creating a Plan, if you supply an end_date and end_date available schedule types are never, evenly, at_range_start, or at_range_end. If item_code is present, revenue_schedule_type must be absent.
* @property string $liability_gl_account_id The ID of the liability general ledger account associated with the add on.
* @property string $revenue_gl_account_id The ID of the revenue general ledger account associated with the add on.
* @property string $performance_obligation_id The ID of the performance obligation associated with the add on.
* @property DateTime $created_at The date and time the add-on was created.
* @property DateTime $updated_at The date and time the add-on was last updated.
* @property string $plan_code Unique code to identify the plan.
Expand Down Expand Up @@ -70,7 +73,8 @@ protected function getWriteableAttributes() {
'add_on_code', 'item_code', 'name', 'display_quantity', 'default_quantity',
'unit_amount_in_cents', 'accounting_code', 'tax_code', 'usage_timeframe', 'usage_calculation_type',
'measured_unit_id', 'usage_type', 'usage_percentage', 'add_on_type', 'revenue_schedule_type',
'optional', 'display_quantity_on_hosted_page', 'tier_type', 'tiers', 'percentage_tiers'
'optional', 'display_quantity_on_hosted_page', 'tier_type', 'tiers', 'percentage_tiers', 'liability_gl_account_id',
'revenue_gl_account_id', 'performance_obligation_id'
);
}
}
Loading