Skip to content

Commit

Permalink
Merge pull request #802 from recurly/add_rev_rec_to_purchases
Browse files Browse the repository at this point in the history
Add RevRec to adjustments/purchases
  • Loading branch information
wsethbrown authored Mar 1, 2024
2 parents 356a32e + 9d175b5 commit 3427587
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
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());
}
}
29 changes: 29 additions & 0 deletions Tests/fixtures/adjustments/show-200-revrec.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<adjustment href="https://api.recurly.com/v2/adjustments/abcdef1234567890_revrec" type="charge">
<account href="https://api.recurly.com/v2/accounts/account"/>
<invoice href="https://api.recurly.com/v2/invoices/1234"/>
<subscription href="https://api.recurly.com/v2/subscriptions/1234567890abcdef"/>
<uuid>abcdef1234567890</uuid>
<state>invoiced</state>
<description>$12 Annual Subscription</description>
<item_code></item_code>
<accounting_code></accounting_code>
<liability_gl_account_code>100</liability_gl_account_code>
<revenue_gl_account_code>200</revenue_gl_account_code>
<performance_obligation_id>5</performance_obligation_id>
<product_code nil="nil"></product_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">1200</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1200</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<start_date type="datetime">2011-04-30T07:00:00Z</start_date>
<end_date type="datetime">2011-04-30T07:00:00Z</end_date>
<created_at type="datetime">2011-08-31T03:30:00Z</created_at>
</adjustment>
8 changes: 7 additions & 1 deletion lib/recurly/adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
* @property string $credit_reason_code Can be set if adjustment is a credit (unit_amount_in_cents < 0). Allowed values: [general, service, promotional, refund, gift_card, write_off]. Defaults to "general".
* @property Recurly_ShippingAddress $shipping_address The Recurly_ShippingAddress object associated with this adjustment.
* @property string $shipping_address_id The id of Recurly_ShippingAddress object associated with this adjustment.
* @property string (SET) $liability_gl_account_id The ID of the liability general ledger account associated with the adjustment to be created. Its associated code will be stored on the adjustment.
* @property string (SET) $revenue_gl_account_id The ID of the revenue general ledger account associated with the adjustment to be created. Its associated code will be stored on the adjustment.
* @property string $performance_obligation_id The ID of the performance obligation associated with the adjustment.
* @property string (GET) $liability_gl_account_code The code of the liability general ledger account associated with the adjustment. Once it is determined from the general ledger account specified in the request, it cannot be changed.
* @property string (GET) $revenue_gl_account_code The code of the revenue general ledger account associated with the adjustment. Once it is determined from the general ledger account specified in the request, it cannot be changed.
* @property DateTime $start_date A timestamp associated with when the adjustment began.
* @property DateTime $end_date A timestamp associated with when the adjustment ended.
* @property DateTime $created_at A timestamp associated with when the adjustment was created.
Expand Down Expand Up @@ -128,7 +133,8 @@ protected function getWriteableAttributes() {
'currency', 'unit_amount_in_cents', 'quantity', 'quantity_decimal', 'description',
'accounting_code', 'tax_exempt', 'tax_inclusive', 'tax_code', 'start_date', 'end_date',
'revenue_schedule_type', 'origin', 'product_code', 'credit_reason_code',
'shipping_address', 'shipping_address_id', 'item_code', 'external_sku', 'custom_fields'
'shipping_address', 'shipping_address_id', 'item_code', 'external_sku', 'custom_fields',
'revenue_gl_account_id', 'liability_gl_account_id', 'performance_obligation_id'
);
}
}

0 comments on commit 3427587

Please sign in to comment.